Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
  2. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
    @Vladnes He has the shader code at the end. you can break it down into parts and assemble it from there or take what you need after finding out about it.
     
  3. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Relevant bits at around 1:00, but I recommend watching the whole thing!



    It's quite complicated, and partially impossible, as there's no custom lighting access to light probes, lightmapping and reflection probes yet
     
    moure, crudeMe, Vladnes and 1 other person like this.
  4. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,694
    can someone please point me in the right direction to achieve correct refraction?
     
  5. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    There's no easy way to do that in SF I'm afraid
     
  6. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,694
    ah ok,thanks for your answer, i thought it was possibble somehow based on the water meshs' normals
     
  7. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    anyone know how use the new node rgb to hsv for change hue please
     
  8. Sinaz20

    Sinaz20

    Joined:
    Nov 16, 2009
    Posts:
    53
    Yeah, I was just doing this the other day-- you use the RGB to HSV to break out the color into hue, saturation, value... take the hue output and run it through whatever process you want... then take that processed hue, and the unprocessed sat and val and run them back into an HSV to RGB node to get your process color.

    [EDIT] Hue is handled as an angle. As a scalar, 0 - 1 would be the spectrum from red to violet and wrapping back to red... just like a color wheel. If you were to increment hue, you'd see the hue walk through the spectrum, eventually returning to the same color. Check out https://en.wikipedia.org/wiki/HSL_and_HSV for visualization of how this colorspace works.
     
    Last edited: Aug 28, 2015
  9. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    thank's it's what's i try i will restart
     
  10. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Any way i can use a UV Channel as parameters?

    ex: Fake btw. just to illustrate


    or



    Thanks :)

    ps: Maybe... Normal Dir., Tanget Dir.? ;)
     
    Last edited: Aug 28, 2015
  11. GNDDCD

    GNDDCD

    Joined:
    Aug 20, 2015
    Posts:
    5
    I want to use distance to fade something, so that if it is greater than 20 distance, the value begins to fade towards "0"((Black)) over a distance of X meters... for the sake of this example, lets say 5.

    How would I go about doing this?

    How would I go about doing this with a Hermite easing curve, as well?

    Currently, I've got it built as Depth -> Add -20 -> Emission(Opacity, or other uses) which only hides anything part of a given model that just tips over into that 1 space.

    I'm also curious if I can have the whole model evenly affected, rather than the measurements being on a per-pixel base. I'm guessing I'd have to do a floor or ceiling on the depth?

    I know that's about 5 questions. Sorry folks :)
     
  12. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    504
    Depth/distance fading is actually pretty easy.

    One way to do it is to use a distance node, connected to the camera position (obviously), and either world position (gives you per-pixel results) or object position (gives you per-object results).

    The output from the distance node is then a number, in meters. So anything right next to the camera will be black, more than 1m away will be white, with a linear gradient in between.

    That's OK for now. What you then want to do is grab that distance number and plug it into a remap node. Not sure if you're familiar with remapping, but it's also easy. You want it to fade from white to black between the distances of (20) and (5). So you remap (distance) from (20) to (25) into (1) to (0). Also, don't forget to clamp this, otherwise you'd have values out of the 0-1 range.

    Once you've got that, you can then do your fancy hermite curve, or as a U/V lookup for a ramp texture so you can draw your own gradients.
     
    GNDDCD and KWaldt like this.
  13. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    What am I doing wrong here with HSV? I've created a new shader (SF Default Lit PBR) and added a HSV to the Base Color input. The editor preview shows the colour changing when changing the hue, but it doesn't work in the scene or game views:

    Gif here: http://i.imgur.com/DJWxfzS.gif http://i.imgur.com/RdvTTvM.gif

    Shader graph: Screen Shot 2015-08-29 at 1.33.05 AM.png
     
  14. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    It works as expected for me - couldn't get anything like what you're seeing.
    Latest fix may be relevant: http://acegikmo.com/shaderforge/changelog/
     
    DMeville likes this.
  15. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Yep, that has been fixed. It's only an issue on OpenGL / OSX as far as I can tell. It's fixed in the coming update
     
    DMeville likes this.
  16. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    I am having a bit of trouble adding refraction to a transparent barrier shader I am working on, I am trying to add an alpha clip later to simulate the barrier being turned off, but for now I would just like to get the refraction working.

    I can't connect the component mask to the refraction node connector for some reason.
    sf_barrier_8302015.png
     
  17. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Refraction is a two-component value, not a single value. Remove the component mask and instead append normal.r with normal.g, and hook it up to multiply, and then input that into refraction. You may also want to multiply by a slider/float too to control its intensity
     
  18. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    I did this, and now my shader is not transparent at all, it seems to be ignoring the opacity.
    sf_barrier_8302015.png
     
  19. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Make sure you don't have any errors in the SF console. For instance, it needs to be alpha blended to make this work
     
  20. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    I don't get any errors, just no transparency.
     
  21. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Then make sure you're passing it sensible data. As you can see, you're using the alpha channel of the texture. Is the alpha channel correctly set up?
     
  22. S_Darkwell

    S_Darkwell

    Joined:
    Oct 20, 2013
    Posts:
    320
    @Acegikmo: Alas, over a week of testing, and I still haven't found any solutions. I was hoping you could set me on the correct path?
    1. Is there a way of obtaining the physical size or extents of a model's bounds, mesh, or even collider?
    2. Adding a "Code" node causes ShaderForge's main window to go blank and Unity to freeze. I'm using Unity v5.2.0f2. Is this a known issue?
    Thank you so much in advance, and please be well!
    - S.
     
  23. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    1. Not automatically, but you can pass it in using a C# script with SetVector, and a Vector4 property in SF.
    2. This is a known issue, and will be fixed for the next update
     
  24. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Instead of incurring an additional draw call because the Material Param is different,
    would it be plausible to use a Global Param then?

    Ex: Material Param for "_brightness"

    ...instead use...
    ex: Global Param for "_brightness"


    And from code call
    Shader.SetGlobalFloat
    before the material shader is rendered... from maybe:
    MonoBehaviour.OnWillRenderObject() ?
    MonoBehaviour.OnRenderObject() ?
    ....

    Not sure. Just spitballing. :(
     
    Last edited: Aug 30, 2015
  25. S_Darkwell

    S_Darkwell

    Joined:
    Oct 20, 2013
    Posts:
    320
    Thank you for your prompt response!

    In regards to #1, is that a limitation of shaders themselves, or simply ShaderForge? I am seeking to create a fixed-width border around the normals of every object in my game, so if it could be done entirely within a shader, it is likely worth the research on my part to determine how to do so.

    Glad to hear #2 will be resolved!

    Thank you again. :)
    - S.
     
  26. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Doesn't refraction not care about alpha? ie anywhere there is refraction on the RG it outputs refraction on the shader, regardless if those pixels diffuse should be alpha-clipped? I remember something like this happening when I was making a refraction shader a while ago. I think the solution I found was instead of plugging in the Append directly into the refraction add a Lerp node between them - then lerp between the append, and a Vector3(0,0,1), with LerpT being your alpha texture. (which will change the refraction normals of any areas that are supposed to be clipped to the default "no" distortion value)

    Try that out. If that doesn't work ignore my nonsense :)
     
  27. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
  28. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @Labyrith Studios @Morfeuskiev Read the last post I made on the last page. It explains what's going on. Here's a screenshot of the shader graph and a gif of it in action as well, in case that my explanation didn't make much sense :)

    Refraction doesn't seem to care about whether a pixel has alpha by default, you have to handle opaque and transparent areas refracting differently yourself if that's the effect you're after by adjusting the normals/refraction input accordingly. Setting the alpha to 0 doesn't affect the refraction automagically.

    Shader graph: http://i.imgur.com/vAY9h9j.png
    Gif: http://i.imgur.com/OPF6DZl.gif
     
    IFL likes this.
  29. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It's a limitation in Unity I'm afraid
     
    S_Darkwell likes this.
  30. GNDDCD

    GNDDCD

    Joined:
    Aug 20, 2015
    Posts:
    5
    Thanks so much, I got the first part working, but not the second. Could you show a tree example of how someone would do a gradient ramp lookup? The shaderforge wiki didn't really make sense to me on this one.
     
  31. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
     
  32. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
  33. klund

    klund

    Joined:
    Mar 21, 2011
    Posts:
    33
    Hi just started using Shader Forge - fantastic product!.

    What is the values of the time node : second, millliseconds or tick ?
    Can we reset to start at 0 so that we now how long time have gone ?
     
  34. synapsemassage

    synapsemassage

    Joined:
    Jul 27, 2009
    Posts:
    334
    Hi Acegikmo,

    I'm currently looking into porting my planet shaders (http://superearth.de or Asset Store) over to shader forge. Started out with the most complex one and I like the first results. Yet, I'm missing the pragma directive "noambient". How would I set this in SF? There is a "Receive Ambient Light" in the Lighting settings, but this always grey-out. Light Mode is unlit/custom. Hope this is an easy one. Thanks in advance
     
    Last edited: Sep 1, 2015
  35. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Yeah, I'm pretty sure the matrix solution is the best way. Could be wrong though. I really like that smooth gradient compared to using vertex coloring.
    Time is in seconds. You can't restart the time without using your own property that is then set by script. But you can use the Frac node to repeat a 0-1 sequence. In that case, if you wanted to have something happen over the course of 3 seconds, you'd divide the time by 3 before passing that to the Frac node. So if a repeating time doesn't fit your needs, use a property.
    I know your question wasn't directed at me, but I just checked and confirmed that ambient light isn't in the compiled shader under any of the major platforms when using Unlit/Custom... I'm probably misunderstanding what you're wanting though.
     
    Vladnes likes this.
  36. synapsemassage

    synapsemassage

    Joined:
    Jul 27, 2009
    Posts:
    334
    Hi IFL,

    thank you for responding.

    I'm looking for way to set the pragma directive #pragma noambient inside shader forge. In my original surface shaders I use for example this #pragma surface surf Ramp vertex:vert noambient alpha:blend to avoid Unity adding an ambient tint on objects dark side. Unity tints ambient per default. Means to get a really black dark side for my planets I need to switch of this ambient tinting. The question is how if #pragma noambient is not available.
     
  37. kyleyoungblom

    kyleyoungblom

    Joined:
    May 1, 2014
    Posts:
    29
    I'm working on a shader to make my trees sway in the breeze. I'm almost there, but I'd like to be able to rotate each instance of the tree model and have the wind direction remain consistent (not adhere to local rotation). Is there an easy way to accomplish this? Right now I'm using a vector4 for my wind direction.

    Also, the motion I see in the editor viewport is much more exaggerated than what I get when I run the game. Any idea why? Thanks!

     
  38. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    That's not my experience with SF Unlit/Custom. I've looked at the compiled source and it's just not there. I also grabbed a screenshot and checked it in an image editor. Since I'm obviously of no help, I'll quit yapping and just assume that we have very different settings. :)
     
  39. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    IFL is right. That pragma tells the compiler not to include ambient lighting calculations when the surface shader code actually gets compiled into a vertex/fragment shader.
    Have you actually tried the custom lighting/unlit route?
    SF is creating vertex/fragment shaders directly - not surface shaders. That pragma directive wouldn't be of much help either because of this.
     
  40. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    504
    Try the transform node. The wind can be seen to be acting as a vector 4, with XYZ acting as a direction and A acting as strength. But ignore strength for now. These coordinates will be in world-space; the wind is coming from the east and slightly uphill (or whatever).

    Try using the transform node to change the world-direction wind to something else, (local, object, etc) and get an idea of what to use where and when. Then plug this output into a multiplier (by the vertex Alpha from the look of it).

    Going back to wind strength a bit, you had the right idea with adding some randomness.
     
    kyleyoungblom likes this.
  41. kyleyoungblom

    kyleyoungblom

    Joined:
    May 1, 2014
    Posts:
    29
    Thank you Jesus! The transform node was exactly what I needed.
     
  42. synapsemassage

    synapsemassage

    Joined:
    Jul 27, 2009
    Posts:
    334
    Thanks Marco, Thanks IFL,
    yeah I'm using lightmode custom/unlit, I mentioned that in my initial question. So if understand you both correctly ambient lighting is not added by default, at the moment I'm not aware what would cause this on my node network, well, I will check into SF node network again. For illustrating what I mean I added a screenshot. The planet on top is made with SF and shows the ambient dark side. The planet below is my original surface shader with black darkside. noambient.png
     
  43. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Sorry, I just read your reply.
    So you are on unlit and still get a lit backside - strange indeed.
    Some things I'd check:
    1) what does the code generated by sf look like - any suspicious unity constants and includes in there?
    2) light probes - are there any? is the shader taking them into account?
    3) reflection probes - again, are there any? are they affecting the shading? *
    4) scene lighting - any baked lighting information affecting the shading? *

    * (should not be the case in unlit, but who knows)
     
  44. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,209
    @Acegikmo,

    Does Shader Forge support Phong Tessellation or PN Triangles? I'm looking for a way to smooth and round out a mesh. If not, is that I feature you'll implement at a later date? Thanks.
     
  45. synapsemassage

    synapsemassage

    Joined:
    Jul 27, 2009
    Posts:
    334
    I checked your tips but the (my) error was in one of the nodes. I calculated dot product NdotL only positive not standard. So it's my bad. Marco and IFL, thank you both for your time. Sometimes I just need another pair of eyes to figure out how to set the ball rolling again. Without you I would still think that it's some #pragma thing. Thanks again.
     
  46. Hylian_a6324

    Hylian_a6324

    Joined:
    May 23, 2013
    Posts:
    1
    Hello,

    I am quite new to shaderforge and still haven't figured out everything. But I try my best.

    I've built a (IMO) very simple shader with reflective transparency, which works fine in Editor view. On the other hand, in Game view the material is not visible at all. I found out it has something to do with "Shader Settings" -> "Target renderer". When unchecking "Direct3D 11" the material becomes visible in GameView, but missing the effects I was trying to achieve.

    This isn't the only shader I made that is struggling with this issue. What am I doing wrong? And how can I fix it?
    Is there a way to have this material visible in Gameview whil having "Direct 3D11" checked?

    Limbs_Shader_Direct3D11_on.JPG

    Limbs_Shader_Direct3D11_off.JPG
     
    Last edited: Sep 2, 2015
  47. GNDDCD

    GNDDCD

    Joined:
    Aug 20, 2015
    Posts:
    5
    I'm wondering, how would I go about doing a gradient shader that lets me darken a model's feet, and as it goes up the body, less is darkened.

    Trouble is, I am working on a model that is modular, it has separate objects set to attachment points, and it's definitely not water tight. It's especially troublesome because the UV islands are rotated various ways to get the best packing.

    If there is a solution that requires a baked out gradient map, that's okay, but ideal would be without requiring map data from the modelers.

    -

    An aside; is there any sort of shader forge hub like on reddit or otherwise? Seems like this poor thread is containing the whole shader forge unity community!
     
  48. AniMoney

    AniMoney

    Joined:
    Sep 28, 2014
    Posts:
    10
    I'm using a custom/unlit shader to make a cel shader and was wondering if there was a way control the threshold angle used in my main lighting calculation (based on phong-blinn model).

    What I mean is, I'm getting the diffuse by doing the Dot product (positive) of Light Dir. and Normal Dir. My understanding is if they point in the same direction, it outputs 1, if they are perpendicular (90 degrees) to each other, it outputs 0, if they point in opposite directions, it outputs -1. Is there a way I can do this with a different angle instead of 90 degrees?

    This may not even be a practical thing for this use case, but it's something I wanted to learn and understand anyways. Still pretty new to shaders and lighting.

    Also I agree it'd be great to have a separate forum or something. It's a little intimidating posting in this huge thread.

    Edit: Actually I think I might be able to do this with the step node, but I'd still like to hear it from someone more experienced...
     
    Last edited: Sep 3, 2015
  49. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Is it possible to use Shader Forge to author a deferred shader that will modify the normals in the g-buffer before lighting is done? It's a task a bit similar to what shaders in the Unity 5 Command Buffers example project do, except I do not need any fancy projection, bounding boxes and other fluff - I just want to add floaters with decal material to my objects. How should I go about this?




     
  50. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    Is it possible to:
    A) Use global scale for UV's
    B) Add a fade-out/opacity drop around edges?

    As a reference for B, I am talking about the fade out on the edges like this: