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

    crudeMe

    Joined:
    Jul 8, 2015
    Posts:
    92
    I'm total fan of your work, especially I'm interested in "Physically based layered shader for Unity".
    Is it possible to make such a shader in SF with nodes? I mean, all that indexes and constants are pretty straightforward, but all other thingy) If so, any guides on that? :D
    Thanks!
     
    Last edited: Jul 16, 2015
  2. jjason08

    jjason08

    Joined:
    May 13, 2015
    Posts:
    15
    I am curious,
    Has anyone written any post processing effects/shaders for camera effects in shaderforge?
     
  3. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Yes, I have, and I think others have too.
     
  4. Deleted User

    Deleted User

    Guest

    How can i change the gradient/ramp of the "depth blend" node? I currently do this by way of multiple depth blend nodes subtracted/divided/blended with each-other but this is very heavy on performance. is there a simpler more efficient way?
     
  5. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I think you just have to figure out an algorithm that works for you.
    Also, each additional DepthBlend node is essentially just single Clamp0-1, Subtract, and Divide nodes. The depth is sampled only once, as far as I know.
     
  6. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    Hi.
    Thanks for the mention, but this is the ShaderForge thread ;) PM instead.
     
    DMeville likes this.
  7. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    Hello, I have a question about an error that I get.
    I can't use together:
    Lightmap & Light probes checked + Scene Color node in Emission + Refraction.

    Shader error in 'Shader Forge/ForceField': undeclared identifier '_Refraction' at line 496 (on d3d11)

    Compiling Vertex program with SHADOWS_DEPTH LIGHTMAP_OFF DIRLIGHTMAP_OFF DYNAMICLIGHTMAP_OFF

    Something else that I forgot.
    I wanted to make a pure emissive shader that could support GI.

    I begin with Unlit, then set up a color node multiplied by a value into Emission.

    I can't make it support lightmaps and light probes.
    So I set the Light Mode to Blinn-Phong, put a value of 0 in Diffuse and specular, then I check
    Lightmap & Light probes, change the light mode back to unlit and remove the value 0.

    Now I have an unlit emissive shader that support GI even if now lightmap & lightprobes is notchecked anymore.

    It looks like a "hack" to me, and I don't think I should be doing that. What should I do to have an emissive shader that support GI on a static object without doing this weird trick?
    I chose Unlit because I don't want the objet to receive any light since it'll act as a light itself.
     
    Last edited: Jul 17, 2015
  8. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    We are using SF 1.12 (for some odd reason we didn't update - I will do that soon) and we are experiencing a weird shading issue that seems to be related to the binormal and tangent calculations.
    Our scene consists of ground tiles that are mapped in worldspace (albedo, normal, metallic). And we see huge shading differences of neighbouring tiles when they get rotated or their UVs get rotated. Our normal map is a custom map where x and w are swizzled on texture import and swizzled again in the shader.
    I know that might not be the best description but I'm at work currently and don't have the time to show you the issue in action (via gif) and the relevant swizzling part in the graph.
    Is there anything going on under the hood when a texture is not flagged as normal map in the texture property node?
     
  9. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Rotating UVs for normal map sampling won't actually rotate the binormals and the tangents, which is why it looks weird. One does not simply rotate normal maps :)
    That being said, it's possible to compensate for it, though I can't remember how at the moment.
     
  10. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Not sure what could be causing this. I'll look into it for the next update
     
  11. Deleted User

    Deleted User

    Guest

    DX11 Tessellation question: When i apply a mask to tessellation, the areas with 0 tessellation (black part of mask) is non existent; there is no mesh there. Is there a way to have tessellating and non tessellating areas on one mesh?
    Example picture
     
  12. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Try remapping it to make the lowest value 1 instead of 0
     
  13. Deleted User

    Deleted User

    Guest

    i remapped the tessellation mask from 0.1 to 1 so there are no 0 values now, I think this fixes it... but doesn't this mean -although i cant see it- tessellation is still applied over the whole mesh? I don't want ANY tessellation where i don't need it)?

    I cant set the min value to 1 as the max value cant be above 1 (it is mask based tessellation and i don't want to lighten the mask above 1)
     
    Last edited by a moderator: Jul 17, 2015
  14. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Yes, since they are called Tangent space normal maps they are locked to the UVs. And rotating UV Islands without also shifting the normal map values results in weirdness :D
    The problem we face is that we want the world position to be the only UV-giving variable. But our SF shader seems to also incorporate the mesh UVs additionally. I'll post some shots and a simple repro case tomorrow.
     
  15. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    Hi guys! I have done a lot of shaders with panners but now I am trying to pan a cubemap but I really don't know how to do that because I need an UV slot in the cubemap. Some ideas? I want to achieve a panning spacebox. Thanks for your help!

     
  16. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Mask out the R and B components of the view vector, rotate using the rotator node, then reconstruct it using the append node
     
  17. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Hey guys,

    I'm trying to convert a shader to Shader Forge so that i can better play around with it. I would like to add a distance based dissolve (Almost have it actually but it doesnt integrate nicely with a color based ramp effect that i have).

    Most of the things in the frag() section makes sense and i know how to convert but what exactly does the vert() section do? Is this a per vertex calculation thing?

    Code (CSharp):
    1. Varys vert ( VertInput  ad )
    2.             {
    3.                 Varys v;
    4.                 float per;
    5.  
    6.                 v.pos            = mul ( UNITY_MATRIX_MVP, ad.vertex );
    7.                 v.tc1               = ad.texcoord.xy;
    8.  
    9.                 // ramp tyexture is left close right = far .. then up/down is under user control see _RampV property
    10.                 per                = clamp ( abs ( v.pos.z ), 0.0, _MaxRampDist ) / _MaxRampDist;
    11.                 v.rampTC         = half2 ( per, _RampV );
    12.  
    13.  
    14.                    v.fxTC             = ( _EffectTex_ST.xy * ad.texcoord.xy ) + _EffectTex_ST.zw ;
    15.                 v.fxTC          += half2 ( _EffectXSpeed * _Time.y, _EffectYSpeed * _Time.y );
    16.  
    17.                 UNITY_TRANSFER_FOG(v,v.pos);
    18.  
    19.                 return v;
    20.             }
     
  18. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    As promised here are some pictures showing the issues:

    shading_issue_on_objectrotation_uvrotation.gif sf_pbr-terraintiles_sf_test_7182015.png

    I would expect the default material inspector parameters of the texture property to not have any effect on the final uv mapping when the UVs get overridden as in the shading graph above. But they still affect the texture sampling. And I believe that might be one of the possible places where the shading issue might stem from.
     
  19. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    There's a whole forum dedicated to shaders you know? Shader Forge shaders are more of a node/visual thing, only digging into the code for optimization and stuff.
     
  20. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    I should rephrase then and ask how one would convert the vert() to a shader forge node setup. I understand the nodes required, just a liiiittle unsure about if the vert stuff means using vertex color nodes
     
    Last edited: Jul 18, 2015
  21. Deleted User

    Deleted User

    Guest

    so is it possible to have a mesh part-tessellated and part not tessellated AT-ALL?
     
  22. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    Thanks for the tip I haven't thought this out! The spacebox starts rotating very well but in some moments it's deform very hard. Maybe that's the way a cubemap behave when rotating and I need to think in some other thing to get the effect that I am looking for.

     
  23. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    I have tried with View Refl. and it seems to work much better!
     
  24. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    It seems we cannot use the tangent direction that is passed into the vertex shader via vertexinput struct. So I tried to remember how it was done in terrain shaders and came up with this replacement I manually edited into the shader code:
    Code (csharp):
    1.  
    2. o.tangentDir = float3(1, 0, 0);
    3. o.bitangentDir = cross(o.normalDir, o.tangentDir);
    4.  
    That tangentDir is making an assumption which should work pretty well for our case. But I remember that there was an additional check to determine the tangent.w component of which I do not know its neccessity.
     
    Last edited: Jul 19, 2015
  25. elamhut

    elamhut

    Joined:
    Sep 13, 2013
    Posts:
    45
    Hey guys,

    First time posting here! Sorry if I say something stupid, I just started studying how to make shaders (previously I only used them without making them :p)

    So, searching here on the forum I managed to put together a frankesntein of a shader based on 2 nodes that were here (one to make squares and a dissolve shader). I managed to make some alterations (making a part of the square glow and adding some colorization).

    There are 2 things I wanted to ask:
    1) Is it possible to make the dissolve shader have a direction? (For instance, from bottom to top) I tried using Object and World Position nodes unsuccessfully :( (I also don't want to lose the noise texture)

    2) Is it possible to remove seams like the hands of the character in the GIF below?

    My programmers tell me that both problems could be solved by remapping the UV using a cilinder shape, can you do that in shader forge? Or is there another epic solution to the issue?

    Thanks a lot you guys, Shader Forge is crazy awesome :) sf_spawn_shader_7182015.png Spawn_Shader.gif
     
  26. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    I did it in a shader by using a couple Vector4 inputs to represent a plane's position and normal. You subtract the plane's position from the World Pos. node and if you Dot the plane's normal with this, you can use this to clip the object or do whatever. Obviously if you want it to animate, you have to control this from an external script.



     
  27. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
    The UVs have to be edited in an external program. Blender for example.
     
  28. elamhut

    elamhut

    Joined:
    Sep 13, 2013
    Posts:
    45
    Hey Obsurveyor, thanks a lot for the quick reply! :D
    I had reached a similar conclusion, the thing is, is that when I move the object around in world space the dissolve shader stays linked to the world (check out the gif) so if I move the character up its texture appears, if I move him down he becomes blue. I wanted the effect to go along with him. (Maybe I did something wrong?)

    Spawn_WorldPosBug.gif

    Hey DaDarkDragon! :D
    I don't really wanna open Maya and do that stuff to our main character (our modeller would KILL me). There are shaders that can remap the UV on the fly, or make procedural stuff that organically covers the mesh so there are no seams. I didn't want to go procedural because its super heavy. I was just wondering because our programmer told me he could do that using code (do a cilindrical map), I was wondering if I could it as well in SF :D (I hate taking programmers time to do this stuff)

    Thanks a lot for the reply :)
     
  29. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    It's been awhile since I messed with my shader and in fact, it took me awhile to even dig it up. It's possible that the nodes I posted were out of date because mine does the same thing. One way to fix it would be to update the plane's position in the script, setting it to the object's position then animating that. This may have been what I was doing in my scripts.
     
  30. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
    @elamhut thats because the value is static. you'll need to take the robots position and possibly rotation into account in the shader.

    as for the UVs maybe try taking a look at how I did the hologram shader in the wiki, specifically the scan-line part at the lower right.
     
    DMeville likes this.
  31. elamhut

    elamhut

    Joined:
    Sep 13, 2013
    Posts:
    45
    Wow! Nice tip! I'm ALMOST there!

    Spawn_ObjectPosBug.gif

    ss+(2015-07-18+at+11.07.15).jpg

    The only problem now is that the dissolve appears on the head and arms before its supposed to, I guess it because the ObjectPosition is per object (so it's taking each pivot separately), I would guess that if I were able to grab the PARENT position this wouldn't happen. Is that right? Do you think there's any way I could solve this?

    @DaDarkDragon I solved part of the puzzle because of the second tip (now the dissolve follows the character)! I'll DEFINITELY take a look at your Hologram shader, I glanced it really quick before and I loved it :D

    Thanks A LOT, you guys! :D
     
  32. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    I'm trying to convert a shader to use shader forge nodes. The shader maps a ramp texture onto an object based off of distance.

    I'm having difficulty getting it into shader forge. Specifically what is happening in the vert() of the shader.

    Code (CSharp):
    1. Varys v;
    2.                 float per;
    3.                 v.pos            = mul ( UNITY_MATRIX_MVP, ad.vertex );
    4.                 v.tc1               = ad.texcoord.xy;
    5.                 // ramp tyexture is left close right = far .. then up/down is under user control see _RampV property
    6.                 per                = clamp ( abs ( v.pos.z ), 0.0, _MaxRampDist ) / _MaxRampDist;
    7.                 v.rampTC         = half2 ( per, _RampV );
    The math is all straight forward and i made a good attempt in the bottom screenshot. But i'm not entirely sure how to handle the Varys. RampTC are:
    Code (CSharp):
    1. half2 rampTC        : TEXCOORD1;
    I've been going through Shader Forge, looking for a node that let's me turn the two value's into a UV set but i couldnt figure out how to do that or if i even understood that bit correctly.

    Is someone able to point me in the right direction?
     

    Attached Files:

  33. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    This is where my original situation would work, instead of using Object Position, use World Position and just update the _PlanePosition via a script, setting it to the the current offset(for animation) + the parent object's position.

    Superflat, I think you can just use an Append node? edit: Nevermind, misunderstood what you were asking. I can't find any documentation on what that Varys means. Is this a data structure that is created in the original shader(if it is, it is very poorly named)? Can you post the entire thing?
     
    Last edited: Jul 19, 2015
  34. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    sorry, i should have elaborated. I assumed that was the basic naming convention. It's the input struct into the vert() function.

    Code (CSharp):
    1. struct Varys
    2.             {
    3.                 half4 pos            : SV_POSITION;
    4.                 half2 tc1            : TEXCOORD0;
    5.                 half2 rampTC        : TEXCOORD1;
    6.                 half2 fxTC            : TEXCOORD2;
    7.                 UNITY_FOG_COORDS(3)
    8.             };
    [EDIT] After some thinking and trying i managed to get it somewhat working. Though it does behave a little weird with a certain distance the ramp texture becomes transparent so its not very consistent. I managed to get it working by using a code node and outputting a half2 with the value's i needed.
     

    Attached Files:

    Last edited: Jul 20, 2015
  35. Ga2Z

    Ga2Z

    Joined:
    Feb 16, 2012
    Posts:
    68
    Hello. Does anybody know how could I make the transmission work with a light pointing directly and not just from the back? I would like to reveal a texture when I lit the object, so I tried using the transmission in the shader but I think is not the best approach.

    Light is being projected from the caharacter´s hand and is a Spotlight. I would light to get this effect but whem I project light directly to the object ando not from the sides or the back. Thanks!!!

    Transmission.png upload_2015-7-21_11-54-58.png
     
    Last edited: Jul 21, 2015
  36. RenOli

    RenOli

    Joined:
    Jan 23, 2013
    Posts:
    102
    I found two bugs at SF...

    1 - The lights that are hitting a mesh that has a SF shader shows on the fog . I tested with custom unity shaders and it doesn't happen.

    upload_2015-7-21_21-4-10.png

    2 - The Double sided is not working, I have to manually go to the shader and add Cull off on all pass blocks.

    that is all.

    Best regards.
     
  37. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Good catch - will fix this for the next version

    Can you show me how to make a shader where it happens? I've never had this happen before
     
  38. RenOli

    RenOli

    Joined:
    Jan 23, 2013
    Posts:
    102
    Oh my, you are really fast hahahaha.. what an amazing support ...

    1 - Glad to hear about that.. :)

    2 - I just remember about one information that will help. The only thing that we can see through is the shadow.

    I just created a new shader, the only thing I did is double sided, and here is the result.

    upload_2015-7-22_0-34-27.png

    if I go through each pass and add Cull Off it will work as expected.

    Thank you very much for your support.
     
  39. RenOli

    RenOli

    Joined:
    Jan 23, 2013
    Posts:
    102
    Here is a better and brighter example, hehehe

    upload_2015-7-22_0-39-12.png

    this is the back side of the plan

    In this shader the Cull Off is in all pass.. so I don't think this is the fixer.
     
  40. KarolisO

    KarolisO

    Joined:
    Feb 2, 2014
    Posts:
    30
    I am looking to create an object outline shader with a selectable outline colour. The trick is that the actual model should be see-through, so that only the outline is visible.

    Does anyone have any idea on how to achieve this?

    Thanks in advance!
     
  41. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Would this help? Quick google: https://gist.github.com/thebeardphantom/c4b9de370425c8dbd7ea
     
  42. KarolisO

    KarolisO

    Joined:
    Feb 2, 2014
    Posts:
    30
    Last edited: Jul 22, 2015
  43. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Cant you just apply the alpha all over your diffuse map? Granted i'm a shader newbie.
     
  44. KarolisO

    KarolisO

    Joined:
    Feb 2, 2014
    Posts:
    30
    I think that'd render the lines on the other side of the object, which is not desired. :S
     
  45. ArthurClark

    ArthurClark

    Joined:
    May 12, 2013
    Posts:
    15
    How do I clip the texture? For example I need a moving texture that is NOT shown all at the time but instead it shows only a part of itself and can be moved along the surface by changing some value. What I mean is:
     
  46. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    I have an alpha question for @Acegikmo though:

    Earlier in the thread you were helping @Amnoon with alpha sorting. Explaining that transparency is a hard thing to do in any engine, what with see-through geometry and what not.

    Is it possible to apply an alpha mask to an object and create a gradual fade from bottom to top? Bit like a clipping mask and just mask out the object that way?

    I'm playing with the UV's and multiplying them with a value. Added a power node to make the edge harder. I've set the transparency mode to Alpha blended but that's just make the geometry transparent base on it's uv's as well as the see-through geometry.
     

    Attached Files:

  47. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    334

    Hi, i quoted my old post regarding the weird effect of shader i am trying to make which is as quoted.
    i think this might be a bug!! here is what i found.

    i have made another shader, which is basically a shader that behaves like texture atlas, and it renders 4 types of texture split around equally.
    which is here (i dunno why shaderforge don't render nodes correctly)
    sf_atlasshader_7222015.png

    Then later on i noticed this odd thing..
    the shader does not "repeat" as expected when the vertices are out of the uv bounds. also when i examined by previous shader, the effect seems also to happen as well when the vertices go outside uv bounds..
    both shaders fails to repeat textures when model vertices exceed certain distance away from bounds. image>>

    outboundissue.jpg

    is this a bug? or am missing a node i should use to fix this?
    i need shader to repeat textures in all uv directions as expected.
    am using latest shader forge version.
     
    Last edited: Jul 22, 2015
  48. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @mangax Is the texture you're applying to your material set to "clamp" or "repeat"?
     
  49. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    334
    its all set to repeat , textures & normals
     
  50. BigDill

    BigDill

    Joined:
    Jan 1, 2013
    Posts:
    31
    Hi all experienced Shader Forge Users.
    Following Ace's original advice I have had a huge amount of success learning to use SF. So thanks Ace.
    Can anyone tell me what is more efficient for blending textures, Channel Blend or a chain of Lerps? I have both methods working really well but I want to deploy to a mobile platform and I am not sure which one would be the most efficient use of GPU and memory using SM3 or SM2. Can anyone on this forum offer me some advice?

    Thanks.