Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. rquinones84

    rquinones84

    Joined:
    Apr 18, 2016
    Posts:
    11
    When we set our lighting mode to use ShadowMask from unity 5.6 , our Shader Forge Shaders no longer receive Directional Lights.

    Works fine with Unity Standard Shaders though.

    Also Pointlights and Spotlights still work with the Shader Forge Shaders

    Shader Forge version 1.36

    Is this a known bug? Does Shader Forge normally work with ShadowMask lightmode? Is there a plan to implement ShadowMask lightmode in Shader Forge?
     
    artistpetemac likes this.
  2. s0w4

    s0w4

    Joined:
    Aug 15, 2014
    Posts:
    3
  3. S-Miyahon

    S-Miyahon

    Joined:
    Jun 30, 2016
    Posts:
    12
    I am attempting to rotate a cubemap sky texture on the y Axis to make it look like the world is spinning around the player. It's possible with Unity's standard cubemap sky shader, so Shader Forge should also be able to do it. But after eight hours of trying, I have given up. Any help would be much appreciated.
     
  4. Deleted User

    Deleted User

    Guest

    I'm getting a lot of console errors coming from Shader Forge since the last update. Is this a known issue?
     
  5. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502

    If you're familiar with vector operations, and from memory the skybox uses view vectors (where red is right, green is up and blue forward, by simply grabbing the X and Z vectors as a (vector2) you might be able to rotate those around (0,0), where you are, and then append Y (up) back in between them.
     
  6. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,277
    Will ShaderForge be on sale too? There's a big shader sale happening right now on the Unity Asset Store. Before I buy any of the alternatives I'd like to ask if ShaderForge will be also put on sale. I'd rather go with ShaderForge. But 100€ only for toying around is a bit too much.
     
  7. justin1230

    justin1230

    Joined:
    Jul 30, 2016
    Posts:
    2
    Hi,
    I am working on a x-ray like material,
    but the geometry overlapped on its own,
    can someone suggest me how to get rid of this ?

     
  8. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    That's because the shader doesn't know to not render anything behind the front surface.

    One of the things you can try is to keep it transparent, but find the option to write to the depth buffer. That should stop those artifacts, but any transparent objects behind it won't be rendered either.
     
  9. KellogsCruncher

    KellogsCruncher

    Joined:
    Apr 18, 2017
    Posts:
    1
    Hi,
    I'm trying to do a triplanar shader in ShaderForge that also reconstructs normals from a Heightmap (which is in the Alpha channel of my Albedo) but I need some code to solve my problem since you can't plug anything else than a TextureAsset into the Tex slot of a Texture 2D.
    Basicly I want it to act like a Texture 2D (Tex and UV input, RGB output). In input (Tex input) it's getting my reconstructed Normal that should be combined with UV output that gives the axis projection for the triplanar.

    I'm stuck because can't write shader code even through I understand the mechanics behind it...

    I hope it's clear... Here is a Screenshot to show it: Texture2D.png
     
  10. Jayme65

    Jayme65

    Joined:
    Dec 11, 2016
    Posts:
    94
    Hello,
    I would like to know if I could achieve distance map effect like those with Shader Forge:



    If yes, is there a tutorial/howto on that subject ?

    Thank you very much!
     
    Last edited: Apr 20, 2017
    MarcHam likes this.
  11. Deleted User

    Deleted User

    Guest

    Is there a way to get semi-transparent realtime shadows like when using Unity's standard shader with "Shader Mode" set to "Transparent"?

    Here's what I'm talking about, above is Shader Forge with transparency and below is Unity's standard PBR shader:

     
  12. MarcHam

    MarcHam

    Joined:
    Apr 13, 2017
    Posts:
    1
    I'm looking to achieve the exactly same effect!
    Really curious to know how to proceed to get this effect done!

     
  13. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    Hey all. Just purchased Shader Forge and was trying to recreate this 'fake light fog' shown in the youtube video:


    Here's a frame in the video:



    Basically, it's a cone with a SF shader attached which has a falloff in the V direction of the UVs.

    Here's the node map the author shared with me:


    I recreated it exactly as shown but I get some sort of ghosting around the edges.
    Below is my node map and settings and here's the actual shader:
    https://dl.dropboxusercontent.com/u/3788438/3D/fogLight.shader

    Can someone please take a peek and let me know what I'm doing wrong? Thanks!

     
  14. marggob

    marggob

    Joined:
    Feb 24, 2013
    Posts:
    65
    You have negative values along the edges. Add a clamp after OneMinus node to remove it.
     
    hopeful likes this.
  15. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    Thanks marggob. That did the trick!
     
  16. DuvE

    DuvE

    Joined:
    May 22, 2016
    Posts:
    168
    How can I get direction from each vert towards center of an object?

    Here is my mesh:



    I collapsed each small cube to 1 vert in UV map, so I can move it with vertex offset node. It is possible to edit each vert's normal direction and direct all of them towards center, but it would ruin reflections.

    I want to replicate this effect:

    (16:37)
     
  17. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    wat

    Are the cubes all part of the same mesh? Or do you have 100 cubes hand-arranged into a sphere? If so...WAT, then maybe try this?

    Probably the one way you could do this is to find the world position of the center of the sphere. You'll need a script that finds it and passes that value (as X Y and Z components of a vector) to a material, which has a slot for it (it'll be a Vector4 in SF, but the 4th value doesn't matter here).

    Then, in the shader, you use a subtract node, with the 'world position' node and the XYZ components from your aforementioned center position plugged in.

    That will give you a worldspace vector pointing from the center of the sphere outwards.

    There'll be an option on the left for vertex offset, you probably want this in worldspace.

    Multiply the output from the subtract node by a slider (0-1) and plug that into vertex offset.
     
  18. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    I have 2 questions, not related.

    1. I'm hoping this should be fairly straightforward. I would like to change the difuse color of a mesh object based on world position. I have a lot of different candles in a store and would like to make them different colors without having to edit each and every one. Ideally, I would like to provide a set of colors of which can be used to choose from. Can someone provide me a strategy to start with?

    2. I'm thinking this may be impossible, but thought I'd ask anyway. In special effects and some rendering programs like KeyShot, they have the concept of a "shadow catcher." It is a shader which when applied to a ground plane (or other objects) shows a specified front projection image on top of it (screen space I believe) and then renders only the shadows and reflections of the scene objects on top of it.

    Here's an example of how it works. Below is a 3D model of a vaporizer. It is shown on a gray plane which shows both specular refelctions and shadows. As I mentioned, in some programs, you can turn this off so that the shadow is projected directly on the backdrop. It's used for compositing CG onto live pictures. Is this possible in Unity? If so, can someone help me understand the best way to do it (hopefully both for deferred and/or forward modes).

    Below it says transparent but I believe that is incorrect. It's actually using the same backdrop image as in the left frame.


     
  19. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    My post about this yesterday must've got wiped in the forum rollback, but I think this may be possible with SF.

    You'll want to get familiar with the custom lighting nodes and planar reflection.

    The reflection script can be found on the Unity wiki, and is invaluable. That'll get you a reflection because you can choose to use layers, and only render the object and nothing else. If you set the clear flags to black, that's basically the additive reflection pass done. Maybe try to add image effects like depth of field to the reflection camera? Might get you some blurriness.

    For the shadow, that might be accessable too. Create a new graph, and copy the Shader Forge blinn-phong custom lighting. Watch the Youtube video on it as well, because you're going to want to try and remove the normal contribution and spec lighting, leaving just the Light Attenuation part I think. Then, instead of plugging it into Custom Lighting, try putting it into emissive, and you should see a white plane with a black shadow. The next step should be setting the blend mode to Multiply, where the white will be invisible, and the black shadow will darken the background behind it. If the shadows are too dark, you can try remapping it from (0-1) to (0.5-1) or something. Maybe put a slider (0-1) instead of the 0.5 value so you can mess with it in the material inspector.
     
  20. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Also, solid water.

    It's rendered as 100% certified solid opaque object, in deferred, full shadow casting/receiving, motion vectors, works with all post processing (SS reflections, etc), has no sorting issues (because it doesn't need to, it's solid).
    solid_water.png

    Admittedly it does require 2 x 1024x512 render textures, for reflection and refraction. But since they're auto-frustrum-culled they don't hurt too bad.
     
    GeorgiSimeonov likes this.
  21. Fb01

    Fb01

    Joined:
    Apr 5, 2016
    Posts:
    6
    Hi could anyone tell me is it possible to bake out /generate uvw cordinates from a triplaner shader forge shader into the uwv channel of a skinned mesh

    (hope this question makes sense)
    thanks
     
  22. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    I'm not sure it is possible,
     
  23. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    Thanks, Jesus. I'll check it out. Much appreciated.
     
  24. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Hi everyone,

    I have been using Triplanar as an alternative for unwrapping simplistic objects such as walls, floors etc, but have hit a bit of a problem.

    My previous textures are tileable on both axis, my wood textures are not (because of grains etc), which is when I noticed that the shader doesn't tile correctly on the horizontal and depth axis.

    On either side of a cube for example, the Z axis faces are facing correctly (arrow up texture faces up), but faces on the X axis face Z+, instead of up.

    Kind of hard to explain but here:
    faces.png

    As you can see, the face on the right (on the Z axis) faces up as it should, but on the left doesn't.

    How can this be fixed? (shader attached)
     

    Attached Files:

  25. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    The problem face is the one with a surface normal in the +X Direction, yes?

    It's being fed U and V coords fromw orld position, swap them around. Right now it's pointing right instead of up, which means that currently U is -Y and V is +Z. That needs to be U = +Z and V = +Y.

    Plug what you've currently got into V into U and (negate node) what you're plugging into U and put that into V.
     
  26. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    Does anyone know exactly what the "Secondary Maps" do in the Standard PBR shader (below)? I know they are great for displaying close up fine textures, but how do they actually work? And, is it possible to add the same function to the default SF PBR shader?

     
  27. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    From memory, they blend over the default albedo and normal maps.

    For normals, it's easy. You've got your main normal map, and the detail one. Plug them both into a Normal Blend node. If you want to control the strength of the detail map, you can Lerp between (detail normal map) and (0,0,1) by (some Value or Slider...), then plug that into the Normal Blend from above with the main normal map.

    For albedo, it multiplies the detail texture by 2 (remap from 0-1 to 0-2) and then multiplies that by the albedo. I think. Plug that result into the Albedo slit and see if that works.

    What I'd do instead is blend between the usual Albedo and detail albedo by a Blend (Overlay) node. Either way, in both cases the detail albedo should be mostly 50% gray; and remember to set that as the default in the Texture2D node as well.
     
    chippwalters likes this.
  28. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    Last edited: May 8, 2017
  29. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Haven't downloaded anything, and skimmed the video, so forgive me if I miss anything.

    The mirror reflection script (the cs one) from the wiki needs to be modified. The clear flags need to be set to solid black. So go through, find clearflags, and change it from (whatever source camera is, usually skybox) to camera.clearflags.color by whatever means you feel like, and leave the line below about it copying the colour from the main camera (which you can then set to black on the main cam).

    I found out you don't even need light color. Just attenuation. Check out the graph below.

    Also, I found it works in forward+hdr, or deferred (no hdr required, but why wouldn't you anyway).

    Various controls for reflection strength, SOME ghetto smoothness for lighting the shadows so they're not pure black, and some other options.

    I DID commit the cardinal sin of doing ambient lighting (the second cubemap down the bottom) on a per-light bases (everything plugged into custom lighting is calculated per light). Forgive me Gaben, for I have indeed sinned. But if you're a 1-directional light kinda guy then surely we deserve some sort of pardon (not!).

    BTW, the cubemaps in the material, use the same cubemap as the skybox. Make sure the reflection texture slot is named ReflectionTex so the script can pick it up automatically. shadowcatcher_5min_ghetto_test.png

    Further work would be to use texture maps, not just sliders, for metallic, smoothness, etc...

    As you can see by the size of the plane in the scene view on the left, and the lack of any seams on the right, it does appear to be seamless, at least to my eyes.

    Haven't tried with any post effects, but the shadow catcher IS a solid object. But, since it's rendered in forward, you will need to check 'forward compatibility' or whatever in the post processing stack bits if it's there.
     
  30. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    Thanks a ton! Mostly working, but for some reason I can't get the reflections to show on the shadowcatcher mat other than the cubemap. I'm pretty sure I've copied exactly but you can see for yourself:

     
  31. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    Also, I was not able to find the "mirror reflection script (the cs one) from the wiki." Can you point me a link to it? Thanks. :)
     
  32. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    http://wiki.unity3d.com/index.php/MirrorReflection4

    You need the cs script from that. Then add that script to the shadow catcher plane.

    The script uses these lines to automatically add the reflection to the object's material, if the name for the Texture2D in Shader Forge is called ReflectionTex.

    foreach( Material mat in materials ) {
    if( mat.HasProperty("_ReflectionTex") )
    mat.SetTexture( "_ReflectionTex", m_ReflectionTexture );

    Just remember to change the lines that says:
    dest.clearFlags = src.clearFlags;

    to dest.clearFlags to clearFlags.color

    then comment out all this:
    if( src.clearFlags == CameraClearFlags.Skybox )
    {
    Skybox sky = src.GetComponent(typeof(Skybox)) as Skybox;
    Skybox mysky = dest.GetComponent(typeof(Skybox)) as Skybox;
    if( !sky || !sky.material )
    {
    mysky.enabled = false;
    }
    else
    {
    mysky.enabled = true;
    mysky.material = sky.material;
    }
    }
     
    antoripa likes this.
  33. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    Hi Jesus,
    Do you add the script as a separate C# script or do you include it in a SF CODE tile? If as C# script, can you please post the whole script with the "using System.Collections.." as well as I don't really know exactly where to place it. Thanks!
     
  34. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Here's the unitypackage. Import this, there's a scene in there go to that, and check things out.

    For some reason I didn't know you could upload unitypackages here...
     

    Attached Files:

  35. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    Thanks! I'll check it out. Much appreciated! :)
     
  36. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Out of curiosity, would something like that be worth me cleaning up, improving and putting on the asset store?

    I'm assuming you'd also want support for background that aren't just cubemaps/panoramas/skyboxes, but single screen-space images (like a picture of a desk, etc) or movies or some such, right?
     
  37. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    Absolutely! I'm teaching a VR + Unity course (no scripting obviously!) at Art Center to the teachers there next week and they would love to have something like this. It allows product designers to be able to very quickly visualize concepts. Most definitely check it out.

    If you do this, PM me (or contact me at chippATchipp.com) and I'll make a video tute for you on my YouTube channel (2K+ followers).

    youtube.com/user/cwalters56/videos

    Of importance would be to consider adding:
    1. GI on the shadow catcher.
    2. Blurred reflections on the shadow catcher.
    I'm also happy to help you with your STORE images, etc.
     
  38. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    This is exceedingly difficult. The lighting calculations are a pain in the ass on their own, but the biggest issue is building a worldspace area from screenspace using a panoramic image.

    Nonetheless, there's a world to walk around in, and UnityGuy (or, Steve, or whatever you call the 3rd person controller) can wander around the Unite stage, walk up the stairs, go down the isles, go behind the lectern, talk some smack about the filthy unreal users, etc....

    Light probe, Reflection Probe, HDR, etc light support in prelim stage. Still working out a decent way to add roughness information to the areas, maybe use deferred decals and write to roughness/metal?

    Note the reflections. Not only is the Unity logo reflection blocked by the guy's legs, but the reflections even handle the lectern hiding the far-right guy's arm. Also you can sorta see the shadow of the middle guy on the stage.

    walking_hdri.png

    tl;dr technically possible, just need to figure out this whole workflow thing before I can put it up.
     
  39. chippwalters

    chippwalters

    Joined:
    Jan 25, 2017
    Posts:
    68
    Wow, that looks great! What about blurry reflections and GI? Are those available?
     
  40. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    It uses normal Unity GI (probes, etc), but I'm still trying to find a better way to do blurry reflections.

    And the world building (even just blocking out shapes, etc) is a massive pain and isn't nearly as easy as you might think.
     
  41. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    it has been asked several times but i did not find any answer - how do i get standard unity environmet lightning and reflection on my custom lit shader?
     
    Last edited: May 14, 2017
  42. Argiris

    Argiris

    Joined:
    Nov 14, 2014
    Posts:
    23
    Hi everyone!

    I'll say upfront that I have no experience with shaders and I'm currently using Shader Forge just to create gradient materials in Unity.

    I would like to make the gradient you see at the bottom right of the image below, that is a 3-color linear gradient.



    Any ideas how I can achieve that?

    Bonus question: How can I affect the location of Stops (as they're called in Photoshop) to stretch a certain color over a wider area? In the image below I've changed the location of one Stop from 50% to 70%, to spread the blue tones.




    Thanks a lot in advance!
     
  43. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Lerp is typically done with a C (third input) of 0-1. With your example, you're using the V coordinate, which is entirely in the 0-1 range, so halfway up the side is 0.5, etc.

    If you want somewhere in the middle to be 100% red, you need to have the lerp between yellow and red be 100% (value of 1) at some point in the middle.

    The trick is using a remap node. Grab the full one (with 5 inputs) and plug the V coord from UV into the first node. Plug 2 static values of 0 and 1 into the second last and last inputs. For inputs 2 and 3, plug a static 0 and a Value (that you can edit, call it location) into them. Then, you want to plug the output into a clamp(0-1) node, then into the first lerp.

    Then, onto the second lerp. Make another remap node, plug the V coord into the same spot, and 0 and 1 into the 4th and 5th slots. This time, plug a 1 into the 3rd slot and link the Location into slot 2. Clamp0-1 again, then plug that into the C value of the second lerp.

    The Location value will be a 0-1 range (instead of 0-100%).
     
  44. Argiris

    Argiris

    Joined:
    Nov 14, 2014
    Posts:
    23
    Thank you for your reply, Jesus!

    I believe I did everything as you described it. I just named my variables StopTM & StopMB for top-middle and middle to bottom, but unfortunately I'm not getting the desired result.

    What have I done wrong?

     
  45. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Try this
    Check out what the remap nodes look like.

    You can split the (mid point) node into two separate ones, and have different values for each remap. This will basically just mess with hoe much yellow is in the image.

    doublelerp.png

    There's another way to do this as well. From scratch, have the 3 colors, and lerp between bottom and mid by V, and then lerp between that result and top by V. But, you have to multiply mid by 2. Also you won't get to control the mid point, but that method saves 2 remaps and clamps if you're absolutely hunting for extra performance.
     
  46. DuvE

    DuvE

    Joined:
    May 22, 2016
    Posts:
    168
    Need some help with cross section shader. So, I have a very simple shader for human model:



    But I want to fill the cross section with some color or texture. I tried to create another shader for a sphere with only backface visible. And I need to make backface visible only when sphere intersects human mesh. How can I achieve this?

    Maybe stencil buffer can help me, but I need to separate backface and frontface of a human mesh. So sphere can be visible only when backface of a human mesh is behind her.

     
    Last edited: May 24, 2017
  47. Argiris

    Argiris

    Joined:
    Nov 14, 2014
    Posts:
    23
    Hi Jesus.

    Thanks again for your help. I tried both your suggestions. None produced an equivalent of Photoshop's gradient.
    The simpler version worked in a strange way, as if the middle color was used to dilute the other two.




    I found this solution (not written in Shader Forge) and its result resembles Photoshop's gradient a lot more.

    Here's an image to see for yourself (from left to right: Photoshop/Jonathan/Jesus)



    I don't know how easily it could be rewritten for Shader Forge, but it would be nice to have, if anyone is up for it.
     
  48. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    What happened when you tried just replicating the one I posted as an image 1:1?

    And specifically what's the difference between it and the Photoshop goal?
     
  49. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Shader Forge is not working in Unity2017 :(
    when can we expect an update for it to work ?
     
  50. C_p_H

    C_p_H

    Joined:
    Nov 24, 2014
    Posts:
    153
    Discovered same issues here with Unity2017.1.0b6...
    He stated he got it working although ShaderForge doesn't have full support for betas. Go here for current details.
    We should be expecting an update a few weeks from now, hopefully.