Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    View direction into your skybox cubemap, then do with that what you will (plug it into emission, usually, or tint it like some sort of glass window, or add some pattern like it's being displayed on a screen, or whatever).
     
  2. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    This seems to work quite well, but the cubemap is inverted.

    In the object, looking up into it displays the bottom of the cubemap as it assumes it is a reflection, how do I flip/rotate a cubemap in SF?
     
  3. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    The cubemap eats a vector3 instead of UVs, you can flip/rotate/etc is like normal UVs by miltiplying said vector3 by -1. If you want to flip it on one axis, you can multiply the vec3 by a new vector3 like (1, -1, 1) which would flip it just upside down but not mirror it on the x or z axis.

    You could also try to rotate it - instead of using the UV rotate node which works on UV (a vector2), you'll need to grab the X and Z components from viewdirection, append those into a vector2, then rotate those around (0,0). Then you need to use the component mask to separate those and the append node to re-assemble it into the X and Z components, using the Y component from above.
     
  4. Gamyo

    Gamyo

    Joined:
    Oct 30, 2014
    Posts:
    2
    Hi, I have an issue in current Shader Forge product : all my nodes are black on the editor. Even a simple Texture node appears black... Any idez how to fix this ?
     
  5. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    post unity version, sf version, etc before you ask for idez plz m8. First step is always to remove your SF folder, re-download, re-import anyway. Try a fresh project as well.


    Does anyone have a good clean way of converting between rgb and Hz? The rgb>hsv seems to use the ye olde straight edge curves that loop, which sorta screws me up, seeing how pink and purple are handled. All my attempts are fairly dirty.


    EDIT:

    https://forum.unity.com/threads/standard-shader-occlusion-what-am-i-missing.497686/#post-3235579

    Looks like SF is slightly off in terms of lighting calculations, but seems to be happening in forward only? I guess if you're using deferred, SF isn't actually doing any of the lighting, it's just outputting whatever you plug into the slots to be handled by Unity's lighting cg system.
     
    Last edited: Oct 11, 2017
  6. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Hello, everyone.
    Got a bit of an issue here:

    I have a shader which keeps bringing up the following error:
    This also causes any mesh with this shader on to have that trusty solid #FF00FF colour.

    This seems to be fixed if I open up the shader in SF and recompile it, but reappears when I open up a another scene.

    What exactly is wrong with this shader, how can I fix this?
     

    Attached Files:

  7. JackalopeConspiracy

    JackalopeConspiracy

    Joined:
    Mar 12, 2015
    Posts:
    32
    Hey guys, a couple of things.

    First I've just finished my Udemy Shader Forge course and so I'm now trying to make and study shaders from the wiki and this thread.

    I'm having trouble right now with the Flowmap shader shown here http://acegikmo.com/shaderforge/wiki/index.php?title=Flowmap

    I've got it mostly working but it isn't looping seamlessly and I'm not sure why? Pretty sure I did everything correct. Anything I miss?
    upload_2017-10-13_22-32-3.png



    Second, the documentation for the wiki is pretty out of date and while there's a ton of great info in this thread it's hard to find. So when I've seen cool shaders I've been adding them to a pinterest board. I want to help out the community despite being such a noob so if anyone finds this useful please feel free to check it out here: https://www.pinterest.com/thedonquixotic/shader-forge/

    Also I would love to help out with the official documentation and wiki, though not really sure where to start.

    Third thing is I'm working on making a depth gradient map shader. It's sort of like the the Distance blending shader except that it samples from a gradient instead of lerping two different colors. It's not quite coming out right though and I'd love to have other peoples suggestions. This is what I've got so far:
    upload_2017-10-13_22-26-25.png

    The basic idea is supposed to be similar to the Faked BRDF shader that was in my Udemy course, except it would measure the 0-1 not from the dot product to of the View and Normal direction, but from the depth distance. Sort of like fog but rendering for the surface instead of the entire screenspace. Anyway any help or pointers would be great! I'm just learning this stuff as a hobbyist really but would love to get a better grasp of things.
     
  8. JackalopeConspiracy

    JackalopeConspiracy

    Joined:
    Mar 12, 2015
    Posts:
    32
    Okay taking another crack at it.


    The main issue I see is that the depth of the object has to be relative to the depth of the scene right, or else you have to tweak the shader differently for every environment it is in. Though I guess that could still be a problem if you had a very big scene that was a bunch of tight enclosed rooms.... so maybe this isn't the best solution and it should just gracefully fade to it's darkest color at a distance?

    I'm having trouble getting it to do that right though. Instead it's only activating the visuals for things that are extremely up close.
     
  9. LazyGoblinCody

    LazyGoblinCody

    Joined:
    Mar 18, 2015
    Posts:
    66
    Hey everyone I just bought shader forge when it was on sale and finally have a reason to use it :D.

    I am trying to create an outline shader at the moment but I am having some issues with it.

    In the image below the outline is also affecting his eyes, which I do not want. I just want it to outline the mesh.



     
  10. JackalopeConspiracy

    JackalopeConspiracy

    Joined:
    Mar 12, 2015
    Posts:
    32
    If the eyes are separate from the the body mesh then it's actually just outlining the eye holes probably. Don't know a fix for that since the outline shader uses a duplicated reversed mesh which is easy to implement but doesn't really have a lot of options on how to deal with it.
     
  11. LazyGoblinCody

    LazyGoblinCody

    Joined:
    Mar 18, 2015
    Posts:
    66
    Ok I guess I will have to open up the mesh and see how it is made. Thanks!
     
  12. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    You might actually be able fix that because you have control of the outline thickness. Usually you'd just use a number (like you have done) but you can actually put a single channel of a texture, or whatever, into that as well.

    What you might want to do, is create a texture, where everything is white, except for the eyes which are all solid black. Multiply that with the outline thickness you're currently using, give that a go.
     
  13. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    Is there any way to enable reflection probes on deferred rendered in 2017.2+?
    Ever since I updated, the shaders no long show reflection.

    Edit: Actually, it does show reflection. But "Environment Lighting" no longer affects it.
     
    Last edited: Oct 19, 2017
  14. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
  15. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    sometimes I've had shaders go bad like that if I do something like flick between forward and deferred in the shader settings panel on the left, whole thing goes pink and throws up some errors.

    Only thing I can think of is to rebuild the shader (copy the nodes into a fresh one).
     
  16. gaiastellar

    gaiastellar

    Joined:
    Nov 8, 2013
    Posts:
    57
    hi,
    i am really interested in the noise function, and will decide whether i ultimately get shader forge or amplify shader editor based on the useability of the noise node.
    im creating planetary terrain , and need to put the noise function (currently 3d simplex multi fractal) on the shader for perfomance. the noise node looks a little simplistic ... any plans to implement something more complex? or perhaps there is a way to use the noise node with vector3 position... etc
    and also can we create multi texture shaders with this similar to megasplat - i need 4 or 5 main textures(with their normals etc) which i can assign through vertex color, or height etc...

    many thanks

    paul uk
     
  17. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    I have rebuilt it, that is the second one, built from a screen-shot of the graph.
     
  18. florianalexandru05

    florianalexandru05

    Joined:
    Mar 31, 2014
    Posts:
    1,810
    This look really OP! I would like to buy this sometime but I wonder if the asset store allows us to sell shaders made with Shader Forge? I'm pretty sure it does and I'd be happy to try it if so. I want to make my own shaders for my assets.
     
  19. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    1,104
    Hello, all. I just started using Shader Forge, and so far I've been able to figure out most of the nodes it has. One can waste a lot of happy hours just fooling around with the node graph. :)

    I needed a shader that combined an unlit surface shader, with specific properties, alongside a wireframe shader on a second pass, with some configurable parameters that I modify from C# scripts.

    I've actually solved my own problem, but what I did was to create the unlit shader in SF, and use SF to insert a dummy pass just to create a template. I then adapted (with extensive modification) some code from an online tutorial and merged it into the second shader pass. Now I have a shader that does 100% of what I need, but I have to manage it from the hand-edited source code.

    Am I overlooking the SF features to manage the wireframe part of this, using barycentric coordinates, or does SF focus on other aspects and not directly support that sort of thing?

    I emphatically do not intend this as criticism for SF. It's a very fine product, well-documented and easy to learn. I am just trying to adapt it to my unusual requirements.

    Thanks for any insights. :)
     
  20. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Check the SF wiki, you can add noise in through the code node. I think it has some example on a funny noise. The existing noise, if you calculate it per pixel, will be per-pixel. Same with UV, but the noise always scales per pixel, so it's not "stable". There are ways to fix that though, like rolling your own bilinear filtering which allows you to set noise 'resolution' like if you were generating noise in PS for a 256x256 (etc) image.

    And yes, you can do the multi-texture thing, check out the channel blend node. There's manual options, but from memory it has base + rgba for 5 texture support. While you're having a look, search the interwebs for the sf node list page, there might be other things of interest.


    Yes, you can, and I do. Always nice if you post some screenshots in this thread, but that's not mandatory. Also I'd reccommend puting "made with shader forge' or 'compatible with shaderforge' or something on the store page.


    @syscrusher I don't think SF does those coords, and I'm pretty sure the support for a hybrid SF / written shader isn't possible (barring some basics for post effects), but I've done the same thing ie prototyping the part I want to make in SF then copying that into a hand written shader I already had.
     
  21. florianalexandru05

    florianalexandru05

    Joined:
    Mar 31, 2014
    Posts:
    1,810
    Thanks for letting me know!
     
  22. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    1,104
    (nod) My shader is actually working very nicely; I was just thinking it would have been cool to be able to create it with the node-based editor. I am a real novice at shaders, though an experienced programmer otherwise, so honestly I'm kind of proud of myself that I was even able to glue these pieces together and get it working. It took the better part of a day, but now that it's done I've offloaded some really intense C# code from CPU to GPU.
     
  23. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    1,104
    Please forgive me if this is a stupid question, but how do I delete a connector in the node editor, without deleting the nodes?

    For example, if I have one of my output pins connected to something, and I simply want to disconnect that output without replacing it with a different value, how do I remove the connection?
     
  24. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    alt + right click, drag a line through any connections.
     
  25. Kubic75

    Kubic75

    Joined:
    Jan 2, 2017
    Posts:
    83
    In Unity 2017.1.2 and 2017.2.0 I can´t open ShaderForge anymore.
    It pops up shortly but then dissapears.

    Also some compiler errors:
    NullReferenceException: Object reference not set to an instance of an object
    ShaderForge.SF_PreviewWindow.SetupPreview ()

    Any solution?
    Product still supported???
     
  26. janvetulani3r

    janvetulani3r

    Joined:
    Feb 8, 2017
    Posts:
    12
    Hi!


    Anyone know how could I use the triplanar Object Space projection shader from here:
    http://acegikmo.com/shaderforge/wiki/index.php?title=Triplanar_Mapping

    But instead be able to use a normal map with it?

    I'm trying to use this in PBR, and I already managed to modify it so it outputs RGBA instead of RGB - since I need the alpha for roughness.

    Another one I'd really like to have with this is to be able to rotate the coordinates for each direction, so I can align my textures by hand. This will go on pieces of furniture and I need to be able to modify the flow of the wood grain.


    Thanks in advance!
     
  27. saishiki

    saishiki

    Joined:
    Dec 25, 2012
    Posts:
    3
    Hello.

    I want to apply a gradient from the minimum value to the maximum value of the object's Y axis
    I want to know how to not use UV

    I tried various investigations but I am in trouble because I can not find a solution

    This is the situation now
    upload_2017-10-27_17-20-9.png upload_2017-10-27_17-29-8.png

    I want to make it like this
    upload_2017-10-27_17-20-38.png
     
  28. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    May need slight modification.
     

    Attached Files:

  29. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    you're pretty close there, but remember position is stored in meters, which is being converted 1:1 to a value there. so position 0 is 0, 1m above that is 1, 2 meters below that is -2.

    You'll need 2 nodes, and to make a new copy of the material that uses this shader for each DIFFERENTLY SIZED object.

    You'll need a toggle node, for object that have their origin position at the center or the bottom.

    You'll need a Value node, where you enter Object Height in the material inspector.

    From what you've got now, divide that by (Value). Then plug that into a Remap Simple node, from (-1 to 1 into 0 to 1). Plug the divide and the remap nodes into a lerp node, and plug the Toggle into the C part of the lerp node.
     
  30. saishiki

    saishiki

    Joined:
    Dec 25, 2012
    Posts:
    3
    Thank you!

    I got the results I wanted.
    upload_2017-10-30_13-43-32.png
    However, it is difficult to enter object height for each object.

    I want to know the object height with just a shader
    However, if processing becomes heavy, I will give up
     
  31. Adam-Bailey

    Adam-Bailey

    Joined:
    Feb 17, 2015
    Posts:
    232
    You could always attach a component to your GameObjects that gets the bounds and then passes it into the material:

    https://docs.unity3d.com/ScriptReference/Renderer-bounds.html
     
  32. saishiki

    saishiki

    Joined:
    Dec 25, 2012
    Posts:
    3
    Thank you for the idea;)
    After all it seems difficult with shaders alone
    We will also refer to "Renderer-bounds"
     
  33. ExplosiveBarrels

    ExplosiveBarrels

    Joined:
    Oct 18, 2016
    Posts:
    11
    Hi, I'm trying to make a shader that recolors my 1-bit color game, and while I have a version that works perfectly on Sprites, it's completely failing on UI Images: it just turns them pure black.

    Here's the shader in question: https://imgur.com/a/fO90D

    Since my game is only 2 colours, this shader is just for changing the color palette for the entire game, so I'm doing a compare on a mid grey and using that to swap. This shader is applied to all my sprites (and works fine there).

    I also tried just using the default Sprite shader that Shader Forge makes, and that turns UI Images pure black as well. Is there something specific I have to do in Shader Forge to make a shader compatible with the UI?
     
  34. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Out of curiosity, could you do that step as a post processing effect instead?
     
  35. ExplosiveBarrels

    ExplosiveBarrels

    Joined:
    Oct 18, 2016
    Posts:
    11
    I had zero luck in figuring out how, but that was my first intention.
     
  36. JackalopeConspiracy

    JackalopeConspiracy

    Joined:
    Mar 12, 2015
    Posts:
    32
    Ooof. I'm having some major weirdness with a shader.
    https://imgur.com/a/iOvYF

    I made a depth map shader that samples a gradient texture and maps it to the depth. This is how it should look.

    Here it is plugged into the custom lighting input. Above it you can see another shader I've been working on.


    The above shader is a sort of subsurface scattering/ faked translucent surface shader that allows light to bleed on the edges when there is a light directly behind the object. I was having trouble getting it to look right so I routed it through a switch so that I could turn it off and on live as I adjusted the variables to see how the settings for the Depth Map shader and the SSS shader played together.


    When the switch is turned on and the SSS and Depth Map shaders are added together the contrast goes all out of whack. That's not the end of it though.


    Weirdly enough when the switch is turned off and the only thing that should be routed through it is the Depth Map shader, it still looks weird and way too high contrast! As you can see comparing the last picture where the SSS switch is turned on, there is no SSS in this picture where it's turned off. And yet the contrast is all messed up??? Why?
     
  37. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    I don't understand why the depth part should go into custom lighting at all? Keep in mind, anything routed through that gets applied for each light in the scene, and since you're not multiplying the depth bit by attenuation, it'll be applied fully to everything multiplied by the number of lights you have.

    Start from the top. Plug the depth color bit into emission, and plug a 0 into the custom lighting, diffuse, etc...

    Also, remember to check the rendering options. Are you using linear or gamma? If you're using linear, you'll get better results but will need a tonemapping on your camera (Unity postprocess stack free from the asset store has one, use that). Have you got HDR ticked? Forward or deferred? Custom lighting shaders don't play with deferred they're done in another forward pass.
     
  38. JackalopeConspiracy

    JackalopeConspiracy

    Joined:
    Mar 12, 2015
    Posts:
    32
    Is there a particular reason it shouldn't be set to custom lighting? If I multiplied the depth map output by light attenuation and then mapped that to the UV for the gradient, wouldn't it be a good idea to have it plugged into custom lighting?

    I guess don't actually quite understand what the purpose of plugging into custom lighting verus plugging into something else is.

    EDIT: Oh wait, upon reading again, I think I get what you're saying. Plugging it into custom lighting means that it will be multiplied by all the lights in the scene. Which is why it should be plugged into emission unless I choose to first multiply it by light attenuation right?
     
  39. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Yep that's correct.

    Try disabling all the lights in your scene, then everything should be black. Then, try adding a small point light somewhere, and everything should light up, then add another point light and everything will get twice as bright.

    One thing to look for that can give errors like this away is when things look like they bloom out to primary or secondary colors (rgb, cmy, white). That usually means you've got a lighting contribution value or more than 1 for some reason.

    If you multiply everything by Attenuation, however, you'll get something slightly different. If you want to have everything black, and only light up the depth areas, then put it at the end and plug that into just custom lighting.

    Or, in the meantime, I think instead of the last add operation, plug the depth part of it into emission, and then the lighting side into custom lighting, after multiplying just it by Light Attenuation. That will give everything depth color independent of lighting, and then add the blue lighting bit per light.
     
  40. JackalopeConspiracy

    JackalopeConspiracy

    Joined:
    Mar 12, 2015
    Posts:
    32
    Excellent thank you so much for the help!
     
  41. hirakyou

    hirakyou

    Joined:
    Nov 6, 2013
    Posts:
    4
  42. essimoon2

    essimoon2

    Joined:
    Nov 13, 2013
    Posts:
    195
    Hi Hirakyou,

    I made that one :) It should be easy to do in ShaderForge. It's basically just built around world position of your meshes.
     
    hirakyou and hopeful like this.
  43. hirakyou

    hirakyou

    Joined:
    Nov 6, 2013
    Posts:
    4
    Wow, your shader is very cool. that's what I want to do. but I'm really new to the shader. can you explain more or provide me some screenshot of the shader node?
     
  44. essimoon2

    essimoon2

    Joined:
    Nov 13, 2013
    Posts:
    195
    Thx! :)
    It's purely code so I can't provide a screenshot I'm afraid :(
    But I'll explain as best as I can.
    The shader calculates the world position of the vertices and generates a height mask based on input parameters. Then the result is transfered to the fragment shader with a tileable texture that matches the terrain texture is blended into the original texture. The UVs are also generated from world space position to match the tiling.
     
    hirakyou likes this.
  45. vbs

    vbs

    Joined:
    Sep 8, 2014
    Posts:
    24
    Some help needed :) I'm having issues with mesh tearing because of vertex offset... Is there a way to prevent this, some parts of the mesh don't break, but other parts to... not sure what the relation here is, and how to prevent it... shader is animated.

    2017-11-10 10_25_55-Unity 2017.3.0b8-sphere-with-shader-issue.png 2017-11-10 10_26_46-Unity 2017.3.0b8-material-settings-in-game.png 2017-11-10 10_27_26-Unity 2017.3.0b8-on-complex-mesh.png 2017-11-10 10_27_54-shader-setup.png

    Thanks!
     
  46. ryo0ka

    ryo0ka

    Joined:
    Sep 27, 2015
    Posts:
    37
    Hi, just a quick question -- Does Shader Forge support PBR + SSS on (recent) mobile platforms?
     
  47. hirakyou

    hirakyou

    Joined:
    Nov 6, 2013
    Posts:
    4
    Thank you very much!. I'll try my best :D
     
  48. ok8596

    ok8596

    Joined:
    Feb 21, 2014
    Posts:
    40
    Hi, I am worried about the stylized water and shoreline shader like below



    Is there a way to make shoreline like this in Unity and SF?
    It seems to need "Distance Fields" or "DistanceToNearestSurface" node.
    But I didn't find similar function.
     
    petey likes this.
  49. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    You can hack it by using the depth blend node
     
  50. ok8596

    ok8596

    Joined:
    Feb 21, 2014
    Posts:
    40
    I thought so, but the depth blend node can affect just front of overlapping objects.
    I hope to get effect also around of them. ex. foam or ripple.
    At least, I want to get intersection parts of them...