Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Shader Forge - A visual, node-based shader editor

Discussion in 'Assets and Asset Store' started by Acegikmo, Jan 11, 2014.

  1. Deleted User

    Deleted User

    Guest

    So it's already fixed in 1.02? It's correct?
     
  2. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    728
    Yes. Which means it won't happen again.

    But if you met this error already, it means the shader you were working on got corrupted. And even if you try to open it again with the new version it won't work.

    In that case, follow the instructions in my previous post.
     
    Deleted User likes this.
  3. Deleted User

    Deleted User

    Guest

    Thanks...
     
  4. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,242
    Thanks for sharing Seith - I would've typed it up myself if I wasn't on the subway/bus while messaging, hehe. So yes, this was fixed in 1.02, but your SF shaders created in 1.00 or 1.01 might be corrupted. It shouldn't happen again if you're on 1.02 or later.

    Sorry for any inconvenience this may have caused!
     
  5. Deleted User

    Deleted User

    Guest

    And for the undeclared errors? It's regular?
     
    Last edited by a moderator: Dec 30, 2014
  6. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    554
    Is there any possibility of using multiple passes inside SF in the future ?
     
  7. Liens

    Liens

    Joined:
    Feb 2, 2012
    Posts:
    42
    Hey everyone, just bought ShaderForge ysterday and still getting used to the way shaders work in general :) Would anyone be able to point me in the right direction for turning this shader into Shader Forge nodes?

    Code (csharp):
    1.  
    2. Shader "Fluvio/Fluid Shader (Refractive, Multiply)" {
    3.     Properties {
    4.         _TintColor("Tint Color", Color) = (1, 1, 1, 1)
    5.         _Intensity ("Intensity", Float) = 2.2
    6.         _MainTex ("Base (RGB)", 2D) = "white" {}
    7.         _DistortTex ("Distort (in RG channels)", 2D) = "blue" {}
    8.         _Distort ("Distort", Float) = 0.1
    9.         _WaveMod ("Wave Speed (XY) Wave Strength (ZW)", Vector) = (2, 6, .02, .025)
    10.         _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
    11.     }
    12.    
    13.     CGINCLUDE
    14.    
    15.         #include "Fluvio.cginc"
    16.         #include "UnityCG.cginc"
    17.        
    18.         uniform half4 _TintColor;
    19.         uniform half _Intensity;
    20.         uniform sampler2D _DistortTex;
    21.         uniform half _Distort;
    22.         uniform half4 _WaveMod;
    23.  
    24.         sampler2D _GrabTex;
    25.        
    26.    
    27.         half4 fragB ( v2fB i ) : COLOR
    28.         {  
    29.             #ifdef SOFTPARTICLES_ON
    30.             float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.uvScreen))));
    31.             float partZ = i.uvScreen.z;
    32.             float fade = saturate (_InvFade * (sceneZ-partZ));
    33.             #endif
    34.            
    35.             half4 off = half4(sin(_Time.y * _WaveMod.x) * _WaveMod.z, cos(_Time.y * _WaveMod.y) * _WaveMod.w, 0.5, 0.5);
    36.             half4 normal = tex2D (_DistortTex, i.uv) - off - 0.5;
    37.             i.uvScreen.xy += half2(normal.x, normal.y) * _Distort;
    38.            
    39.             half4 screen = tex2Dproj (_GrabTex, UNITY_PROJ_COORD (i.uvScreen)) * (_TintColor * i.color * _TintColor.a * _Intensity);
    40.             screen.a = tex2D (_MainTex, i.uv).a * i.color.a;
    41.            
    42.             #ifdef SOFTPARTICLES_ON
    43.             screen.a *= fade;
    44.             #endif
    45.            
    46.             return screen;
    47.         }
    48.    
    49.     ENDCG
    50.    
    51.     SubShader {
    52.         Tags {"Queue"="Transparent+100"  "RenderType"="Transparent"}
    53.         Cull Off
    54.         ZWrite Off
    55.         ZTest LEqual
    56.         Blend SrcAlpha OneMinusSrcAlpha
    57.        
    58.     GrabPass { "_GrabTex" }
    59.        
    60.     Pass {
    61.        
    62.         CGPROGRAM
    63.        
    64.         #pragma vertex vertB
    65.         #pragma fragment fragB
    66.         #pragma fragmentoption ARB_precision_hint_fastest
    67.         #pragma multi_compile_particles
    68.        
    69.         ENDCG
    70.        
    71.         }
    72.                
    73.     }
    74.     Fallback "Fluvio/No GrabPass/Fluid Shader (Refractive, Multiply)"
    75. }
    76.  
     
  8. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    290
    Little bug.
    I have a warning ( see picture ) when I click on button for correct problem nothing happen.



    Version 1.02
     
  9. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,242
    Yeah it has a few silly issues like this, but it's usually because the usage is often contradictory.
    Why do you need the light vector in the refraction slot?

    This should only appear when you have auto-sort enabled, I'll fix this in 1.03 :)
    Edit: Actually, this is rather weird. It might be just an old message. Have you tried simply pressing compile again?
     
    Last edited: Dec 30, 2014
  10. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    290
    Cool :)

    New problem when I watch source code of my shader.

    I have two variables which come from nowhere:

    In Properties, I have
    Code (JavaScript):
    1. Properties {
    2.         _Camps ("Camps", 2D) = "bump" {}
    3.         [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    4.     }
    And in CGPROGRAM, I have :

    Code (JavaScript):
    1. #pragma target 2.0
    2.             uniform sampler2D _Camps; uniform float4 _Camps_ST;
    _Cutoff and _Camps_ST are not from my tree ( see Images)
    And my picture is bump for default value ( because I play with before ? ) instead of white

    Also I have a question, where I set precision because I don't find that. Thx


     
  11. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,242
    _Camps_ST is the tiling/offset parameter you can set in textures in materials.
    _Cutoff is automatically added when using alpha or alpha clip to aid in depth sorting.

    Precision view can be enabled in the settings menu :)
     
  12. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    290
    That does not take performance so ?

    Really !? I don't know that so ok :)

    Find, thanks !

    Last question, I have often that logic

    Code (CSharp):
    1. float3 emissive = (i.vertexColor.rgb*_Camps_var.a);
    2. float3 finalColor = emissive;
    3. return fixed4(finalColor,_Camps_var.a);
    where finalColor does not use. In futur, have you planned to optimize?
     
  13. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,242
    It does, but not much. I may add an option to disable it at some point.

    No, and I think this is a case that the compiler will optimize anyway. This shouldn't happen in SF2, but in SF1, I'll leave it as-is
     
  14. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I think that one of the main reasons that SF is so affordable is that part of the payment is collected in the form of tears shed from a lack of this feature. Joking aside, I'm sure it's possible:
     
    Cactus_on_Fire likes this.
  15. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    294
    Careful with the vertex color node, you have to connect it to a pow node with a 2.2 or 2.0 value(gamma correction) to get the accurate vertex color.
    Well, at least that's what I had to do, vertex color painted in maya and using Shader Forge v0.3- something, i dont really have time to check that right now with the new version.
     
    Last edited: Dec 30, 2014
  16. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    290
    I just watch. No problem. but vertex color come from my script so for you case it's maya and unity which have problem :)
     
    Deon-Cadme likes this.
  17. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    294
    Ho well, must be that damn maya again, doing everything it can to waste your time.
     
  18. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,242
    As of 1.03, you can now hold Ctrl to temporarily toggle hierarchal node movement
     
  19. Deleted User

    Deleted User

    Guest

    @Acegikmo

    I tested all direction nodes to see the end result (i search a way to make a zoom lens), but this undeclared error made me think that maybe it was caused by a bug (sometimes appear an incompatibility error when something it's contradictory)...only this...

    However how i can get this?

     
    Last edited by a moderator: Dec 30, 2014
  20. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    294
    @H92 I can't currently use Shader Forge but here's how i would go about doing it procedurally :
    1.Node [Scene pos.] with parameter {Scene Uvs}.
    2.[Vector 2]{0.5, 0.5}
    3.[Remap(Simple)]{From:0, 1|To:-1, 1}
    4.Connect 1 and 2 with a [Distance], connect that to a [Power] which has an {Exp} of [Value customizable in inspector]{Name: FromCenterIntensity}{Value: 1}
    5.Connect 3 to a [Multiply] with a [Value customizable in inspector]{Name: BasicIntensity}{Value: 1}.
    6.Connect 4 and 5 to a [Multiply]
    7.Connect 1 and 6 to an [Add]
    8.Connect 7 to a [Scene Color]
    9.Connect 8 to whatever you want. You might do that to the Custom Lighting or Emission to test it.

    I'll try to test it as soon as I can but it "should" work.
     
    Deleted User likes this.
  21. Deleted User

    Deleted User

    Guest

    Thanks...even i will check this procedure
     
  22. Liens

    Liens

    Joined:
    Feb 2, 2012
    Posts:
    42
    Would anyone be interested in helping me out with that? I could pay if necessary I'm just not that great at making shaders from scratch even with shader forge
     
  23. khreathor

    khreathor

    Joined:
    Jan 29, 2014
    Posts:
    6
    Update:
    FIXED!!
    Wrap Mode
    in texture must be set to Clamp.

    Thanks to DMeville for pointing this out.

    Guys test this shader, if it works fine for you, we can add this to wiki as fake BRDF shader.

    Original:
    Hi guys,
    I'm working on fake BRDF shader. Someone requested same shader in post i have linked below, but he misunderstood BRDF from video with MatCap, which are two different things.
    http://forum.unity3d.com/threads/sh...sed-shader-editor.222049/page-42#post-1777845

    So my shader is working, except one thing... it has some weird black dots. It looks like its specular reflection with black color:


    What i'm doing wrong?

    PS
    Some more info:


    Some example gradient maps, so you can test it:
    http://i.imgur.com/lebhNPx.png
    http://http.developer.nvidia.com/GPUGems3/elementLinks/14fig23.jpg
    http://www.farfarer.com/temp/DiffuseScatteringOnRing.png
    http://farm2.static.flickr.com/1392/5126517019_65ed41213d.jpg
     
    Last edited: Dec 31, 2014
  24. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    401
    @khreathor: Just a huge shot in the dark (I had a problem that kind of looked like yours a while back..) What is your import settings on your texture you're putting into the "Texture" slot of the shader? Try changing the wrapmode to clamp?
     
  25. khreathor

    khreathor

    Joined:
    Jan 29, 2014
    Posts:
    6
    Oh Man !! Setting Wrap Mode to Clamp helped !! I was fighting with this for hours... Thanks !!
     
  26. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    294
    We can't currently reproduce the shader you gave us because of the following :
    1.#include "Fluvio.cginc" isn't possible under Shader Forge at the moment.
    2."sampler2D _GrabTex;" might be like the [Scene Color] in shader forge but it could be a custom one from the cginc above as well.
    3."ifdefs/endif" isn't possible under Shader Forge at the moment.
     
  27. Liens

    Liens

    Joined:
    Feb 2, 2012
    Posts:
    42
    I see, thanks for letting me know
     
  28. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    7,163
    I'm using a code node with return unity_DeltaTime; in it, Do I have anything I should look out for here? I'm trying to make sure my displacement shader is properly synchronised with a custom wave physics system I'm implementing.
     
  29. khreathor

    khreathor

    Joined:
    Jan 29, 2014
    Posts:
    6
    Hi folks
    I have made another fake BRDF shader. This one is based on this shader:


    Fake basic SSS looks nice and its cheap:



    Here you have some gradients:
    Basic one so you can see how shader behaves:


    And here is gradient for this fake SSS:


    Now i have problem with adding specularity. When i just ADD specular nodes to last Multiply node, shader specularity starts to blink (stroboscope effect) when i move objects. Any ideas what i'm doing wrong ? :)

    Update:
    Ok i figured it out. You need add Specular to color before multiplying it with Light Color etc.
     
    Last edited: Dec 31, 2014
  30. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    If I remember correctly, that's all you have to do, but why? Is the Time node not synchronized? I used it for a scene of vertex-displaced "rolling" hills (everything had a similar shader to "roll" along with the hills) and it seemed to work just fine.
     
  31. Arkham

    Arkham

    Joined:
    Dec 16, 2013
    Posts:
    9
    I'm currently trying to get an asset I made using Substance Painter to properly show up with a Shader Forge PBR (metalness) shader, but I'm struggling with it a bit. (To clarify, this is for Unity 4.)

    These screenshots should show the issue; if I hook up the base color fairly straightforwardly (directly to Specular) I get a result that is too dim (Setup 1); if I brighten the specular by adding in a dimmed version of the spec cubemap, I get something closer, but too bright and shiny (Setup 2). Both also look a bit too, eh, saturated?
    I'm just wondering if I should be tweaking the shader itself that much when it comes to a PBR shader -- it seems like it could mess with the "energy conserving" aspect of it? Or at least like the appearance should translate over more directly or something.

    SF_shader_setup.jpg

    Basically i want to make sure it will appear as it should by default in a given environment when someone else uses it (I'm planning on putting this up on the asset store for purchase). If it helps at all, I'm using the diffuse and specular cubemaps included with the Lux shader framework (those should be working correctly as far as I know).

    Additionally, I have a second issue -- the shadows from the light look like this. Changing bias doesn't seem to help.
    SF_shadow_issue.jpg

    Could I get some pointers for dealing with these two issues? Please and thank you!
     
  32. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    554
    Can I make a cubemap or a reflection map texture always face the light ? Connecting the light dir. to the cubemap direction input doesn't work.
     
  33. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    7,163
    My issue is that I'm not sure if it's safe to do that while trying to preserve framerate independence while also making it sync up with some Unity scripts that also rely on deltaTime.
     
  34. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    This is far from perfect, but it might help...?
    SF_CubeToLight_KindOf.jpg
    Just tested it - seems safe & synced. If you really want it to be 100% solid, you can set a variable controlled through code. Also, when testing shader-time-scale stuff, you have to be in Play mode to see results. I didn't know that at one point and it ate up a bunch of my time trying to debug what was going wrong.
     
  35. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    554
    The tangent setting is causing problems on UV seams, so It should rather operate on the mesh normals. It feels like it should be a really easy thing to do but I can't figure out how.
     
  36. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,242
    This is as good as it can get without C#, I believe :)
    You need to define a "light space" set of basis vectors. You can get quite far using just the light dir, but you get popping when passing certain limits. Right now I'm calculating it based on the assumption that you want Y to point upwards, which it doesn't always do.

    If you want bulletproof light tracking, pass in another vector of the light source, such as its local X or Y vectors, in world space, and then cross that vector with the light direction to get the final component.

    Hope it helps :)

     
    IFL and Marco-Sperling like this.
  37. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    554
    You are a wizard Ace ! Thanks for the help.
     
    Acegikmo likes this.
  38. Deleted User

    Deleted User

    Guest

    Someone can explain how relief map nodes work? I still not understand
     
  39. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Are you referencing the POM-shader stuff or just relief algorithms in general?
     
  40. Deleted User

    Deleted User

    Guest

    DDX and DDY nodes.
     
  41. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Do you know calculus/derivatives? If so, the answer here is wonderful. If not, check out the videos on derivatives at Kahn Academy.
     
  42. Deleted User

    Deleted User

    Guest

    So it's possible make this actually?

     
  43. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,242
    Yes, and I've got code that's pretty much ready to be made into a node for it :)
     
  44. Deleted User

    Deleted User

    Guest

    Will be implemented in 1.03?
     
  45. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,242
    Maybe, not sure. It depends on whether or not I'll run into unexpected issues with it
     
    Cactus_on_Fire and Deleted User like this.
  46. Deleted User

    Deleted User

    Guest

    When we will know something about this?
     
  47. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,242
    I don't know, during this coming week, at some point?
     
    hopeful and Deleted User like this.
  48. Ascensi

    Ascensi

    Joined:
    Sep 7, 2013
    Posts:
    579
    Is there a way to replace Unity's terrain shaders with SF? Unity's Terrain UI needs a button to "paint with Shader Forge instead" ;)
     
  49. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    554
    Just wondering, does it work like a step parallax relief where you can see the cutout steps if you zoom in, or does it simply distort the pixels in that direction.
     
  50. EricColossal

    EricColossal

    Joined:
    Sep 7, 2013
    Posts:
    6
    Hello, I was working on a shader and Unity crashed. I reopened Unity and any shader I open in ShaderForge v1.02 compiles but there are no nodes or anything in the middle window. It's just a flat grey. Even opening example shaders that come with ShaderForge are empty. If I create a new shader everything seems to work fine.

    Any ideas?
     
unityunity