Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shader Forge - A visual, node-based shader editor

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

  1. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    This is DISGUSTINGLY clever and I'm shamelessly stealing this idea.
     
  2. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    Just an Idea,
    Is it possible to simulate via shader painting colors? (for example : Oil paint, Acrilic and Water color)?
    If yes, which will be a good approach?
     
  3. Seplabmikash

    Seplabmikash

    Joined:
    Sep 30, 2014
    Posts:
    12
    Thanks a bunch Cactus on Fire! :D
     
  4. Redz0ne

    Redz0ne

    Joined:
    Oct 19, 2010
    Posts:
    332
    Hey, I know that this might sound like a bizarre question but if Shader Forge can do this (without having to fry my brain) you can be assured a sale.

    What I'm looking for is a shader that has the full range of the usuals (normal, spec, self-illum, etc) but two different "channels" dependant on where light hits it.

    So, if the material has no (or less than X) light hitting it, it's one "channel" but if the light hits it (or more than X) it's another... Also, a gentle blending (so, less than X it's 1, greater than Y it's 2 and if between X and Y, it's a gradual blend between the two.)

    It's for an idea I want to eventually make.

    Also... PBR shaders... yes/no?
     
  5. NapalmRain

    NapalmRain

    Joined:
    Mar 3, 2013
    Posts:
    29
    Please suggest how to do so that the texture does not change size when the mesh size is changed, as is the case with standard Unity water.
    thank you in advance!
     
  6. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
  7. NapalmRain

    NapalmRain

    Joined:
    Mar 3, 2013
    Posts:
    29
  8. Redz0ne

    Redz0ne

    Joined:
    Oct 19, 2010
    Posts:
    332
     
  9. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    The 0.37 update is taking so much time.. I cant wait for the variable control feature....
     
  10. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    @Redz0ne If by material you mean a texture or any other values then yes, of course.
    The lerp node blends between two values(or texture, vector, anything else) by another value(in your case a dot product between the light and normal direction).
    Here's the documentation, search for "Lerp".
     
  11. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    You can do that - depending on what you are after you could use the custom lighting input of the main node and plug two different lighting models into it while using a lerp node and the light attenuation node to blend between the two lighting models.
    There are limits to this approach - multiple lights will be a cause of trouble that you would have to workaround.

    edit:
    You cannot however blend directly say between Material A and Material B. That's not how shaders work. You will have to merge the shaders of both materials into one blend shader.
     
  12. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Sorry, I've jumped to start rewriting the whole program. It took a long time to get my Unite talk done, and after that, shortly after I got home, I got a kidney stone and was hospitalized for a while, then I had planned to join a DreamHack game jam, so I did, and shortly after that I got sick again.

    Many things are slowing me down at the moment, but, I'm working on it :)
     
  13. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    Hello everyone, I'm in need of some help please. It looks simple but I can't find a way to do it.

    What I want is to draw a line when an object enters the plane with the shader. The pic shows the idea.
    I'm sorry if this looks really simple, but I seariously spent hours trying to find how to do it.

    Thank you for making this program!
     

    Attached Files:

  14. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    You can approximate the effect using the depth blend node, and making sure the camera writes to the depth buffer
     
  15. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Oh my :eek: I hope you get well soon !
     
  16. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    Ok, so I added this in Awake on my camera script
    camera.depthTextureMode = DepthTextureMode.Depth;
    I tried to use the depth blend node but i get weird results. from 0 to 1 on the slider I can't see the difference.
    I think I have a lack of knowledge and I don't understand what I should do and I don't know where to search or what to search. Also, I wish you to heal quickly :)
     

    Attached Files:

  17. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Make sure the shader on the plane doesn't write to the depth buffer. Easiest way of doing that is to set it to transparent / connect something into Alpha
     
  18. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    Ok changed that, I'm trying this on a simple empty shader because I want to add this to another shader a bit more "full".
    Ok I can see what it changes in play mode now, but for I don't know how to use it. I tried to multiply white color with the depth blend and then multiply with the red color, into the emission but it didn't do anything.

    Thank you for the help.

    Edit : I used a Lerp with Depth Blend :) It's getting close, thx.

    Edit2 : Ok it was a nice discovery, but I can't use it in our project because we have other objects using different blending methods going through the Red wall and I can't find a way to keep the look of these objects and at the same time display this line with the Depth Blend. It looks like the objets that go into the red wall need to have blend mode OFF and Render Type Opaque.
     
    Last edited: Oct 9, 2014
  19. Michael-Thomas

    Michael-Thomas

    Joined:
    Jul 8, 2014
    Posts:
    20
    I'm pretty new to working with Shader Forge, so I'm expecting I'm missing something obvious...

    I'm trying to adjust an existing shader forge shader to include some vertex offset in order to perform billboarding.

    I've successfully used an approach like this: http://en.wikibooks.org/wiki/Cg_Programming/Unity/Billboards in the past, but it's not clear to me if there's any way to make something like that work within Shader Forge (I did try using a Code node and passing the world position, transformed to local position, into that but I couldn't seem to make it work - it also seemed like it was going to produce some rather inefficient shader code which made me think maybe it wasn't the best approach).

    Does anyone have any suggestions for a good way to do a billboard vertex offset within shader forge?

    Edit: I found a way that I believe should be equivalent to what I was trying before, but without a Code node. However, this ends up with the objects I'm using this shader on totally misplaced in the scene. I've attached a screengrab from shaderforge. One thing that seems perhaps wrong is that the View->Local transform node I'm using ends up producing shader code that's multiplying by UNITY_MATRIX_MV - this seems like that would be the matrix to use to transform in the other direction.

    billboardshader.png
     
    Last edited: Oct 9, 2014
  20. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    @IFL and @Marco Sperling, thanks a bunch for contributing to the Wiki as of late! I really wish I could incentivize more people to write. Do you have any ideas?
     
  21. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I'm actually doing about the bare minimum of contributing by only posting the node graphs and not explaining them. I hope it helps, but I wish I had more time to give instructions or an explanation - it takes me forever to write because I'm a perfectionist.

    I don't think there's much you can do to convince people to help aside from what you've already done by making a great tool. You could go for a larger user-base by making a limited, free version in an attempt to draw in people that are more likely to contribute, but that's not a guarantee to work and it'd be a headache to maintain two versions.

    On another note, are the TRANSFORM_TEX operations done in the fragment shader to adhere to SF's framework or is there some other reason that they're not in the vert shader? It's not a problem - I'm just curious.
     
  22. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It's to save on interpolators. This is another thing that can be fixed in a rewritten version of SF. SF has no idea how many interpolators you're using, it simply adds them as needed, and if you run out, the shader won't compile.

    Putting the TRANSFORM_TEX operation in the vertex shader, means it needs at least one interpolator to send it to the fragment shader, and you can run out of those quickly!

    What it should do, is to do it in the vert shader if it has interpolators free, otherwise not.
     
  23. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Oh! That makes sense. Thanks for taking the time to explain it.
     
  24. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Does this fix it?
    SF_MichaelThomas_01.jpg

    [EDIT] Still doesn't work for meshes if they're rotated...
     
    Last edited: Oct 10, 2014
  25. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    As IFL wrote it is quite hard to maintain a steady flow of community made contributions - especially to something dry as a documentation. Like IFL I want my writings to be clear, concise, to the point - and hopefully accurate. Which takes time - which most of us lack. I have no clue what might rake in more contributors. Maybe it is as easy as asking for it in every post you (we) make? Reminding us all of the wiki and making it a central place to get all the information required to get the best out of SF? Currently there is your node documentation. And then there is your wiki. Perhaps people are missing out on the latter?
     
  26. Michael-Thomas

    Michael-Thomas

    Joined:
    Jul 8, 2014
    Posts:
    20
    @IFL - Thanks, that does indeed fix things for non-rotated meshes. I'm still trying to see if I can adjust it to also work for my rotated ones (Some of mine are rotated because they're children of larger parents which need to be rotated).

    I don't really follow the "why" of why your adjustment would solve the issue. Is there an easy explanation of why that extra subtraction makes sense? It seems like the transform should already have handled that part of the math.
     
    Last edited: Oct 10, 2014
  27. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I really have no idea. I didn't go into the code to look at what was happening so I don't have a clue why it didn't work. I just quickly figured out how to fix what was happening (the object's Z position didn't affect the screen-space offset). I didn't see the rotation issue until I was trying to add the shader to one of my scenes. I might take a look at it again over the weekend, but I doubt I'll come up with much unless I can figure out how to get the rotation of an object (never had to do that before). Though to be honest, that feels like walking the wrong direction since it's likely a problem with something around the transforms. :confused:
     
  28. Kirbyrawr

    Kirbyrawr

    Joined:
    Jul 23, 2012
    Posts:
    945
    Hi there, i'm trying to put a simple generated gradient shader on the skybox but it's giving me this result:

    As you can see it makes weird things on the vertex of the skybox, the shader is really simple:

    Any suggestions?

    Oh and the skybox is not a mesh, but the one of unity:


    PD: @Acegikmo get better! : D
     
  29. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    Hi,

    Would it be overly difficult to get this running with RageSpline?

    Rendering outlines through a shader instead of having both fill and outline meshes, would save major on performance for me.
    (I have to refresh meshes every frame, while I'm animating there vertices)
     
  30. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Use the view vector instead of UV coords - just using UVs won't get you perspective correction on the skybox
     
    Kirbyrawr likes this.
  31. Kirbyrawr

    Kirbyrawr

    Joined:
    Jul 23, 2012
    Posts:
    945
    Hi @Acegikmo, can you specify how to do it?, i mean i need to use a component mask with that?
    Thanks for the reply!

    Edit: Nevermind i found it:


    Is that the way to do it? If yes i think it should be cool to put it on the wiki
     
    Last edited: Oct 13, 2014
  32. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Yep. And feel free to add it to the Wiki! The Wiki isn't mine, it's everyone's ;)
     
  33. Kirbyrawr

    Kirbyrawr

    Joined:
    Jul 23, 2012
    Posts:
    945
    Last edited: Oct 13, 2014
    Baldinoboy likes this.
  34. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Thanks for adding it!
    I would suggest removing the "problem" section though; I don't think most would approach it in that way, so it's mostly clutter for people looking for a way to do sky gradients :)
     
    Kirbyrawr likes this.
  35. Kirbyrawr

    Kirbyrawr

    Joined:
    Jul 23, 2012
    Posts:
    945
    Okey i'm going to do it ! ^^
    Thanks you for help me : D!

    Edit: Done!
     
  36. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    [q] t's to save on interpolators. This is another thing that can be fixed in a rewritten version of SF. SF has no idea how many interpolators you're using, it simply adds them as needed, and if you run out, the shader won't compile.

    Putting the TRANSFORM_TEX operation in the vertex shader, means it needs at least one interpolator to send it to the fragment shader, and you can run out of those quickly!

    What it should do, is to do it in the vert shader if it has interpolators free, otherwise not. [/q]

    Or give us access to the interpolators which are free as inputs on the root node (and special value nodes) so we can compute anything in the vertex shader. Given the amount of Unity development which targets mobile, this would be a big win for those that need to optimize their shaders for low end platforms.

    (I like the automatic idea if unspecified, though)
     
  37. libin717

    libin717

    Joined:
    Oct 15, 2014
    Posts:
    6
    hello,
    I have a question, I created a Shader of plants, in real time and display the shadow is correct, but after baking Lihgtmap shadow has been a fast.How to solve this problem?
    real time shadow: upload_2014-10-15_21-4-46.png
    baking Lihgtmap shadow: upload_2014-10-15_21-6-37.png
     
  38. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Yeah. I get this in shader forge too. With cutout shaders.
     
  39. irwit

    irwit

    Joined:
    Sep 30, 2014
    Posts:
    55
    Hi

    I am trying to create a red glass shader but I am really struggling with the alpha. As it only accepts a single value Im ending up having to create a semi transparent red material. Coloured glass should simply multiply the colour of the glass over the image behind but I dont seem to be able to do this? Or am I missing something obvious?
     
  40. Kirbyrawr

    Kirbyrawr

    Joined:
    Jul 23, 2012
    Posts:
    945
    Do you mean something like this?:
    sf_colouredglass_10152014.png
     
  41. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    If you want it to multiply, simply set the blending mode to multiply. No need for alpha in that case
     
    Kirbyrawr likes this.
  42. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Hey Ace, can you add a node to retrieve the world position of a fragment from its depth? Or add a checkbox to the current worldPos node to make it use the depth.

    Use case for example:
    Fog based on Y coordinates of pixel behind the fragment that is currently rendered and the worldPos.Y coordinate of the currently rendered fragment... think of underwater fog.
    ZWrite of the currently rendered fragment needs to be turned off for this to work I guess.
     
  43. Sinaz20

    Sinaz20

    Joined:
    Nov 16, 2009
    Posts:
    53
    I'm looking at the scene depth and depth blend nodes wondering if these could be used in conjunction with a depth cue texture to clip a 3D object against a quad with a 2D scene texture+depth cue where the range of the depth cue represents the camera's near and far clipping planes. (Like, imagine I pre-rendered a scene and its depth cue, then matched up the unity camera to the scene's original camera.)

    Does this seem possible with Shader Forge?
     
  44. libin717

    libin717

    Joined:
    Oct 15, 2014
    Posts:
    6
    Who can share a vegetation SHADER?
     
  45. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    You can try this out: TFP_Leaf_Shader. It is one of my first shaders in Shader Forge and has been worked on. Want it to be tested out anyway.

    It is physically based. If you do not want it PB then switch to over to blinn-phong and remove the value node below the Color node.

    Also it is set up for two-sided leaves. Switch it to double sided if you are using single sided plants.

    It has that lightmap problem that you posted above. So far I cannot figure out how to get cutout shadows.

    Hope it works for you:). Let me know if there are any problems.
     
  46. libin717

    libin717

    Joined:
    Oct 15, 2014
    Posts:
    6
    Thank you very much baldinoboy, but I can't download TFP_LEAF_SHADER.If you can, please send me email to libin717@126.com. Ok?Thank you very much for the
     
  47. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Sorry. Can you download the attachment here? Always forget about attachments:rolleyes:.
     

    Attached Files:

  48. libin717

    libin717

    Joined:
    Oct 15, 2014
    Posts:
    6
    Yes, ok.Thank you very much.
     
  49. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Almost forgot to tell you.

    For bending you need the blue vertex color for main bending, green for edge fluttering(can not get the edge fluttering to work well), and red for random bending.

    If you do not want any bending just deselect the Leaf Bending switch in the material. Should be deselected by default anyway.
     
  50. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Regarding the lightmap issues with cutout shaders:
    Please compare the code of the original shaders that ship with Unity with the code that SF creates. I am sure that you will find differences that cause this issue. My guess: it has to do with how properties need to be named (e.g. _MainTex) and where Beast expects the alpha value to come from (_MainTex.a).