Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    Did you try to close SF, open it again and delete those nodes ? Everytime this bug shows up, i do the same thing and it goes away.

    I did some basic NPR shading, screen space halftoning and screen space fake cross hatching.
    Untitled.png
    Feel free to pm me or post in this thread if you would like to see the node tree or shader code.
     
  2. sundance

    sundance

    Joined:
    Mar 19, 2014
    Posts:
    52
    Hi, its always interesting to explore some good custom lighting solutions :)
     
  3. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    I had some people who asked me about those node tree in private so i'll share it here as well.

    SF_Halftone.png

    The halftone is pretty straight forward.
    Remap tiled Screen Pos. node to get the same value-gradient as a UV Coord then tile it according to the dev's preference.
    Frac. node repeats the same value-gradient, the remap and length combo generates the circle gradient pattern then the power node scale those circle by the light/shadow input and the last Round sharpen the gradient to a normal circle.

    SF_Hatching.png

    Hatching is a mess, i dont really know how i could optimize the node tree to something a little bit simpler without using textures ( it's far more interesting to avoid using them but i would probably use one if i had to create a game with that shader ).
    Of course it isn't real hatching, the shader scales the two lines using light input, real hatching would use more line the more shaded the zone should be, I tried to do something close to that at first but it actually wasn't that pretty ( the node tree was even more stupid too but that wasn't really what made me delete it )

    The nodes connected to the UV Rotator by the ang input are the degrees to radians translation, you probably dont need some of them if you are comfortable with radians.


    I would love to see what you can do with this shader !
     
  4. dart4140

    dart4140

    Joined:
    Nov 25, 2013
    Posts:
    2
    Hi,

    I don't know If this is the right place to post this, but Is it possible in ShaderForge to feed the shader with array of colors with variable length ?

    Thanks !
     
  5. RUBILYN

    RUBILYN

    Joined:
    Jun 22, 2013
    Posts:
    54
    HI EVERYONE ! <3

    Can Someone be kind enouph to send a package or Show the Nodes on How to convert and do this exact BRDF Shader into SHaderforge. Please ... !

    My idea is to Pick on Zbrush matcaps / Alter them also in photoshop and translate correctly the Zbrush matcap to Brdf Shader in Shaderforge.

    I think is possible and there is this shader bellow but might need some kind of "nodes Magic" to make "Proper" BRDF MatCaps from ZBRUSH be Equal Looking in Unity ...

    I think this would be reaaly a greath thing for all us if someone can port the code bellow to shaderforge nodes.

    Can someone That understands how try it for us please ?

    THANKS SO MUCH.



    Code (CSharp):
    1. Shader "MatCap Normal with Extras!" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
    4.         _BumpMap ("Bumpmap (RGB)", 2D) = "bump" {}
    5.         _MatCap ("MatCap (RGB)", 2D) = "white" {}
    6.         _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    7.         _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    8.         _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    9.     }
    10.  
    11.     Subshader {
    12.         Tags { "RenderType"="Opaque" }
    13.         Blend AppSrcAdd AppDstAdd
    14.         Fog { Color [_AddFog] }
    15.  
    16.         Pass {
    17.             Name "BASE"
    18.             Tags { "LightMode" = "Always" }
    19.      
    20.             CGPROGRAM
    21.                 #pragma vertex vert
    22.                 #pragma fragment frag
    23.                 #pragma fragmentoption ARB_fog_exp2
    24.                 #pragma fragmentoption ARB_precision_hint_fastest
    25.                 #include "UnityCG.cginc"
    26.                 struct v2f {
    27.                     V2F_POS_FOG;
    28.                     float2  uv;
    29.                     float2  uv2;
    30.                     float3  TtoV0;
    31.                     float3  TtoV1;
    32.                 };
    33.                 uniform float4 _BumpMap_ST;
    34.                 uniform float4 _MainTex_ST;
    35.                 v2f vert (appdata_tan v)
    36.                 {
    37.                     v2f o;
    38.                     PositionFog( v.vertex, o.pos, o.fog );
    39.                     o.uv = TRANSFORM_TEX(v.texcoord,_BumpMap);
    40.                     o.uv2 = TRANSFORM_TEX(v.texcoord,_MainTex);
    41.                     TANGENT_SPACE_ROTATION;
    42.                     o.TtoV0 = mul(rotation, glstate.matrix.modelview[0][0].xyz);
    43.                     o.TtoV1 = mul(rotation, glstate.matrix.modelview[0][1].xyz);
    44.                     return o;
    45.                 }
    46.          
    47.                 uniform float4 _Color;
    48.                 uniform sampler2D _BumpMap;
    49.                 uniform sampler2D _MatCap;
    50.                 uniform sampler2D _MainTex;
    51.          
    52.                 float4 frag (v2f i) : COLOR
    53.                 {
    54.                     float4 texcol = tex2D(_MainTex, i.uv2);
    55.                     // get normal from the normal map
    56.                     float3 normal = tex2D(_BumpMap, i.uv).xyz * 2 - 1;
    57.              
    58.                     half2 vn;
    59.                     vn.x = dot(i.TtoV0, normal);
    60.                     vn.y = dot(i.TtoV1, normal);
    61.              
    62.                     float4 matcapLookup = tex2D(_MatCap, vn*0.5 + 0.5);
    63.              
    64.                     return texcol*_Color*matcapLookup*2;
    65.                 }
    66.             ENDCG
    67.         }
    68.         UsePass "Bumped Specular/PPL"
    69.     }
    70. }
    71.  

     
    Last edited: Sep 17, 2014
  6. Play_Edu

    Play_Edu

    Joined:
    Jun 10, 2012
    Posts:
    722
    Awesome look materials
     
  7. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    Hi Guys,

    I need your help. I am really starting to learn and I've encountered one problem.

    I generated a mesh via C# and I apply a Material.
    This material has a texture, and "from far" looks fine.
    Unfortunately when I zoom in the texture disappear, leaving just the shader.

    Any suggestion?

    thanks,

    Dom
     
  8. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Question: How do I get the Clipping Mask to work without having 1 row of pixels transparent?



    This approach works... BUT...
    it also clips off 1 pixel from the outputed texture:



    Any suggestions appreciated. ;)
    (previously asked in post 1774, but no reply)

    Thanks, Izzy.
     
  9. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    No, but you could have a fixed size "array" and pass in data as needed, so you'd always pass in 8 colors, for instance, but you keep all of them black, except the ones you want to pass in.

     
    RUBILYN likes this.
  10. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    need some good tutorials for making different shaders. Please developer spend some time on that too.
     
  11. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Your generous post gave me the missing piece to one of my shaders. Thank you!
    ComicStyle05.jpg ComicStyle04.jpg
     
  12. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    Hi!. i am trying to do a skybox shader. I have seen a lot of skybox shaders which works with cubemaps but when i try to do something similar in Shader Forge (for example a simple cubemap node attached to the diffuse) and i try to the material in the skybox component of the camera there is no way to make it work. I need to activate something especial to make it work?
     
  13. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,360
    That is a very interesting question, i would love to know both how to move multiple blades of grass in shader and make it react to the game in general ( i suppose first the blades need to be combined in a single mesh)

    Opens up a world of new possibilities
     
  14. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    hmm... NM. Got It! :)
     
  15. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Is the cubemap assigned in the material itself?
     
  16. Hesham

    Hesham

    Joined:
    May 29, 2008
    Posts:
    147
    A Quick question, can I share the generated shader with people that don't have Shader Forge?
     
  17. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,155
    Yep.
     
  18. layola

    layola

    Joined:
    Aug 6, 2013
    Posts:
    94
    don't know why my shader only work in shader forge preview,but not work on unity player with skin mesh animation
    sf_vertextest_9222014.png
     
  19. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    So, this is a general issue it seems. Please allow me to help you help me help you all :)

    Try to describe your problems as in-detail as possible.
    "It doesn't work" says nothing about what doesn't work, and when it doesn't work, and where it doesn't work.

    "My shader doesn't work on Android" could be anything. You covered the "where" but not what and when.
    Does any of your other shaders work on Android? What breaks in the shader; does it not compile at all, or is it black, or does your specific feature not work as intended?

    I have to be able to isolate the issue as much as possible using as little time as possible in order to help, so, for the benefit of everyone, be descriptive!
     
  20. layola

    layola

    Joined:
    Aug 6, 2013
    Posts:
    94
    ok,sorry for no detail in descriptive, I forget the step .
    I create another scene and test again ,and find that work now.
    and I found another issus that is you can't delete( uv coord) node use delete key in some times
     

    Attached Files:

  21. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    No problem - sorry if it felt aimed at you specifically; it's a common thing, many people make the same mistake :)
    The UV node thing is a known issue, there's not really any specific way around it at the moment.
     
  22. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    Here you can see what i have done. I do a simple shader with a cubemap node. Then i create a material (Spacebox) with my custom shader. I put the correct cubemap and the result is very strange.

     
  23. layola

    layola

    Joined:
    Aug 6, 2013
    Posts:
    94
    how to dynamic change uv node value ?
    20140923150443.jpg
     
  24. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Make a view vector node and plug it into the DIR input of the cubemap node

    Use a UV coord node and an add node, and add a two-component value to pan UVs, without the panner
     
  25. layola

    layola

    Joined:
    Aug 6, 2013
    Posts:
    94
    uv20140923200255.jpg
    you mean this? it's not what I expected ,
    any thing I missing?
     
  26. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
  27. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Hey guys, I'm wondering if anyone could give me a hand in figuring out how to set up a specific shader in SF. I'm still really new to shaders, but I have played around with SF quite a bit. I think I understand how most basic things work, I'm just having trouble deciphering how to recreate a specific shader in Shaderforge.

    This is what I'm after: [Image 1] [Image 2]

    I've taken a look at the unity-chan shaders and they look pretty close to what I want (or at least a good starting point..), and throwing them into a scene with a face I made has nice results, I would like to add on a few effects that I've already created in SF (glows, alpha-clip, stuff like that)

    These are the properties present on the unity-chan material: [link]

    Where would be a good place to start?
    How would you create a shader like in the examples above?
    All advice and help is greatly appreciated! :)

    One specific question I have currently as I try to figure this out is: Is it possible to have the outline colour set from the diffuse texture, rather than a solid colour?

    *goes back to messing around and failing in SF*

    Edit: After some while I've made some basic progress: Tinting shadow colours! [Node Graph]
     
    Last edited: Sep 24, 2014
  28. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
  29. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    Thanks a lot! Sometimes i miss the simple things.
     
  30. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    @Vladnes:
    That effect is probably done in multiple layers of meshes. One layer for distortion. One or two for coloring that cloud like nebulae. And maybe one more for the zigzaging energy beams that feed the portal.
     
  31. AGeorgy

    AGeorgy

    Joined:
    Sep 16, 2013
    Posts:
    42
    how to build it in SF?:

    Code (CSharp):
    1. Shader "Custom/Flare" {
    2.     Properties {
    3.         _MainTex ("Texture", 2D) = "black" {}
    4.         _Color ("Color", Color) = (1,1,1,1)
    5.     }
    6.  
    7.     SubShader {
    8.          Tags {
    9.           "Queue"="Transparent"
    10.           "IgnoreProjector"="True"
    11.           "RenderType"="Transparent"
    12.          }
    13.  
    14.      Cull off
    15.      Lighting Off
    16.      ZWrite off
    17.      ZTest Always
    18.      Blend One One
    19.      Fog { Mode Off }
    20.      Color (1,1,1,1)
    21.          Pass {
    22.           SetTexture [_MainTex] {
    23.                 constantColor [_Color]
    24.                 combine texture * primary, texture * constant
    25.           }
    26.          }
    27.     }
    28. }
     
    Last edited: Sep 25, 2014
  32. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Take a look at the Blending panel in the Shader Forge editor window. Then, go through the lines in that subshader and change whichever settings you need to. Blend One One means it's Additive. ;)
     
  33. bdiggidydog

    bdiggidydog

    Joined:
    Mar 18, 2014
    Posts:
    1
    Is there a way to set up a shader so that it can be used with the Unity Projector?
     
    IFL likes this.
  34. AGeorgy

    AGeorgy

    Joined:
    Sep 16, 2013
    Posts:
    42
    Thanks

    but:

    What's wrong?

     
    Last edited: Sep 25, 2014
  35. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    @AGeorgy:
    Not sure what you're expecting to see - or what you expect us to see in the upper screenshot.
    But the lower one looks like it does what is to be expected by an additive shader - it adds the objects color to whatever background color there is.
     
  36. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Try this:
    SF_AGeorgy_01.jpg
    If that doesn't look right, can you post a picture of what it should look like?

    [EDIT:] Ignore projectors should be checked. My bad.
     
    Last edited: Sep 25, 2014
  37. AGeorgy

    AGeorgy

    Joined:
    Sep 16, 2013
    Posts:
    42
    Thank you to all!
    In the ShaderForage - everything worked, and the Scene is not.
    Run the project again and everything works.
    It's like having a USB Flash. Connected - not working; flipped, connected - not working; flipped, connected - works. :)
     
  38. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    I'm not sure if this is a bug or something I'm just doing wrong (most likely!) but something isn't working quite as I'd expect.
    I'm working on a face which consists of two parts: The face, and duplicate geometry for eyes.
    I created the skin shader first (node graph) and applied it to the face. Looking good.

    I then duplicated this shader to make a shader for the eyes. This is how it looks without any changes to the shader.
    Now I open the duplicated shader in shaderforge and make
    some modifications (Remove normals and outline, cutting out the spec contrib, plugging in diffuse alpha into the alpha input)

    Now the graph looks something like this and my head looks like this. There is no shadow being cast from the object above on the eye on the right. (Should I be multiplying by the light atten. again somewhere else? I dunno..)

    Anyways, I undo all the changes I made so the node graph is exactly as it was before I made any changes and now there are NO shadows being cast on my face. I'd expect it to revert back to how it was before, as the node graphs are EXACTLY the same, but nope. Maybe the shader is being marked somehow and the change isn't being reverted on a recompile? I have no idea.

    Trying to figure out exactly what step is causing my problem, I duplicated the original shader again, and simply disconnected the spec contrib but didn't plug anything into the alpha input. It looks like this, good so far. So it seems the moment I plug anything into the alpha input I lose my shadows, and breaking the connection and recompiling doesn't bring them back. Any thoughts? I'm using version 0.36.

    EDIT: Plugging the alpha into the alpha clip input gives desirable results, except for the really sharp and pixel-y looking edges now. I guess I'd rather have shadows, but is this what's going on? The moment the shader is marked for "maybe everything partially transparent" it doesn't get any shadows on it? I guess that would make sense, maybe someone can clarify for me, I'm still a shader noob!

    On a different note, is it possible to have the outline colour be more than just a single colour? Something like using the diffuse colour for the outlines? Like so
     
    Last edited: Sep 26, 2014
  39. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Hey Ace. I have two questions.

    First - Have you found a way to get normals working on the terrain?

    Second - I am trying to make a shader with a sense of hemispherical ambient lighting. I have the colors multiplied by the ambient light and combined into the diffuse ambient light input. The only problem I am having is trying to figure a way to tell the shader that this light is shining directly down and this light is shining directly up. I am currently using a normal direction perturbed node and it looks decent. There are some strange colors coming out of it though.

    So long story short. How do I give exact up and down directions to Shader Forge?

    Thanks Ace
     
  40. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    If you lose shadows and you're not using alpha, check the Blending panel settings. Blendmode=off and Autosort=true.
    To color the outline, sample the color of a texture or create a procedural color based on position, distance, etc.
     
    Baldinoboy likes this.
  41. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Oh, thanks. Yeah this is being set to Alpha Blended when the alpha input has a connection, it's not being set back to None though once I break the connection and recompile.

    I guess I didn't even really think about just plugging in the diffuse rbg into the outline colour slot. Thanks!
     
  42. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I know this was directed @ Ace, and you said that you were using the normal, but did you multiply the color(s) by the clamped Y value (clamp0to1(Y) for above, clamp0to1(one_minus(Y)) for below) of the normal? If the object pitches or rolls, you'll want to transform that into world space as well. If it looks decent, I'm guessing you already have that though. Weird colors should only really happen if you combine the light colors with the rest in a weird way. Hope this helped - I'm not 100% sure I know what you're having to troubleshoot.
     
    Baldinoboy likes this.
  43. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    Thank you for the response.

    No I have not. I am not on my computer right now so can not try it out. Also do not remember the clamp not being able to clamp a certain axis(I have only used simple clamp). I am going to want to use it is world space. It does look decent but there are some angles where the ground light should not be showing. When I get back to my computer I will try it out. I may have some questions then.

    Thanks for your help.

    A little off topic but why when using the Physically Based shaders is the incoming light so dark. Have it to receive double light and am not using a strong specular texture. To make the model not look crazy dark I multiply the diffuse by 1.6 or even 2. That makes the model visible but also makes it look unlit. Can barely tell the difference between the sunlight and the ambient light. Is there a fix for this besides increasing the light strength. Ace mentioned there soon being the ability to control the actual ambient light. This would help with this situation too. Multiplying the AO texture by .5 and inputting that into the AO. Look forward to trying that out.
     
  44. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Success! (For the most part)
    Gif of my shader in action!

    Any tips or anything of how I can do things better?
    Is it bad to have multiple UV nodes that all are the same? Should I be reusing one?
    What about having so many inputs? Making shaders is starting to grow on me... at least when it works how you want it to ;)
    sf_eyes_9272014.png
     
  45. Deleted User

    Deleted User

    Guest

    Looks nice, will this work with Unity5?
     
  46. Maverick

    Maverick

    Joined:
    Dec 18, 2009
    Posts:
    240
    Just bought SF, great tool. :)

    But as new user of the tool I've noticed a small issue. The diffuse texture is darker in the shader made by SF comparing with default diffuse unity shader. Here is a screen:
    sf_q1.png
    The top one is the default diffuse shader.
    The second one is SF new default shader with just a diffuse texture.

    As you see the SF is darker. Could it be that default unity shader has a *2 multiplier in final color calculation (i.e. (atten * 2))? Am I doing something wrong?

    Thanks.
     
  47. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,634

    Yes four times, and as I said other people at my college see the same issue... I have a bought license were everyone else is using the schools. So same issue, the lag is gone now though since I stop auto updating, but still adds nodes and does not delete them.

    I stopped using shader forge until the next update. I went back to writing my own for now.
     
  48. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    If I remember right, and like you noticed with the atten*2, the default unity shaders double the incoming light. SF has a setting to automatically double it on the Lighting panel.

    I know of no issues with clamping a single axis either. I think I didn't properly convey what I was trying to say. I was very wrong about the one_minus and the transforming. Here's what I got to work:
    SF_Baldinoboy_01.jpg
     
    Baldinoboy likes this.
  49. Raikuns

    Raikuns

    Joined:
    Sep 28, 2014
    Posts:
    4
    hey Shaderforge community

    so i have a problem with making a ocean shader. i want to make an ocean in world space so i can just upscale the Plane

    This is my Node setup.
    shade.png shader_op.png

    so if some1 knows how to make this into World space and explain how. that would be great!

    Greetz Raikuns
     
  50. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    This worked great. Thank you very much.