Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. stiltskin

    stiltskin

    Joined:
    Feb 27, 2010
    Posts:
    93
    hey Acegikmo,

    do you have an plans on making some kind of lookat node? I would like to add some billboarding elements to a shader.

    thanks!
     
  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,733
    Unfortunately, this is kind of a deceiving number, in that certain operations can take more time than others. For instance, add, multiply, dot, and lerp are very fast, but things like arc, sin, etc are much slower. I used to have a chart of what these took on a certain piece of hardware, but I couldn't find it in my links page. That said, some of the more esoteric functions can be many, many times as slow as the basic ones, even thought they only add one instruction to the counter.


    There are hashing functions available to generate random numbers on the gpu, and they're not excessively slow. Most of these involve using some input, such as a UV or WorldPosition, scaling it's domain, and then using sin to create a high frequency noise. Something like so:

    float2 hash( float2 p )
    {
    p = float2( dot(p,float2(127.1,311.7)), float2(p,float2(269.5,183.3)));
    return -1.0 + 2.0*frac(sin(p)*43758.5453123);
    }

    this will essentially give you what looks like static. Note that sin(p)*43758.5453123 can cause issues on older hardware like the XBox360, especially if you're input UVs are being panned. You can lop off a few significant digits and it'll still look fine.

    If you want something that has less discontinuity, then what you want is a noise function. This usually involves taking some number of sample points and interpolating between them using a non-linear interpolation like a Hermite (smoothstep) curve.

    A wonderful explanation of this technique is here:
    http://thndl.com/?15

    the best implementations I've seen for textureless noise are here:
    http://briansharpe.wordpress.com/2011/10/01/gpu-texture-free-noise/

    and for sheer awesomeness, IQ is the master:
    http://www.iquilezles.org/

    A note on speed:

    Modern hardware is heavily optimized for texture lookup, and in almost all cases, a texture always wins for speed. My tests have shown that the faster noise functions are about 1.4 to 1.8 times as slow as a texture lookup. However, you can replace the hashing (random) function with a texture lookup and increase speed to about 1.2 or so, while still gaining the major advantages of using procedural noise. To do this, you have to generate a texture where each pixel represents one of the 4 random values you need for the noise function (representing the four corners of the gradient).

    Why are these functions so awesome?

    + No memory usage
    + Result is in full precision - no artifacts from texture compression, etc. This makes a big difference when generating UV distortions and input data which needs to be smooth
    + Every parameter is fully animatable, and can be plugged together to create domain warps and other effects which are impossible to produce with traditional texturing (see http://iquilezles.org/www/articles/warp/warp.htm)
    + No resolution and (nearly) infinite size
    + Can be generated in any number of dimensions, 1D, 2D, and 3D are the most useful. (3D textures are extremely limited due to memory usage, but 3d noise functions are fine)

    If there's ever a Custom HLSL node, or way to plug in your own nodes, I'll be happy to add this stuff for everyone. It's super useful..
     
  3. Deathnote

    Deathnote

    Joined:
    Nov 26, 2013
    Posts:
    52
    Who can teach me do some cool shader effects ?
     
  4. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    Thanks a bunch for the links!
    I've implemented a Noise node now which uses stuff from the thndl blog :)
    I saw it on Facebook as well, way after you messaged me (FB has a tendency to hide messages from people you aren't friends with)

    There will be a custom code node, soon!
     
  5. ColinKnueppel

    ColinKnueppel

    Joined:
    Nov 6, 2013
    Posts:
    9
  6. Filto

    Filto

    Joined:
    Mar 15, 2009
    Posts:
    697
    I bit the bullet and bought Shader Forge and your solution worked like a charm. The if statement seems pretty expensive so I don't know if it is a good solution in the long run but for now I'm happy .)

    As for another feedback. If the feature doesn't already exist I think it would be good to be able to make an instance of a node so one can use it elsewhere in the node tree without having to draw connections all over the place from one node that needs to be reused. It gets cluttered very quickly

    Thanks for a great tool!
     
  7. Ren072

    Ren072

    Joined:
    Aug 3, 2012
    Posts:
    5
    Is it possible to add a texture background behind the preview sphere?
    It would be easier to have a pattern when you work with transparencies.

    Thanks
     
  8. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    You could use a lerp node instead of an if node :)

    Glad it worked out!

    This is a planned feature!

    http://shaderforge.userecho.com/topic/254089-preview-background-texture/
     
  9. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,670
  10. GreatBigJerk

    GreatBigJerk

    Joined:
    May 20, 2012
    Posts:
    35
    Is there a way to feed an input node into the U and V parameters of the panner nodes? I want to be able to control the speed and direction of the panners at runtime. If not, can it be added?

    Edit: I just did a test by adding some properties to the shader code and replacing the values from ShaderLab, very easy to do. I'd definitely like to be able to handle that through ShaderLab though.
     
    Last edited: Feb 12, 2014
  11. donzen

    donzen

    Joined:
    Oct 24, 2009
    Posts:
    54
  12. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    You can handle that in SF too. Just make a manual panner :)

    Panning is just UV coordinates incrementing over time, so, you can use the value properties and hook them up to a time node, then an append node, and add a UV coordinate node together with the time offsets.
     
  13. Airborn-Studios

    Airborn-Studios

    Joined:
    Oct 31, 2012
    Posts:
    30
    Hey Joachim,

    i think i found a bug

    when i do

    (world position - object position)/64 i get a nice gradient from bottom to top of the object (or if i rotate it a gradient from left to right, or front back), this works when plugged into the pixelshader like emission, so i could give an object a nice shade or something. But i wanted to use this as a mask for a sine to be put into the vertexshader via worldposition - but i get a magenta object and this error

    "Shader error in 'Shader Forge/test_environment_wind': Program 'vert', undefined variable "objPos" at line 126"

    also i guess it is planned to give s a node for the object boundaries? right now i just do /64 because it gave me a nice gradient, but a unified value would of course be great

    also i couldn't find it on the feedback page as searching for wind returns tons of post about windows beeinf frozen etc.
    Using the windzones would be awesome.
     
    Last edited: Feb 13, 2014
  14. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    That's a bug that has been fixed in Beta 0.23!
     
  15. GreatBigJerk

    GreatBigJerk

    Joined:
    May 20, 2012
    Posts:
    35
    Your description was a little confusing, but you posted a reference image on the polycount forums a while back. For anyone else who wants the quick reference:
    http://www.polycount.com/forum/showpost.php?p=1882010&postcount=13
     
  16. Airborn-Studios

    Airborn-Studios

    Joined:
    Oct 31, 2012
    Posts:
    30
    0.24 maybe? because here it says 0.23 and i have just that bug :|
     
  17. MichaelCurtiss

    MichaelCurtiss

    Joined:
    Jun 11, 2013
    Posts:
    2
    On the Node documentation I didn't see any nodes that let you write your own code in them. I sometimes have to write some advanced shaders and in rare cases I may want some custom functionality like using the smoothStep() function to act as a pseudo conditional. Based on my experience with UDK's material editor and writing shaders in Unity, sometimes writing code is faster/more efficient to iterate with, and sometimes using the node editor is. It would be ideal if I could do both in one environment.

    It would also be great to be able to be able to add our own preprocessor directives, like #pragma glsl or #pragma multicompile, etc.
     
    Last edited: Feb 13, 2014
  18. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    Yeah, I meant 0.24, sorry :)

    Custom code node a planned feature :)
    http://shaderforge.userecho.com/topic/366897-ability-to-write-custom-nodeshlsl/

    What did you intend to use the #pragmas for, by the way?
    Ideally, #pragma glsl and #pragma multicompile should be added automatically, no?
     
  19. Zeblote

    Zeblote

    Joined:
    Feb 8, 2013
    Posts:
    1,102
    Add a way to rotate the light direction in the preview? Maybe by dragging with right click?
     
  20. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
  21. MichaelCurtiss

    MichaelCurtiss

    Joined:
    Jun 11, 2013
    Posts:
    2
    Awesome on the custom code node!

    As for the preprocessor stuff - I suppose most should be set automatically. I still imagine scenarios where I would want to set the multicompile defs manually though. For example, lets say that I want to make a custom editor script for a shader that I make, and I want to be able to toggle between different multicompile defs - I would need to know what these defs are. I would also need to be able to specify which functions in the shader are related to which defs. For example, lets say I only want the emission on if the preprocessor def #EMISS_ON is a keyword in the material. In shader forge I would want to be able to specify this def, and then state somehow in the node based editor that the emission nodes are only active if #EMISS_ON is active.

    The reasons for wanting this are very practical. Lets say I have a project that requires several different shaders that have only minor alterations. It is much more efficient to have the code for all of these different shaders in one multi-compiled shader - that way if I want to make a change that propogates through to all use cases, it would be easily achieved - you only have to manage one shader instead of ten.
     
  22. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    Oh, that's an entirely different topic though. #pragma glsl has nothing to do with compiler branching in the shader code, like #if EMISS_ON.

    It's a planned feature too anyhow :)
     
  23. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    Are the effects you show in there or only the editor? (things like the smoke distorsion animations on front page, is that in the samples or not included?)
     
  24. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    Not sure what you mean, but, yes, there are shaders included, one of them is the smoke-looking DX11 shader (Requires DirectX though).
    Some of them are just to demonstrate things you can do; you can do a lot more than what you can see on the front page :)
     
  25. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    Aye just buying as much for the samples as for the system. DX11 is fine (it's my only target), so the smoke is included, is the orange bumpy torus sample in there too? If so you've got a sale there.
     
  26. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    That one is included yes!
     
  27. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    6,362
    Oh my god THANK YOU! This is exactly what I was just about to check the site for, since I might need something like this very soon.

    Is there a way to get the rotation of an object relative to the camera view in the shader, or would this require a geometry shader too?
     
    Last edited: Feb 14, 2014
  28. Jacob-Aldridge

    Jacob-Aldridge

    Joined:
    Feb 26, 2009
    Posts:
    120
    Ace- I have a question about the preview window since I'm trying to make sure I'm not missing something. Have a voxel model that I've created using a custom UV calculation. There is an orange like color coming back from the specular, which is on the V channel of the first UV. Where is this color coming from?

    Thanks!
    $sf_vertex_simple_2142014.png
     
  29. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    The preview window has two light sources, one white and one orange, which is most likely where it's coming from :)
    See how it looks when used in-game!
     
  30. Jacob-Aldridge

    Jacob-Aldridge

    Joined:
    Feb 26, 2009
    Posts:
    120
    It does look fine in game, I just wanted to make sure I wasn't missing anything. Appreciate the explanation.
     
  31. Jacob-Aldridge

    Jacob-Aldridge

    Joined:
    Feb 26, 2009
    Posts:
    120
    Would it be feasible to allow us to adjust the color of those lights? Not that it is a huge thing, but having the preview allow us to set a similar lighting to what our game would be might be useful.
     
  32. Acumen

    Acumen

    Joined:
    Nov 20, 2010
    Posts:
    1,041
    I have neither knowledge nor usage for this product, I just wanted to chime in to say how inspiring I find it that you developed this super helpful item for such a big crowd of unity users in such a tight conjunction with them, sticked to your dev plan and didn't put it out rushed or unpolished. And to see how much success this has and how much it has paid off for you, is something that makes me happy inside - it just screams for a virtual hug - incase you can handle it \o/
    Just a wonderful piece of work !

    Hope this doesn't count as spam :)
     
  33. Jacob-Aldridge

    Jacob-Aldridge

    Joined:
    Feb 26, 2009
    Posts:
    120
    Actually something else I've found is that with this shader I've made Unity is asking: "Shader wants tangents, but the mesh MeshName doesn't have them". I'm not using any normals in this shader but it's still asking for them? Is there a setting I need to use to shut this off?
     
  34. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    Thanks a bunch! I gratefully accept virtual hugs :D

    Strange! What are you using in your shader then? Something seems to cause it to want tangents
     
  35. Jacob-Aldridge

    Jacob-Aldridge

    Joined:
    Feb 26, 2009
    Posts:
    120
    What you see is what you get. That's the whole shader. Do you want me to take a screenshot of the settings?
     
  36. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    Strange, the shader doesn't generate anything weird from what I can see. I can't see why Unity would ask for tangents.

    Changing the colors of the preview window lights might happen some time in the future :)
     
  37. Jacob-Aldridge

    Jacob-Aldridge

    Joined:
    Feb 26, 2009
    Posts:
    120
    Do you want me to send you the shader to look at?
     
  38. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    Throw the shader code up on pastebin!
     
  39. Jacob-Aldridge

    Jacob-Aldridge

    Joined:
    Feb 26, 2009
    Posts:
    120
  40. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    It's the lightmaps, lightmaps require tangents. If you uncheck lightmapping in the shader, you shouldn't get the error anymore
     
  41. Jacob-Aldridge

    Jacob-Aldridge

    Joined:
    Feb 26, 2009
    Posts:
    120
    Ah. Yeah, I can see that now. And because this shader doesn't use textures with the UV coordinates, lightmaps would be pointless anyway. Thanks for your time!
     
  42. SFtheWolf

    SFtheWolf

    Joined:
    Feb 14, 2014
    Posts:
    3
    I registered just to say how fantastic I'm finding Shader Forge. As a combination technical/artistic person I find it incredibly intuitive and a far more "musical" experience to create experimental effects with than code ever is.

    Some screenshots of a technodreamy game I'm working on that's shaded entirely with Shader Forge + built in Unity image effects:

    $Screen Shot 2014-02-12 at 6.37.44 PM.png
    $Screen Shot 2014-02-14 at 12.46.15 PM.png
    $Screen Shot 2014-02-14 at 12.46.26 PM.png

    This thing isn't optimized at all and it still manages to stay between 100-200 FPS on my mid-2012 laptop.
     
    Last edited: Feb 15, 2014
  43. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,317
    @Acegikmo,

    ShaderForge is incredibly awesome. I'm mainly on Mobile.

    Please, Please add support for Mobile soon.

    Many Thanks.
     
  44. Rirath

    Rirath

    Joined:
    Dec 5, 2013
    Posts:
    30
    Hey Acegikmo, if you haven't seen this yet, it might make your day. Seems Dear Esther is being ported to Unity, and the author specifically cites Playmaker and Shader Forge as being the enabler that helped him make it happen.

    Regardless of what you think of the game (it's reputation is hit-or-miss), it's a pretty well known title among indie games. I know that'd make me feel good.
     
  45. AlexanderWichlas

    AlexanderWichlas

    Joined:
    Feb 15, 2014
    Posts:
    1
    Hey Guys,
    I wanted to create a Box-Mapping-Texturing Shader ( Simply a Texture is projected on the mesh from x, y and z axis and blends out were the normals face in a different direction), and it works ok with just diffiuse, but the problem in my Shader is that the 3 projections get combined after the texture state and added over each other, which gives problems with normals. And is most likely to be very inefficent with multiple textures if you need to copy the full shadertree for every texture.
    My question would be if there is an easy and accurrat way to combine the uv Projections befor putting them into the Texture Node.

    Here s a picture. Hope you get my intention from it :D
    $sf_koordinatenmap_2152014.png
     
  46. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    Nice! Glad it works well :)

    It's probably coming, at some point, but I have some tough decisions to deal with at the moment, which may delay things.

    I didn't know he had posted it yet, but yeah, Briscoe has been the most active tester of SF during the Alpha/Beta :)

    Right now you'd have to clone a large part of the nodes, but I do want to make a node that makes a triplanar setup much easier!
    Also, the expensiveness of a shader doesn't have much to do with the amount of nodes you have, so I wouldn't worry about performance
     
  47. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    A little showcase of a new node along with a completely unrealistic but fun shader :)



     
  48. Becoming

    Becoming

    Joined:
    May 19, 2013
    Posts:
    781
    I was sometimes wondering if it makes a difference if i use nodes multiple times instead of connecting the same nodes output many times. Of course calculations would be done multiple times but i am talking about the nodes that grab the data from the same source anyway, i.e. time, uv cordinates, normal direction, world position, etc...

    I assume that it does not make any difference in performance to use these kind of nodes multiple times instead of just once and do multiple connections, am i right?

    About triplanar projection, a special node for this would be appreciated for sure, i made several shaders that use triplanar already and it takes quite a lot nodes.
     
  49. HJPL

    HJPL

    Joined:
    Dec 6, 2013
    Posts:
    12
    $sf_cubewall_2152014.png

    Yea my first shader! Still not exactly sure why it works, but its doing what I need. Thanks for this wonderful tool Acegikmo.

    One quick suggestion... More example shaders for us learning Noobs :)
     
  50. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    No in that case it doesn't matter :)