Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. bmccall1

    bmccall1

    Joined:
    Jul 28, 2013
    Posts:
    120
    Ace, I think you deserve all the accolades thrown at you, this product is great.

    So, renaming my diffuse textures MainTex seems to have solved like 90% of my issues. Are there any other tips to working with beast I should know about?
     
  2. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Thanks alot dude. Of course you can.
     
  3. Jebus

    Jebus

    Joined:
    Sep 17, 2011
    Posts:
    18
    Incredible work Cactus, it looks fantastic in motion.
     
  4. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    I want to make a simple clipping shader with shaderforge, where the clipping is defined by a plane (its normal vector) in 3d-space.
    So when I move the object in world space and parts of it goes under the plane these will be clipped.

    Could anyone tell me how?
     
  5. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    There are quite a few, that I sort of want to forget because it's so, backwards and weird / o\
    There's some information here, especially at the bottom of the Material Properties section:
    http://docs.unity3d.com/Manual/LightmappingInDepth.html

    You'll most likely want to clip by using the world position node's G component, which is the Y position. Try simply plugging it into the alpha clip input :)
     
  6. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    No, I want to be able to rotate the clipping plane in all possible directions, so I believe I have to pass its normal vector to the shader. But don´t know how to go on in Shaderforge...

     
    Last edited: Aug 14, 2014
  7. Cactus on Fire

    Cactus on Fire

    Joined:
    Mar 4, 2014
    Posts:
    8
    Thanx brah. Glad you liked it.
     
  8. c2j

    c2j

    Joined:
    Jul 27, 2013
    Posts:
    11
    Ace, please, can you help me with my problem ? :)
     
  9. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    577
  10. aCallum

    aCallum

    Joined:
    Oct 8, 2012
    Posts:
    5
    Help with Vertex Offsetting.

    So I'm trying to convert a shader previously written in XNA. It's a sort of 'rolling horizon' shader typically seen in infinite runner games, anyway I used it to create the environment for Retro Rocket Rampage.

    Anyway, I've pretty much got the basics down with the following graph:


    The idea is, that the vertices (WorldPos.) are adjusted in height by the square of the distance from an average game world position (AvgPosition) - this causes an effect of a rolling sphere, without the need for complex spherical geometry.

    However, this only appears to work correctly on meshes that have zero rotation, here you can see the plane and left cylinder have been modified correctly, but the right cylinder (with a rotation of 90 degrees Z) has failed to adjust (it should be at the same height as the vertices in the plane below it)



    If anyone can shed any light on what may be causing this, that would be great - my only thoughts have been there is some issue with conversion between local/world translations of the vertices once the mesh is rotated?

    [EDIT] Its amazing what a little time can do.. Looking back I just shoved in a Transform(World to Local) and I *think* it's working now.. I will keep playing but any advice as to -why- this works will be great

    [EDIT 2] Well, I think that has cracked it, sharing this to show exactly what I was aiming for..

     
    Last edited: Aug 15, 2014
  11. aCallum

    aCallum

    Joined:
    Oct 8, 2012
    Posts:
    5
    Now that issue is out of the way, I wanted to ask about Vertex Normals. Now conventionally this is not a shader thing as it's handled by the modelling program or the unity importer. However, I'd love to know if shaderforge has the capability to render hard/soft normals? Or is this exclusively a mesh related attribute?
     
  12. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    I have a feature request I think would be simple to implement, though I don't know how many would find it useful. A check box for hiding a property from the inspector. I'm making a set of shaders that need properties that are accessible through script, but I want them hidden from the inspector, so I'm adding [HideInInspector] to certain properties in the .shader file. However, every time I open shader forge that gets removed.
     
  13. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    This seems like a difficult effect to make, especially where you want the clipped section to be re-rendered, as if the object is volumetric. You may be able to do something by passing the plane position and the plane normal using either global variables or exposed Vector4 properties.

    This should be about the same as just using regular transparency and enabling depth buffer write. Although it won't be vertex lit, it'll be lit per-pixel still.

    Yeah, usually this is handled in the mesh itself, and there's not really any way to detect hard vs soft "edges" on a shader level, without going into the DX11 geometry shader stuff (you can modify normals though)

    This should be pretty straightforward to implement. Could you request it on the feedback/UserEcho page?
     
  14. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Done. I also offered some potential use cases for it. I did also want to ask, are you working on/considering working on a way to more easily make terrain shaders with SF? I've finally got the splatting stuff and the firstpass, addpass, basemap thing going but I still for the life of me can't get normal maps working.
     
  15. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    577

    You can see what happens there, if that can be fixed then its working.
     
  16. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    Hello! Before asking my question I want to thank you for this great tool!

    I am trying to make a shader that makes an object dissapear using Alpha Clip controled by a slider, this part works fine. But I also want it to have an emissive color around the dissapearing parts.

    Here is my shader.

    Thank you!

    Edit : I'm not looking for the full solution btw, just some tips. I don't want to come here and ask people to do everything for me :)
     

    Attached Files:

    Last edited: Aug 17, 2014
  17. c2j

    c2j

    Joined:
    Jul 27, 2013
    Posts:
    11
    Really Sad for me :( Ace reply to all for helping, but not me..
     
  18. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    I tried something for you. It changes the color of the object with the shader depending on his position on Y (100). I don't know how to do this acording to another object position.
     

    Attached Files:

  19. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
  20. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    The terrain dependency system is a bit of a mess in the shader. I would recommend not using Unity's terrain system, and instead use your own mesh where you have normals and such defined properly.
    I think the problem is that Unity's terrain don't generate tangents, and instead directly use the normal map as an object space normal map.

    That's a general problem with alpha blending, there's not much you can do about it at the moment.
    I would recommend using alpha clipping instead of alpha blending, and you'll get both proper shadows and proper depth sorting.

    I don't know what you need help with - your previous posts seemed to have you thanking about two people helping you out
     
  21. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    I see. That sounds liberating and terrifying at the same time. Hurdles that come to mind are the 65000 vertex limit on meshes, dynamic tessellation, collision, and loss of all terrain editing in the editor.
     
  22. c2j

    c2j

    Joined:
    Jul 27, 2013
    Posts:
    11
    They didn't sadly, maybe too busy (its hollidays i understand). What i need Ace, is to know how can i make a shader who can change with time between two textures (From day to night) its what i want to achieve
     
  23. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    C2j, I gave you something to experiment with, try to do something with it, maybe you'll find what to do :)
     
  24. c2j

    c2j

    Joined:
    Jul 27, 2013
    Posts:
    11
    Thanks i will try it ;)
     
  25. Bluntie

    Bluntie

    Joined:
    Jun 11, 2013
    Posts:
    10
    I'm in the process of making a worldspace texture to rapidly texture landscapes, but I've run against a bit of a wall now. I've managed to get it to map to worldspace and use same texture on all sides, but now I would like to get a secondary texture that only maps to the top of the mesh. Basically, for putting grass on top of a rock. I could simply map it into my current setup, but that would mean the secondary texture would appear both on the top and the bottom of the mesh. Plus, I'd really like to be able to control the transition with a mask texture of some kind.

    Anyone have any fancy ideas or tips they feel like sharing? And if you spot anything in the shader that could be optimized in general, feel free to suggest. :) sf_triplanar_-_diffuse_8182014.png
     
  26. wsz

    wsz

    Joined:
    Oct 20, 2012
    Posts:
    19

    For the depth sorting you can split each element in one object. Maybe works.
     

    Attached Files:

  27. Bluntie

    Bluntie

    Joined:
    Jun 11, 2013
    Posts:
    10
    Am I the only one or is anyone else unable to get version 0.36 on the Asset Store? All I can get is 0.35, despite the note on top saying 0.36.
     
  28. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Same here
     
  29. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    How to create a glow shader with a smooth transition to the transparency as in the picture. I did shader glow, but I need a more interesting transition to transparency

    My current shader.For glow i turned on HDRI on camera.

    This effect on the video
     
  30. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    I was trying to help you , but I needed to animate this using the animation system. But it looks like I can't make it work. I have to use a script but it's a lot harder to make the animation I want =/

    I think it is just that the alpha is set smoothly to 0.8, and when the emission is almost at 0, the alpha is set to 0.

    Or maybe you' re talking about the emission centering on the object over time?
     
    Last edited: Aug 19, 2014
  31. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    Yes, second, emission centering over time
     
  32. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    I tried something, I think that if an object is too complex, the uvs will mess up the emission. Maybe changing to uv1 will fix that. I think that lightmaping uses uv1, i'm not sure about what will happen hahaha. D3.jpg
     
  33. c2j

    c2j

    Joined:
    Jul 27, 2013
    Posts:
    11
    very interesting shader ! Do the glow is in one shader ? Or do you change the shader of the object in runtime ?
     
  34. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    I didn't think about that yet :) I was just trying to make something that looks like the animation in the video.
     
  35. Kivak

    Kivak

    Joined:
    Jul 13, 2013
    Posts:
    140
    I am trying to create a shader which adds snow to a terrain grass mesh. The shader works exactly the way I want (for now), but it doesn't seem to be affecting any of the grass on the terrain. However, if I take one of the grass models and put it in Unity without being on the terrain, it looks exactly how I want. Is there something wrong with my node structure that is in error?

     
    Last edited: Aug 20, 2014
  36. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    @Vladnes : You could probably Lerp between the glowing and normal phase to get that smooth transition. Use vertex colors on your model to tell the shader where the glow should focus (Color the center of the object with the lightest color of the specific channel you choose and fill the rest of the object to create a sort of round gradient towards a darker color from the center) . And of course use a bloom post-effect.

    @c2j : Same as above, use the lerp node, input your day in A or B and your night in the other, choose one of those four waveforms to input into T.

    @Kivak : What Ace posted on the last page could perhaps help you :
    "The terrain dependency system is a bit of a mess in the shader. I would recommend not using Unity's terrain system, and instead use your own mesh where you have normals and such defined properly.
    I think the problem is that Unity's terrain don't generate tangents, and instead directly use the normal map as an object space normal map."
     
  37. Kivak

    Kivak

    Joined:
    Jul 13, 2013
    Posts:
    140

    So the terrain dependecy system affects the trees and detail meshes as well? That seems rather strange. I thought that detail meshes and trees were treated differently than the splat textures. I don't think I can make my terrains into meshes and keep my terrain texture shaders. AFS seemed to be able to do something similar to this without requiring the terrain to be made into an object mesh.
     
  38. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    I have a question kind of related to Shader Forge, i need to use a depth texture for a standard intersection fading but i already use the light attenuation node and other nodes exclusive to forward rendering so i can't really go deferred.
    The depth texture generated by this line :
    Code (csharp):
    1. Camera.current.depthTextureMode = DepthTextureMode.Depth
    seems rather inaccurate as seen below

    It isn't linked to the shader itself since unity's soft particles render the same.
    It might be unrelated to the depth texture precision, i dont really know much about those but i saw on that page that the number of bits vary with respect to the platform, is there a way to get the same render as the deferred one in forward rendering ?
     

    Attached Files:

    • Fwd.png
      Fwd.png
      File size:
      48.8 KB
      Views:
      1,901
  39. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    @Dimlos Thanks, but it is not working well.

    @Eideren I did as you advised shader, vertex colors should be drawn in 3D program like Maya?
    Here is what I got:

    Is it possible to create a shader that he will find the edges and center of the silhouette of the mesh and make the transition from the center to the edges?
     
  40. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    @Vladnes : Well, actually i have a better solution than the one above, here is the node tree and the ingame render :

    It's just an inverted fresnel. Remember to activate HDR on your camera and add a bloom image effect.
     

    Attached Files:

  41. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    @Eideren Thank you, Fresnel works well on the sphere, but on a more complex mesh no transition.
    Here's how it looks:
     
  42. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    @Vladnes The Exp node should help with that but if it still isn't the case then you probably need more geometry on your mesh or a normal map.
     
  43. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
  44. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    That reversed Fresnel was a brilliant idea :D
     
  45. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    @Eideren For your shader can be connected world space gradient or something similar?
     
  46. Bluntie

    Bluntie

    Joined:
    Jun 11, 2013
    Posts:
    10
    Does anyone have an idea for how I can do a shader that has a secondary texture that only renders "on top" of a mesh, like grass would for instance? Ideally I want to have a mask texture between the two, and a slider for determining at which inclination the change should occur, but I'm fairly sure I can figure those out on my own once I have that crucial beginning down - but I seriously cannot figure it out.
     
  47. Kivak

    Kivak

    Joined:
    Jul 13, 2013
    Posts:
    140
    I think you just need a heightmap and select a certain height range as a mask for the texture. :)
    For example, snow... Think of TexA as the terrain texture and TexB as the snow. You could use a Step (for abrupt changes) or a Remap (for smoother changes) (or something else someone might bring up) on the heightmap for TexA to isolate the height range you want to fill. Then, using that height range as a mask, use the Multiply node with TexA, TexB, and the mask as inputs (from top to bottom). You may also find the "clamp" node useful if you use the Remap option. :)
     
    Last edited: Aug 22, 2014
  48. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    If you need to apply the bloom based upon the object's height then that should do the trick :

    You mean, like that ?
     

    Attached Files:

  49. Kivak

    Kivak

    Joined:
    Jul 13, 2013
    Posts:
    140
    I am trying to not re-invent the wheel... has anyone converted the default "WavingGrass.shader" shader into a ShaderForge file? I would LOVE to get a-hold of it. I really need to override the shader but I don't know enough about the specific code in it to duplicate it yet.
     
  50. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    I still get this error "undeclared identifier 'viewDirection' in .35, using ViewDir when trying to billboard polygons.

    I noticed that viewDirection is being calculated here:

    fixed4 frag(VertexOutput i) : COLOR {
    float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
    SHADOW_CASTER_FRAGMENT(i)
    }

    Is this the correct place?
     
    Last edited: Aug 24, 2014