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. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Huge thanks to all of you who have contributed to the Shader Forge Wiki so far! It's exciting to see it grow :)
     
    Last edited: Mar 13, 2014
  2. Hendrixlt

    Hendrixlt

    Joined:
    May 25, 2009
    Posts:
    51
    Is there a way to create a "Heat Shimmer" materrial like it's possible in UDK's material editor?
    $firemat.jpg
     
  3. Dantas

    Dantas

    Joined:
    Mar 9, 2014
    Posts:
    28
    Is this the "same" thing as Alloy?
     
  4. BradHerman

    BradHerman

    Joined:
    Jan 10, 2013
    Posts:
    21
    No. Those a shaders that give an effect. This is a tool to design shaders. It's like the material editor in UDK, Maya, or Houdini.
     
  5. BradHerman

    BradHerman

    Joined:
    Jan 10, 2013
    Posts:
    21
    Yes. Those nodes are all in shader forge. Just connect them the same way.

    DepthBasedAlpha is called scene depth in shader forge.
     
  6. Hendrixlt

    Hendrixlt

    Joined:
    May 25, 2009
    Posts:
    51
    And what about distortion. I'm assuming it's "refraction" but it grays-out when I try to plug in the texture.
     
  7. Deathnote

    Deathnote

    Joined:
    Nov 26, 2013
    Posts:
    52
    thanks a lot will be look UDK shader tutorials

    but. SF wiki will be greate )))
     
  8. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Refraction is a screen-space effect, so it's expecting a two-component vector. Take your normal, and make an append node, and append R to G, then multiply it by a slider (To control refraction intensity), and then connect that to the refraction input.

    However, if you're using Unity Free, refraction will only work in the editor, but not in a build, since Unity doesn't permit Render Textures in Free.
     
  9. anadin

    anadin

    Joined:
    Oct 28, 2005
    Posts:
    98
    Just been thinking... what about an extra function to create an include file i.e. a .cginc where we can build it in shader forge then have an 'Include' node and point it at my new cginc?

    Until wet shader keywords nodes (hint hint) I reckon it could be an OK way to implement shared code between shaders? I am at the moment starting the whole process of an opaque/transparent/clipped variant of a 3 or 4 shaders and of course that will mean when I want to change the way one works I have to change them all :(
     
  10. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Nested nodes (Node prefabs, essentially) should solve that issue, alternatively, if I implement #ifdefs, it'll be even easier :)
    I've also planned to add a shader post processor system, so you can define scripts that are run on the shader before it's compiled, which would allow you to add things like an include, and so forth
     
  11. jasonMAN

    jasonMAN

    Joined:
    Mar 13, 2014
    Posts:
    1
    I dont know if this has already been said, however Im looking to create an outline with a shader and then apply a falloff to it. The look I would like to achieve is below. We are trying to get a glow around an object, (we have Unity pro) however we want to optimize the project as much as possible. The material would be applied in an on off fashion and wont be turned on all the time. I have been pouring over books, and working with a peer to try and figure out the math behind it.I would appreciate any and all help, and maybe some screen shots or examples of how to go about this type of shader, It may well not even be possible I acknowledge that.
    Thanks in advance...

    http://www.jurn.org/dazposer/wp-content/uploads/2013/11/glow.png
     
  12. Hendrixlt

    Hendrixlt

    Joined:
    May 25, 2009
    Posts:
    51
    Okay, I plugged "Scene Depth" into "alpha", and my normal map I plugged the R and B channels into an "Append" node which i then multiplied with a slider and plugged the "multiply" node into "refraction", but the material is completely black.

    i have a pro license. Am I missing something/
     
  13. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
    A diffuse node? Check out the refraction shader example that comes with sf. It might give you what you're missing.
     
  14. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Glow is a bit tricky, because there's usually not a straighforward way of doing it, since it's an effect that is "outside" the object itself. This is usually done using post processing effects. For instance, setting your shader to have a color that goes beyond 1.0, using an HDR camera, and the bloom script, you'll get a glow. You'll probably want to do something like that.

    So, make an outline, set the color to something beyond 1.0, use an HDR camera with a bloom script with a threshold at 1.0


    Scene depth is the distance from the camera to the background, not from the object to the background.
    I think you want the Depth Blend node, not Scene Depth, read the difference here:

    http://acegikmo.com/shaderforge/nodes/?search=depth
     
    Last edited: Mar 15, 2014
  15. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    I've now updated the Shader Forge Wiki front page, splitting things into categories rather than sorting by level of complexity

    Feel free to edit / add things if you like :)
     
  16. zettam

    zettam

    Joined:
    Apr 8, 2013
    Posts:
    28
    I can directly reach the scene depth in strumpy (without enabling it from the camera) - as far as ı can see from the documentation od Shaer Forge, it's not possible. Why is this? What is the difference? And is it possible to use it without using render textures?

    Thanks
     
  17. Urre

    Urre

    Joined:
    Mar 15, 2014
    Posts:
    1
    I've been writing a bunch to the wiki lately and figured my latest article might deserve a special mention, Using Shader Forge for Mobile. There's obviously more to be said, but this is a good start I think.

    I'd love to see more people contributing, let's grow this wiki fast!
     
    Gekigengar likes this.
  18. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    That was perfect timing, Urre, i'm going to go have a look now
     
  19. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    How's deferred rendering support coming along?

    Also...I may be confused with the channel blend node. I can't seem to add a 4th texture to the Acol node as an input. Any clarification on this?
    Just to clarify, I can't add the 4th texture to the Acol input because it is disabled.
     
    Last edited: Mar 15, 2014
  20. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
  21. fireheadd

    fireheadd

    Joined:
    Jan 6, 2013
    Posts:
    3
    Hi Joachim! I can't express how much I like Shader Forge! So very well designed! Thank you very much.
    As I am still learning I tried to replicate the Matcap Shader you posted a while back. But I don't get it.
    I don't understand what I need to set inside the Transform-Node (from to what?). And what happens inside the Node on the left?
    $progress_day20_matcap_howto.jpg

    I want to create a Matcap-Shader that uses the Light Direction as well. Like this Any pointers would be very helpfull!
    Thanks!
     
  22. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    How does Shader Forge get the object position for the object position node? Would it be theoretically possible to get an object rotation node?
     
  23. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Strumpy makes Surface shaders rather than CG shaders, and surface shaders are available for both deferred and forward, whereas SF currently only makes forward passes; which I think is why you're getting the depth "for free", since you have deferred passes.

    Deferred will take a while, in the middle of a bunch of other things at the moment, including a custom code node.

    As for the channel blend - Is the first node a Vector3 or a Vector4? It needs to be a Vector4 for Acol to be active.

    Here's a regular matcap shader:


    You should be able to extend it to read from the light direction as well, though you'll need a bit of extra math since you need some sort of coordinate system to work with :)

    It should be possible yeah. Although, what do you need it for? If you want to transform directions, you can use the transform node, as it can transform from and to local space as well, which will account for the rotation as well.
     
  24. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    Basically, I'm trying to account for object rotation and height (which I check against a few other things) to simulate moss growth. Right now I use a modified bit from the end of this rainfall shader:



    But if I just had a rotation node that'd make everything (along with a lot of other shaders) a lot easier to manage. The copy/paste system right now is a bit much to deal with, and having to use a bunch of grouped nodes when one would do the trick for this instance would make things a lot smoother. Plus, an object rotation reporting node would just be kinda handy in general, since it's something that could see a lot of use.
     
  25. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    If you want moss growth on top of things, just use the normal direction Y component :)
     
  26. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    Ah, but I don't! I want to incorporate the world position along with the object rotation and the normal map so that it gradually creeps up the object, but not along certain angles, along with incorporating certain things like where the sun would be hitting. Normally I'd be texturing this all on my own, but once you get past 5 or 6 objects, it becomes a bit more sensible to do it somewhat procedurally.
     
  27. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    You can dot product your perturbed normal against a direction vector to create a moss growth mask. Similar to how lighting/shading works.
    This way you probably won't need any object orientation - and you would benefit from having a single transform in your scene that dictates the moss growth.
     
  28. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    ...This actually sounds like it may work. I'll give it a shot when I'm back at my dev desk.
     
  29. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    This is coming soon, hopefully tonight :)

     
  30. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
  31. zettam

    zettam

    Joined:
    Apr 8, 2013
    Posts:
    28
    It works in forward rendering as well, here is a simple example of how depth node looks like:
    $strumpy_depth_simple.PNG

    And here is the shader being used ingame:
    $strumpy_depth_simple_game.PNG

    Without any calculations, it looks dull of course, but here is a little more controlled use of it:
    $strumpy_depth_complex.PNG

    And here is how this one looks in-game (with near and far control):
    $strumpy_depth_complex_game.PNG

    I've not made additional adjustments to the camera, and it's right now set to "forward rendering".
    $forwardrendering.PNG

    I've checked the shader to see what's being used; here is what the magical line looks like:

    float4 ScreenDepthDiff0= LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPos)).r) - IN.screenPos.z;

    I hope this helps, would love to see this functionality without needing additional camera renders. This is right now the only thing that's keeping me away from the purchase.
     
  32. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Oh! I thought you meant the distance from the camera to the background :)
    You can do that in SF as well, works in both forward and deferred, without additional scripts!

    Just take the view position node and the world position node, and check the distance, and you're set!
    There's also a node for this coming in a few hours, called "Depth", which is pretty much a shortcut for the above ;)
     
  33. zettam

    zettam

    Joined:
    Apr 8, 2013
    Posts:
    28
    You just earned another customer then!
    Making my purchase in a few minutes :)
     
  34. bigSky

    bigSky

    Joined:
    Jan 31, 2011
    Posts:
    114
    Eeep! This is fantastic! I want it to bake bread before beta .30.
     
  35. SFtheWolf

    SFtheWolf

    Joined:
    Feb 14, 2014
    Posts:
    3
    I just released a weird little free game that heavily features shaders made possible by Shader Forge.

    I definitely couldn't have achieved its experimental cyberpunk aesthetic without it. Thank you so much!
     

    Attached Files:

  36. helloDim

    helloDim

    Joined:
    Jan 10, 2014
    Posts:
    3
    Hi Joachim !
    It's a great update !
    But I'm a little confused with the trilerp function example.
    If t= 0.5f, I would expect that the function returns full red (mid color) but in this case it returns 0.75,0.25,0.
    Am I wrong ?

    EDIT : I would expect something like this :
    float3 a = lerp(start, mid, t*2);
    float b = lerp(mid, end, (t-0.5f)*2);
    if (t<0.5f){
    return a
    }else{
    return b}
     
    Last edited: Mar 16, 2014
  37. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Yeah, technically, it's not a lerp between three values, it's a quadratic Bezier interpolation :)
    The advantage with this though is that the mid color is smoothly approached and left, instead of having a sharp spike.

    If you want a real lerp with three values, here you go, without ifs/branching:

    Code (csharp):
    1. float t2 = t*2;
    2. float3 a = lerp( start, mid, saturate( t2 ) );
    3. return lerp( a, end, saturate( t2 - 1 ) );
    Perhaps I should allow more than three inputs on the built-in Lerp node? ;)

    Also, I added this to the Wiki page now, in node format:

    http://acegikmo.com/shaderforge/wiki/index.php?title=Gradient_Mapping

     
    Last edited: Mar 17, 2014
  38. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Got 16 hours of plane rides this week, so I think it's time to start adding some nodes to my library!
     
  39. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    love it! that's getting a bunch of attention when im up to it. do you think its fair or sensible to have lil custom node import export functionality, itd be great to expand your node library with helpful custom nodes from the range of knowledge across shaderforge users. shaderforges abilities could get enormous with a large available library of these
     
  40. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    Couldn't this sort of be added to the wiki? I mean, it looks like the custom nodes are just a simple text box, so you could probably copy/paste into them.
     
  41. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It does make sense to export this in practice, but technically it's quite a lot more to it than just that.

    So, just to not get your hopes up, this isn't a node/system for making custom nodes, it's a node that allows you to type code in and define inputs, but it's not exportable/importable.

    And you can't copy/paste either, but that's just a bug, you should be able to :)
     
  42. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Out of curiosity, if you could install these into the menu system, what do you think is missing vs a system for making custom nodes?
     
  43. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Let's say you've defined a custom code node, and then started using it in many shaders.

    Now, let's say you want to edit this node.

    1. Where do you edit it? Designated node designer area or in the node graph itself? If in the node graph - it needs to be clear that this will alter the node itself, not this *instance* of the node.
    2. If you change a custom node, ALL shaders using it needs to be recompiled, so SF needs to scan the entire project, parse all SF data, look for the custom node, and reload + recompile the shader, which can be tricky to make in a slick/fast way.
    3. If you're missing a custom node when loading a shader, what should happen?

    Ideally, a custom node system shouldn't display all the node editing tools inside the node itself, which the code node is doing right now, in which case it needs to be edited elsewhere.

    There are solutions to all of these issues, but the time could probably be better spent elsewhere. I personally feel that nested nodes pose the same kind of issues, but will in the end be a more elegant solution :)

    (Besides, nested nodes will be able to hold the code node too)
     
  44. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    I would treat all placed versions as inlined data. If you want to update the referenced code, simply re-install it into the menu to update the source; but any existing instances wouldn't be updated automatically.

    If all placed versions are essentially inlined, then that isn't an issue you need to worry about. Yes, it would be nice to have a way to "Apply back to all use cases", but I don't think you need to fully automate this. One thing that would be nice is a simple string compare when a shader is loaded and a visual indicator/option to update the node if it doesn't match.

    If it's all inlined each time, it will just work. This is actually pretty important, because it means if someone posts a shader on the web, it will always work regardless of which nodes the user might have installed. If they want that node in their library, they can just install it as if they had just written it themselves.

    I don't really mind that, as I generally develop these functions elsewhere (heroku or shadertoy) before using them in the graph. That said, if it could be opened/closed, I bet people would like that. Also, given our previous conversations on how the previews are done, I'm guessing these nodes totally break the preview system?
     
  45. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    They don't break it, they just return 0, so, the previews beyond those nodes will just be useless.
    This won't be a problem with a nested node system though!
     
  46. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Thinking about this some more, there are several axis's of user extensibility to consider:

    As currently written, the custom node allows for users to easily extend the system to have any type of node they want. But the downside is that those nodes are not nearly as nice or feature complete as the nodes Shader Forge offers. This system could likely be expanded to support things like placing them in the menus, etc - but would be unlikely to reach the customization level that nodes written in C# for the system allow. These nodes also require the user to understand how to write traditional shader code, thus preventing large swaths of the user base from writing them.

    Function Nodes, created with shader forge nodes, allow anyone familiar with shader forge to write new nodes using the system they already know. The downside is that some complex shaders are not easily represented via the graph, and this feature has a ton of UI/Workflow issues to solve, including all of the updating/referencing issues you brought up above.

    Finally, there's the option of opening up a way to write nodes from the C# side. This exposes a lot of internals of the system and makes it harder for you to change that system in the future, but allows for the highest quality nodes. It also has the steepest learning curve.

    I submit that each of these features has a unique audience and use case. As an example, I have a ton of nodes I would love to add to shader forge. If these were to be sold on the asset store, I would expect that they should match the quality of the nodes provided by shader forge, and would want to be created with option 3. However, if I were to give them away for free by placing the code on the website, then the current solution plus some form of install is likely good enough.

    So I guess my point in all of this is to ask what type of extension is considered the most important to get into 1.0? I don't think a 1.0 requires all of these features (or maybe any of them for most users) - but the choice here will likely shape how the community forms around shader forge to extend it; would we prefer a large selection of user-created nodes which are less integrated into shader forge, or a small number of professionally developed nodes? Does the average user want to extend shader forge via node graphs or via entering code?
     
  47. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    My guts say no to "does the average user want to extend sf via node graphs or via entering code". Most users probably want to migrate UDK graphs to Unity. Some may want SF to work in tandem with image effects. And some want SF to support particles (*hint hint*).
    Not everything that can be done should be done. People that are able to write sophisticated shader code should be able to create shaders entirely without SF.
    If these guys want to sell nodes or give them away for free - fine. But there's another question arising: who performs maintenance tasks on nodes that have been abandoned? It is a common thing to see assets not getting the attention they need by their original authors. This worsens with third party plugins for assets I'd guess.
     
  48. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Which is one thing I like about the current custom node; it encourages free nodes and those nodes are unlikely to need support since they are just raw HLSL code with some inputs/outputs defined. That stuff isn't likely to change for many, many years. Unfortunately, the fact that they won't work with SF's CPU rendered previews is really going to limit how much they feel like a workable extension system, even if you can install them into the interface.

    From what I've gathered, the current c# nodes have a lot of functionality that's required for them to work, since they often have custom interfaces as well as requiring the code to render previews in C#; that makes them much likely to incur support costs if Acegikmo decides to change any of the internals. Personally, that would bias me towards not opening up those interfaces.

    And while macro nodes solve the preview issues well, they are definitely a huge amount of work, and don't solve the issue that writing certain types of code in a graph is extremely hard (see POM shaders for UDK, for instance).
     
  49. hobstob

    hobstob

    Joined:
    Dec 18, 2013
    Posts:
    20
    Shader forge is a awesome product however I noticed a rendering issue when using it in conjunction with Candela SSRR ( Screen Space Real-time Reflections ) asset. Will this be something that is fixed in future updates?
     
  50. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Exactly, that's part of the problem with fully custom node approaches - they may break when SF updates, and many node creators won't update them.

    So, in my view, there are three ways of doing custom nodes:

    1. Fully custom. Opening up the C# guts of SF and allowing people to make their own nodes.
    Pros:
    - Most flexible, can allow almost any type of setup, with custom GUI and whatnot
    Cons:
    - Least intuitive, hard to grasp and is currently full of caveats that are hard to figure out.
    - Changes to the node system will most likely break a lot of custom nodes, leaving them unmaintained by their original authors
    - Will most likely spawn a lot of new requests form users, to get me to implement more features to it, and fix an entirely new category of bugs that may arise.

    2. Nested nodes that can be saved and reused in multiple shaders
    Pros:
    - Ties into the existing nodes, including the code node, but looks like a new node, essentially giving you a safe way of making custom nodes
    - The node preview will work, assuming the internal nodes all have node previews
    - Can easily make a system for selecting a set of nodes and grouping them into a single node
    - Most intuitive for the target audience of Shader Forge
    Cons:
    - A lot of work to make a clean system for editing/creating these nodes

    3. Code node that can be saved and reused in multiple shaders
    Pros:
    - Able to create reusable nodes defined by code
    Cons:
    - Has all the dependency/updating implications of the nested node system, but without being as safe
    - No previews will be able to render, since you never type the C# part
    - Hard to figure out how to access data that isn't sent into it as an input


    To me, #2 is the best way to go, for many reasons, but it is a huge feature with many implications.