Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. AlBrennan

    AlBrennan

    Joined:
    Nov 10, 2013
    Posts:
    2
    Hey Everyone!

    Can you share any advice on improving this foliage shader, or improving it's performance? I'm very new to Shader Forge, and was hoping you guys could help me out and share some collective wisdom :)

    The goal for this shader is;

    • To make a foliage shader for believable large-leaf foliage in a Unity environment where the non-foliage elements are baked in as photo textures.
    SF_MapleLeaf_FakeIBL_Shader.png SF_MapleLeaf_Transmission_Bottom.png Ferns.jpg mapleLeaves.jpg Screenshot (5321).png

    The shader was made for this fern model, but I also included the same shader with
    some maple leaf textures. The arbitrary values in the shader were made to tint
    parts of the fern specifically, however...

    • Because of the changing color of the leaves depending on the viewing angle, the leaves needed a shader that would heighten their specular 'sheen' at steeper viewing angles, to avoid baking the high specularity in, and having them look as if they're completely white, from a perpendicular viewing angle.I also wanted a shader that had slots for Alpha clipping AND a specular map, at the same time. It seemed like standard Unity shaders expect a specular map in the alpha of the diffuse texture file, and never have another slot for an alpha clipping texture, unless I'm wrong? I wanted the leaves to look sunlit in the light, and in the shadow have bluish reflection, as if from the ambient sky color. Also to have a brighter overall reflection at steeper viewing angles. I ended up plugging in a lot of arbitrary values to tint things enough to fit against the photo reference. How it's working right now...

    Leaf Tops:

    Diffuse:
    Diffuse takes the Color texture, multiplies it against a color (just to tint it a
    little - could just adjust the texture file itself). In order to fake some
    ambient occlusion, I baked some AO into the vertex colors as black. A lerp node
    gives a white color to the white vertices, and a bluish color to the darker
    vertices, then multiplies them against the texture file, so the 'AO' parts will
    show up as if in soft blue AO shadows...

    Specular:
    I wanted to be able to control the colors in the specular highlight (so, one
    color in the center of the highlight, another towards it's edge. Like a lighter
    center surrounded by a 'ring' of another color).

    Normal: Just a normal map.

    Specular Ambient Light:
    This uses the IBL setup from the Shader Forge example scene, but the IBL is
    masked out by a fresnel node, too... For it to look right though, it needed;

    The fresnel to 'spread' over the surface different amounts in light, and in
    shadow.

    The center / outer (depending on the fresnel) tinge of the IBL to be different,
    in light, and in shadow.

    The Alpha clip just comes from the alpha channel of the diffuse texture.

    Leaf Bottoms:
    It's a separate texture / material / shader / object, since the 'frontface culling' option,
    needed to get the shadows to show up on the bottom, will affect the whole mesh.
    (So you can't have one mesh, with two sets of faces sharing the same space, with
    opposite-facing normals and separate materials. They need to be two separate
    meshes with identical geo, but with opposite-facing normals, I think.)

    This has some arbitrary values to tint the light / shadow areas, as well.
    I understand this is alot to read through, but if anyone is willing, it'd be great
    to know if there are ways I can improve the shader to be simpler and faster. I'm
    worried about how this might perform, with many foliage objects on screen. I'm
    very new to shader forge, so any advice from you experienced guys is greatly
    appreciated! :)

    I haven't used the new physically based shaders in Unity 5, would those be helpful?

    I can't thank you guys enough, for any advice! (hopefully this wasn't TLDR)
     
  2. dd3igames

    dd3igames

    Joined:
    Mar 11, 2015
    Posts:
    2
    With the new lighting model (Unity5) is emissive still broken ? I set this to 20 and I can't get anything out of it unlike when I use the standard material, and set it to 2-5 it's basically a neon sign.
     
  3. FreakForFreedom

    FreakForFreedom

    Joined:
    Jan 22, 2013
    Posts:
    156
    The change to have the PBL Fresnel/Visibility terms always on seem to cause this problem for me. Tested it on a previous version of SF (had it on an other machine) and the fresnel of the models is quite different and I don't have those flickering pixels. Is there a way to turn the fresnel/visibility term off manually?
     
  4. DeveloperRLA

    DeveloperRLA

    Joined:
    Jun 17, 2013
    Posts:
    53
    Hey guys. Can anyone give some suggestions on creating a car paint shader with shader forge? I can't seem to get anything that looks correct. Thanks a lot!
     
  5. Deleted User

    Deleted User

    Guest

    @Acegikmo

    In 1.11 if i remove autosort, in the console will always appear a message for enable opacity clip, can also fix this in 1.12? Thanks
     
  6. Becoming

    Becoming

    Joined:
    May 19, 2013
    Posts:
    781
    If you want better help try to layout your shaders nicely using the relay nodes... its quite messy and following the lines to see whats going on is tedious. One thing is quite obvious though. You care a lot about spec color and little about gloss. I'd suggest to do the opposite. It looks like you aim for realism so i suggest you to dive into PBR and learn it. I'd say you can have a more realistic look with fewer nodes. Although please don't get my feedback wrong, i think your results are very good, i just think you'd have problems with different lighting conditions.
     
    AlBrennan likes this.
  7. Michael-Thomas

    Michael-Thomas

    Joined:
    Jul 8, 2014
    Posts:
    20
    I have a shader which was working in Unity 4.6/SF 1.06, which is setup to be double-sided.

    It generates, in the Shadow Caster (and Shadow Collector though I understand these are ignored in U5) passes the following fragment shader function:

    Code (csharp):
    1. float4 frag(VertexOutput i) : COLOR {
    2. /////// Vectors:
    3.   float3 normalDirection = i.normalDir;
    4.  
    5.   float nSign = sign( dot( viewDirection, i.normalDir ) ); // Reverse normal if this is a backface
    6.   i.normalDir *= nSign;
    7.   normalDirection *= nSign;
    8.  
    9.   SHADOW_CASTER_FRAGMENT(i)
    10.   }
    Since viewDirection is not defined in the function (it is defined only in the forward pass), this causes an error.

    For now, I'm just manually removing the offending code in the shadow caster after compiling from SF. Is this a known bug in SF 1.11? Or am I missing something here?

    Thanks in advance!
     
  8. Drewson

    Drewson

    Joined:
    Apr 19, 2009
    Posts:
    168
  9. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Perhaps this is a silly question, but something isn't clicking in my head. I'm still learning about all this PBL Unity 5 magic, but maybe someone can shed some light.

    So toggling the PBL box in the Lighting tab LightMode turns it on, and we get a bunch of new slots on the Main node - awesome and straightforward.

    However, I'm used to running Unlit/custom and creating my own Blinn-phong (as per Acegikmo's youtube tutorials) - is there an equivalent to this custom blin-phong but for the PBL setup. So I can drop specific (custom nodes) anywhere in the process. Or is that simply not how PBL works?

    For example I'm trying to take the normal standard shader and make it cell shaded (posterized shadows) - I can't wrap my head around how to get this done with the PBL inputs on the main node alone - so that makes me think I need a custom setup that mimics whatever is going on under the hood.

    Can anyone offer some insight or a nudge in the right direction? :)
     
  10. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Could you show me the node tree to trigger this error?

    Edit: Nevermind, fixed this now :)

    PBL is a bit complicated, especially if you want to get all the components (Lightmaps, probes, etc) in there. You can of course set up the nodes to (almost, minus reflection probes and lightmaps) replicate the entire PBL pipeline, but, it's quite a lot of code :)
    Unity's shaders are open-source, you could simply open them and have a look at how they do it!
     
    Last edited: Mar 19, 2015
    DMeville likes this.
  11. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    Thanks a lot! I will take a look to this.
     
  12. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Alright, thank you very much!
     
  13. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi Acegikmo,

    Any way to correctly use unity_LODFade.x in Shader Forge to use smooth LOD fading?
    Like in SpeedTree Shader, that stores two positions in one vertex: one is the model-space vertex position and the other is the position of the same vertex in the next LOD. It uses unity_LODFade.x to lerp between the two positions to achieve smooth transition effect.

    Thanks in advance.
     
  14. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    I'm guessing the speedtree shader is highly specialized, since it's made to work on procedural meshes, rather than any mesh you want. I don't think it's that simple I'm afraid!
     
  15. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Shader Forge 1.12 is now released:
    • Fixed a bug where tessellation couldn't use baked lighting
    • Fixed a bug where double-sided shaders with alpha clipping sometimes broke
    • Fixed a bug where unlit shaders didn't compile when diffuse and baked light was previously on
    • Fixed a bug where you got warnings about alpha blending when auto-sort was off
    • Removed the (now redundant as of Unity 5) shadow collector pass
     
    elbows and Deleted User like this.
  16. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    But how i can use the unity_LODFade.x from LOD group to lerp (for example) the alpha?
     
  17. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    I'm curious what happens when you plug something into Diffuse Ambient Light while Lightmaps are checked. It looks like the input gets added to Unity 5 ambient? Is that correct?
     

    Attached Files:

  18. Ga2Z

    Ga2Z

    Joined:
    Feb 16, 2012
    Posts:
    68
  19. LeagueOfMonkeys

    LeagueOfMonkeys

    Joined:
    Aug 13, 2012
    Posts:
    33
    I am getting some constant crashing with V1.11 - download / import / open shader forge window - start making changes to a shader..... few seconds later crash. Its very consistant, other devs in our office are having same crashing issues. If I had to guess without further testing it might be enlighten and the continuous baking being on. Ill try and do some testing today. Any suggestions would be appreciated
     
  20. LeagueOfMonkeys

    LeagueOfMonkeys

    Joined:
    Aug 13, 2012
    Posts:
    33
    crash crash crash........................tried 1.12..................crash crash crash arrrrrrrrgh
     
  21. Yamo

    Yamo

    Joined:
    Nov 18, 2012
    Posts:
    18
    Is there a way to get a shaderforge shader to work like the new unity5 "fadeout" setting for alpha? The regular alpha clip is a bit harsh, especially at a distance.

    Unity 5 standard(specular) with fadeout setting



    Alpha clip with Shader Forge


    Is there anything I can do?
     
  22. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Sounds like a broken installation, try this first: http://acegikmo.com/shaderforge/faq/?Q=erroronnewversion#erroronnewversion

    If that doesn't work, please give me a more detailed crash report.
    Did Unity or SF crash?
    Are you getting any errors in the console?
    Do all actions cause a crash, or only some?
    Which version of Unity are you running?

    Connect Opacity instead of Opacity Clip
     
  23. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It should
     
  24. Yamo

    Yamo

    Joined:
    Nov 18, 2012
    Posts:
    18
    Oh I see, I guess my issue is that I'm using deferred rendering as opacity is unavailable in that mode? It works great in forward rendering
     
  25. J566

    J566

    Joined:
    Nov 15, 2013
    Posts:
    2
    Any idea when the emissive property will function like emissive in the standard shader, contributing to GI.
     
  26. WHKS

    WHKS

    Joined:
    Dec 13, 2011
    Posts:
    61
    when i download the update i still get 1.06 even when i delete an re down load im on unity 4.6.3 how can i get the lastest update to 1.12. let me know thanks
     
  27. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    1.12 is for Unity 5 only.
     
    Acegikmo likes this.
  28. AlBrennan

    AlBrennan

    Joined:
    Nov 10, 2013
    Posts:
    2
    Thanks very much, Becoming - I really appreciate the advice. I'll dive into the PBR, focus on gloss more, and clean this network up - if I get something simpler and worthwhile, I'll post more!
     
  29. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It already does
     
  30. Deleted User

    Deleted User

    Guest

    @Acegikmo

    I have found a bug on transmission with pbl



    And same problem without pbl

     
    Last edited by a moderator: Mar 21, 2015
  31. JokieWa

    JokieWa

    Joined:
    Mar 22, 2015
    Posts:
    1
    Hi,
    I need to use the light attenuation for the opacity clip, but it bugs out:
    2015-03-21_2042.png
    It's not declared in the right places in the code:
    Code (CSharp):
    1. /////// Vectors:
    2.                 clip( BinaryDither2x2(attenuation - 1.5, sceneUVs) );
    3. ////// Lighting:
    4.                 float attenuation = LIGHT_ATTENUATION(i);
    5.                 float3 attenColor = attenuation * _LightColor0.xyz;
    6.                 float3 finalColor = 0;
    7.                 return fixed4(finalColor,1);
    It's also used undeclared in the third, "ShadowCaster" part, but if I try to get LIGHT_ATTENUATION(i) in that one, it is unrecognised.

    EDIT:
    I got another one. I tried to do my own thing instead, but opacity clip doesn't like Light Direction either:
    2015-03-21_2137.png
    Again it's a wrong order in the code:

    Code (CSharp):
    1.  
    2. /////// Vectors:
    3.   clip( BinaryDither2x2(lightDirection.r - 1.5, sceneUVs) );
    4.   float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
    5. ////// Lighting:
    6.   float3 finalColor = 0;
    7.   return fixed4(finalColor * 1,0);
    8.  
     
    Last edited: Mar 22, 2015
  32. pjenness

    pjenness

    Joined:
    Mar 3, 2013
    Posts:
    52
    Hi have done a number of searches, but hard to find exact what looking for..so....

    Is there an example of a shader that takes into account the player camera position.
    Which then feeds somehow into a tesselate and displace node system

    The goal being as camera crosses a threshold the displacement kicks in

    Cheers!

    -P
     
  33. FreakForFreedom

    FreakForFreedom

    Joined:
    Jan 22, 2013
    Posts:
    156
    That's quite simple actually since there already is a tesselation shader in the shader forge package... simply add these few nodes to the Mult-Node for the displacement input :)
    distant-based tesselation.png
     
    Acegikmo likes this.
  34. Deleted User

    Deleted User

    Guest

    @Acegikmo

    Mhh...seems there is another bug on tessellation

     
  35. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,145
    I was having some issues with my old triplanar shader since it was kinda awkward for static terrain, due to Vpaint's new lagginess, so I rewrote it so it's entirely possible to do from Blender:



    What I do is make it so that the mask is based on a texture rather than vertex colours (fine for terrain) that I can paint from Blender, since the only easy way to use Alpha in that is to use textures. HOWEVER, I also made sure to make it so that the alpha value is calculated last so that you always draw over other colours.



    The ring around the middle of the sphere is the alpha value of the texture. In Blender, you accomplish this by using a brush with Remove Alpha in the texture painting tools. That's the reason for the Remap node attached to the alpha. It's all pretty bare bones otherwise, but it allows my entire workflow to take place in blender with quick and easy updates to Unity AND it allows me to use terrain that isn't set by a height map, which was hugely important.

    Here's the full Shader Forge code in case you don't want to try and rebuild my mess of nodes by hand and this may be of use to you.

    Code (CSharp):
    1. // Shader created with Shader Forge v1.12
    2. // Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
    3. // Note: Manually altering this data may prevent you from opening it in Shader Forge
    4. /*SF_DATA;ver:1.12;sub:START;pass:START;ps:flbk:,lico:1,lgpr:1,nrmq:1,nrsp:0,limd:1,spmd:1,grmd:0,uamb:True,mssp:True,bkdf:False,rprd:False,enco:True,rmgx:True,rpth:0,hqsc:True,hqlp:False,tesm:0,blpr:0,bsrc:0,bdst:0,culm:0,dpts:2,wrdp:True,dith:0,ufog:True,aust:True,igpj:False,qofs:0,qpre:1,rntp:1,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,ofsf:0,ofsu:0,f2p0:False;n:type:ShaderForge.SFN_Final,id:1,x:34974,y:32712,varname:node_1,prsc:2|diff-5095-OUT;n:type:ShaderForge.SFN_ValueProperty,id:4845,x:31424,y:32936,ptovrint:False,ptlb:Scale,ptin:_Scale,varname:node_4845,prsc:2,glob:False,v1:1;n:type:ShaderForge.SFN_Max,id:9163,x:31609,y:32936,varname:node_9163,prsc:2|A-4845-OUT,B-8778-OUT;n:type:ShaderForge.SFN_Vector1,id:8778,x:31424,y:32994,varname:node_8778,prsc:2,v1:0.001;n:type:ShaderForge.SFN_Append,id:4148,x:31808,y:32936,varname:node_4148,prsc:2|A-9163-OUT,B-9163-OUT;n:type:ShaderForge.SFN_FragmentPosition,id:3965,x:31808,y:32780,varname:node_3965,prsc:2;n:type:ShaderForge.SFN_Append,id:4431,x:32103,y:32694,cmnt:Top,varname:node_4431,prsc:2|A-3965-X,B-3965-Z;n:type:ShaderForge.SFN_Append,id:1609,x:32105,y:32878,cmnt:Front,varname:node_1609,prsc:2|A-3965-Y,B-3965-Z;n:type:ShaderForge.SFN_Append,id:7365,x:32105,y:33041,cmnt:Side,varname:node_7365,prsc:2|A-3965-X,B-3965-Y;n:type:ShaderForge.SFN_Divide,id:5166,x:32318,y:32694,varname:node_5166,prsc:2|A-4431-OUT,B-4148-OUT;n:type:ShaderForge.SFN_Divide,id:7058,x:32318,y:32878,varname:node_7058,prsc:2|A-1609-OUT,B-4148-OUT;n:type:ShaderForge.SFN_Divide,id:3094,x:32318,y:33041,varname:node_3094,prsc:2|A-7365-OUT,B-4148-OUT;n:type:ShaderForge.SFN_Tex2dAsset,id:6800,x:32631,y:32403,ptovrint:False,ptlb:Red Channel,ptin:_RedChannel,varname:node_6800,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2dAsset,id:3461,x:32634,y:32902,ptovrint:False,ptlb:Green Channel,ptin:_GreenChannel,varname:node_3461,tex:82db80af78ef9f849b63a113baa3c9b8,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2dAsset,id:1836,x:32654,y:33415,ptovrint:False,ptlb:Blue Channel,ptin:_BlueChannel,varname:node_1836,tex:e1f7fdbcd92f264428d3114db0bf0e3e,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2dAsset,id:5278,x:32658,y:33905,ptovrint:False,ptlb:Alpha Channel,ptin:_AlphaChannel,varname:node_5278,tex:8f11bd0f823dc9545902020fa2334f71,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2d,id:208,x:32908,y:32218,varname:node_208,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-5166-OUT,TEX-6800-TEX;n:type:ShaderForge.SFN_Tex2d,id:4023,x:32908,y:32501,varname:_node_5543_copy,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-3094-OUT,TEX-6800-TEX;n:type:ShaderForge.SFN_Tex2d,id:8813,x:32908,y:32681,varname:node_8813,prsc:2,tex:82db80af78ef9f849b63a113baa3c9b8,ntxv:0,isnm:False|UVIN-5166-OUT,TEX-3461-TEX;n:type:ShaderForge.SFN_Tex2d,id:9271,x:32908,y:32862,varname:node_9271,prsc:2,tex:82db80af78ef9f849b63a113baa3c9b8,ntxv:0,isnm:False|UVIN-7058-OUT,TEX-3461-TEX;n:type:ShaderForge.SFN_Tex2d,id:9736,x:32908,y:33049,varname:node_9736,prsc:2,tex:82db80af78ef9f849b63a113baa3c9b8,ntxv:0,isnm:False|UVIN-3094-OUT,TEX-3461-TEX;n:type:ShaderForge.SFN_Tex2d,id:545,x:32908,y:33215,varname:node_545,prsc:2,tex:e1f7fdbcd92f264428d3114db0bf0e3e,ntxv:0,isnm:False|UVIN-5166-OUT,TEX-1836-TEX;n:type:ShaderForge.SFN_Tex2d,id:8606,x:32908,y:33376,varname:_node_545_copy,prsc:2,tex:e1f7fdbcd92f264428d3114db0bf0e3e,ntxv:0,isnm:False|UVIN-7058-OUT,TEX-1836-TEX;n:type:ShaderForge.SFN_Tex2d,id:1604,x:32908,y:33534,varname:_node_545_copy_copy,prsc:2,tex:e1f7fdbcd92f264428d3114db0bf0e3e,ntxv:0,isnm:False|UVIN-3094-OUT,TEX-1836-TEX;n:type:ShaderForge.SFN_Tex2d,id:263,x:32908,y:33862,varname:_node_2859_copy,prsc:2,tex:8f11bd0f823dc9545902020fa2334f71,ntxv:0,isnm:False|UVIN-7058-OUT,TEX-5278-TEX;n:type:ShaderForge.SFN_Tex2d,id:9446,x:32908,y:34038,varname:_node_2859_copy_copy,prsc:2,tex:8f11bd0f823dc9545902020fa2334f71,ntxv:0,isnm:False|UVIN-3094-OUT,TEX-5278-TEX;n:type:ShaderForge.SFN_Lerp,id:5234,x:33401,y:32229,varname:node_5234,prsc:2|A-208-RGB,B-489-RGB,T-777-R;n:type:ShaderForge.SFN_Lerp,id:8826,x:33581,y:32710,varname:node_8826,prsc:2|A-5234-OUT,B-4023-RGB,T-777-G;n:type:ShaderForge.SFN_NormalVector,id:2439,x:32498,y:32039,prsc:2,pt:False;n:type:ShaderForge.SFN_Abs,id:906,x:32704,y:32039,varname:node_906,prsc:2|IN-2439-OUT;n:type:ShaderForge.SFN_ComponentMask,id:777,x:32908,y:32039,varname:node_777,prsc:2,cc1:0,cc2:2,cc3:-1,cc4:-1|IN-906-OUT;n:type:ShaderForge.SFN_Lerp,id:7920,x:33390,y:32872,varname:node_7920,prsc:2|A-8813-RGB,B-9271-RGB,T-777-R;n:type:ShaderForge.SFN_Lerp,id:6591,x:33581,y:32930,varname:node_6591,prsc:2|A-7920-OUT,B-9736-RGB,T-777-G;n:type:ShaderForge.SFN_Lerp,id:340,x:33381,y:33345,varname:node_340,prsc:2|A-545-RGB,B-8606-RGB,T-777-R;n:type:ShaderForge.SFN_Lerp,id:8714,x:33581,y:33164,varname:node_8714,prsc:2|A-340-OUT,B-1604-RGB,T-777-G;n:type:ShaderForge.SFN_Lerp,id:785,x:33395,y:33867,varname:node_785,prsc:2|A-85-RGB,B-263-RGB,T-777-R;n:type:ShaderForge.SFN_Lerp,id:6757,x:33592,y:33422,varname:node_6757,prsc:2|A-785-OUT,B-9446-RGB,T-777-G;n:type:ShaderForge.SFN_ChannelBlend,id:6736,x:34145,y:32962,varname:node_6736,prsc:2,chbt:0|M-4618-RGB,R-8826-OUT,G-6591-OUT,B-8714-OUT;n:type:ShaderForge.SFN_Tex2d,id:85,x:32908,y:33711,varname:node_85,prsc:2,tex:8f11bd0f823dc9545902020fa2334f71,ntxv:0,isnm:False|UVIN-5166-OUT,TEX-5278-TEX;n:type:ShaderForge.SFN_Tex2d,id:489,x:32908,y:32362,varname:node_489,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-7058-OUT,TEX-6800-TEX;n:type:ShaderForge.SFN_Tex2d,id:4618,x:33813,y:33219,ptovrint:False,ptlb:Splatmap,ptin:_Splatmap,varname:node_4618,prsc:2,ntxv:2,isnm:False;n:type:ShaderForge.SFN_Lerp,id:5095,x:34425,y:33114,varname:node_5095,prsc:2|A-6736-OUT,B-6757-OUT,T-1098-OUT;n:type:ShaderForge.SFN_RemapRange,id:1098,x:34115,y:33460,varname:node_1098,prsc:2,frmn:0,frmx:1,tomn:1,tomx:0|IN-4618-A;proporder:4845-6800-3461-1836-5278-4618;pass:END;sub:END;*/
    5.  
    6. Shader "Custom/Terrain Triplanar" {
    7.     Properties {
    8.         _Scale ("Scale", Float ) = 1
    9.         _RedChannel ("Red Channel", 2D) = "white" {}
    10.         _GreenChannel ("Green Channel", 2D) = "white" {}
    11.         _BlueChannel ("Blue Channel", 2D) = "white" {}
    12.         _AlphaChannel ("Alpha Channel", 2D) = "white" {}
    13.         _Splatmap ("Splatmap", 2D) = "black" {}
    14.     }
    15.     SubShader {
    16.         Tags {
    17.             "RenderType"="Opaque"
    18.         }
    19.         LOD 200
    20.         Pass {
    21.             Name "FORWARD"
    22.             Tags {
    23.                 "LightMode"="ForwardBase"
    24.             }
    25.            
    26.            
    27.             CGPROGRAM
    28.             #pragma vertex vert
    29.             #pragma fragment frag
    30.             #define UNITY_PASS_FORWARDBASE
    31.             #include "UnityCG.cginc"
    32.             #include "AutoLight.cginc"
    33.             #pragma multi_compile_fwdbase_fullshadows
    34.             #pragma multi_compile_fog
    35.             #pragma exclude_renderers xbox360 ps3
    36.             #pragma target 3.0
    37.             uniform float4 _LightColor0;
    38.             uniform float _Scale;
    39.             uniform sampler2D _RedChannel; uniform float4 _RedChannel_ST;
    40.             uniform sampler2D _GreenChannel; uniform float4 _GreenChannel_ST;
    41.             uniform sampler2D _BlueChannel; uniform float4 _BlueChannel_ST;
    42.             uniform sampler2D _AlphaChannel; uniform float4 _AlphaChannel_ST;
    43.             uniform sampler2D _Splatmap; uniform float4 _Splatmap_ST;
    44.             struct VertexInput {
    45.                 float4 vertex : POSITION;
    46.                 float3 normal : NORMAL;
    47.                 float2 texcoord0 : TEXCOORD0;
    48.             };
    49.             struct VertexOutput {
    50.                 float4 pos : SV_POSITION;
    51.                 float2 uv0 : TEXCOORD0;
    52.                 float4 posWorld : TEXCOORD1;
    53.                 float3 normalDir : TEXCOORD2;
    54.                 LIGHTING_COORDS(3,4)
    55.                 UNITY_FOG_COORDS(5)
    56.             };
    57.             VertexOutput vert (VertexInput v) {
    58.                 VertexOutput o = (VertexOutput)0;
    59.                 o.uv0 = v.texcoord0;
    60.                 o.normalDir = UnityObjectToWorldNormal(v.normal);
    61.                 o.posWorld = mul(_Object2World, v.vertex);
    62.                 float3 lightColor = _LightColor0.rgb;
    63.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    64.                 UNITY_TRANSFER_FOG(o,o.pos);
    65.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    66.                 return o;
    67.             }
    68.             float4 frag(VertexOutput i) : COLOR {
    69.                 i.normalDir = normalize(i.normalDir);
    70. /////// Vectors:
    71.                 float3 normalDirection = i.normalDir;
    72.                 float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
    73.                 float3 lightColor = _LightColor0.rgb;
    74. ////// Lighting:
    75.                 float attenuation = LIGHT_ATTENUATION(i);
    76.                 float3 attenColor = attenuation * _LightColor0.xyz;
    77.                 float Pi = 3.141592654;
    78.                 float InvPi = 0.31830988618;
    79. /////// Diffuse:
    80.                 float NdotL = max(0.0,dot( normalDirection, lightDirection ));
    81.                 float3 directDiffuse = max( 0.0, NdotL) * attenColor;
    82.                 float3 indirectDiffuse = float3(0,0,0);
    83.                 indirectDiffuse += UNITY_LIGHTMODEL_AMBIENT.rgb; // Ambient Light
    84.                 float4 _Splatmap_var = tex2D(_Splatmap,TRANSFORM_TEX(i.uv0, _Splatmap));
    85.                 float node_9163 = max(_Scale,0.001);
    86.                 float2 node_4148 = float2(node_9163,node_9163);
    87.                 float2 node_5166 = (float2(i.posWorld.r,i.posWorld.b)/node_4148);
    88.                 float4 node_208 = tex2D(_RedChannel,TRANSFORM_TEX(node_5166, _RedChannel));
    89.                 float2 node_7058 = (float2(i.posWorld.g,i.posWorld.b)/node_4148);
    90.                 float4 node_489 = tex2D(_RedChannel,TRANSFORM_TEX(node_7058, _RedChannel));
    91.                 float2 node_777 = abs(i.normalDir).rb;
    92.                 float2 node_3094 = (float2(i.posWorld.r,i.posWorld.g)/node_4148);
    93.                 float4 _node_5543_copy = tex2D(_RedChannel,TRANSFORM_TEX(node_3094, _RedChannel));
    94.                 float4 node_8813 = tex2D(_GreenChannel,TRANSFORM_TEX(node_5166, _GreenChannel));
    95.                 float4 node_9271 = tex2D(_GreenChannel,TRANSFORM_TEX(node_7058, _GreenChannel));
    96.                 float4 node_9736 = tex2D(_GreenChannel,TRANSFORM_TEX(node_3094, _GreenChannel));
    97.                 float4 node_545 = tex2D(_BlueChannel,TRANSFORM_TEX(node_5166, _BlueChannel));
    98.                 float4 _node_545_copy = tex2D(_BlueChannel,TRANSFORM_TEX(node_7058, _BlueChannel));
    99.                 float4 _node_545_copy_copy = tex2D(_BlueChannel,TRANSFORM_TEX(node_3094, _BlueChannel));
    100.                 float4 node_85 = tex2D(_AlphaChannel,TRANSFORM_TEX(node_5166, _AlphaChannel));
    101.                 float4 _node_2859_copy = tex2D(_AlphaChannel,TRANSFORM_TEX(node_7058, _AlphaChannel));
    102.                 float4 _node_2859_copy_copy = tex2D(_AlphaChannel,TRANSFORM_TEX(node_3094, _AlphaChannel));
    103.                 float3 diffuseColor = lerp((_Splatmap_var.rgb.r*lerp(lerp(node_208.rgb,node_489.rgb,node_777.r),_node_5543_copy.rgb,node_777.g) + _Splatmap_var.rgb.g*lerp(lerp(node_8813.rgb,node_9271.rgb,node_777.r),node_9736.rgb,node_777.g) + _Splatmap_var.rgb.b*lerp(lerp(node_545.rgb,_node_545_copy.rgb,node_777.r),_node_545_copy_copy.rgb,node_777.g)),lerp(lerp(node_85.rgb,_node_2859_copy.rgb,node_777.r),_node_2859_copy_copy.rgb,node_777.g),(_Splatmap_var.a*-1.0+1.0));
    104.                 float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
    105. /// Final Color:
    106.                 float3 finalColor = diffuse;
    107.                 fixed4 finalRGBA = fixed4(finalColor,1);
    108.                 UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
    109.                 return finalRGBA;
    110.             }
    111.             ENDCG
    112.         }
    113.         Pass {
    114.             Name "FORWARD_DELTA"
    115.             Tags {
    116.                 "LightMode"="ForwardAdd"
    117.             }
    118.             Blend One One
    119.            
    120.            
    121.             CGPROGRAM
    122.             #pragma vertex vert
    123.             #pragma fragment frag
    124.             #define UNITY_PASS_FORWARDADD
    125.             #include "UnityCG.cginc"
    126.             #include "AutoLight.cginc"
    127.             #pragma multi_compile_fwdadd_fullshadows
    128.             #pragma multi_compile_fog
    129.             #pragma exclude_renderers xbox360 ps3
    130.             #pragma target 3.0
    131.             uniform float4 _LightColor0;
    132.             uniform float _Scale;
    133.             uniform sampler2D _RedChannel; uniform float4 _RedChannel_ST;
    134.             uniform sampler2D _GreenChannel; uniform float4 _GreenChannel_ST;
    135.             uniform sampler2D _BlueChannel; uniform float4 _BlueChannel_ST;
    136.             uniform sampler2D _AlphaChannel; uniform float4 _AlphaChannel_ST;
    137.             uniform sampler2D _Splatmap; uniform float4 _Splatmap_ST;
    138.             struct VertexInput {
    139.                 float4 vertex : POSITION;
    140.                 float3 normal : NORMAL;
    141.                 float2 texcoord0 : TEXCOORD0;
    142.             };
    143.             struct VertexOutput {
    144.                 float4 pos : SV_POSITION;
    145.                 float2 uv0 : TEXCOORD0;
    146.                 float4 posWorld : TEXCOORD1;
    147.                 float3 normalDir : TEXCOORD2;
    148.                 LIGHTING_COORDS(3,4)
    149.             };
    150.             VertexOutput vert (VertexInput v) {
    151.                 VertexOutput o = (VertexOutput)0;
    152.                 o.uv0 = v.texcoord0;
    153.                 o.normalDir = UnityObjectToWorldNormal(v.normal);
    154.                 o.posWorld = mul(_Object2World, v.vertex);
    155.                 float3 lightColor = _LightColor0.rgb;
    156.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    157.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    158.                 return o;
    159.             }
    160.             float4 frag(VertexOutput i) : COLOR {
    161.                 i.normalDir = normalize(i.normalDir);
    162. /////// Vectors:
    163.                 float3 normalDirection = i.normalDir;
    164.                 float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
    165.                 float3 lightColor = _LightColor0.rgb;
    166. ////// Lighting:
    167.                 float attenuation = LIGHT_ATTENUATION(i);
    168.                 float3 attenColor = attenuation * _LightColor0.xyz;
    169.                 float Pi = 3.141592654;
    170.                 float InvPi = 0.31830988618;
    171. /////// Diffuse:
    172.                 float NdotL = max(0.0,dot( normalDirection, lightDirection ));
    173.                 float3 directDiffuse = max( 0.0, NdotL) * attenColor;
    174.                 float4 _Splatmap_var = tex2D(_Splatmap,TRANSFORM_TEX(i.uv0, _Splatmap));
    175.                 float node_9163 = max(_Scale,0.001);
    176.                 float2 node_4148 = float2(node_9163,node_9163);
    177.                 float2 node_5166 = (float2(i.posWorld.r,i.posWorld.b)/node_4148);
    178.                 float4 node_208 = tex2D(_RedChannel,TRANSFORM_TEX(node_5166, _RedChannel));
    179.                 float2 node_7058 = (float2(i.posWorld.g,i.posWorld.b)/node_4148);
    180.                 float4 node_489 = tex2D(_RedChannel,TRANSFORM_TEX(node_7058, _RedChannel));
    181.                 float2 node_777 = abs(i.normalDir).rb;
    182.                 float2 node_3094 = (float2(i.posWorld.r,i.posWorld.g)/node_4148);
    183.                 float4 _node_5543_copy = tex2D(_RedChannel,TRANSFORM_TEX(node_3094, _RedChannel));
    184.                 float4 node_8813 = tex2D(_GreenChannel,TRANSFORM_TEX(node_5166, _GreenChannel));
    185.                 float4 node_9271 = tex2D(_GreenChannel,TRANSFORM_TEX(node_7058, _GreenChannel));
    186.                 float4 node_9736 = tex2D(_GreenChannel,TRANSFORM_TEX(node_3094, _GreenChannel));
    187.                 float4 node_545 = tex2D(_BlueChannel,TRANSFORM_TEX(node_5166, _BlueChannel));
    188.                 float4 _node_545_copy = tex2D(_BlueChannel,TRANSFORM_TEX(node_7058, _BlueChannel));
    189.                 float4 _node_545_copy_copy = tex2D(_BlueChannel,TRANSFORM_TEX(node_3094, _BlueChannel));
    190.                 float4 node_85 = tex2D(_AlphaChannel,TRANSFORM_TEX(node_5166, _AlphaChannel));
    191.                 float4 _node_2859_copy = tex2D(_AlphaChannel,TRANSFORM_TEX(node_7058, _AlphaChannel));
    192.                 float4 _node_2859_copy_copy = tex2D(_AlphaChannel,TRANSFORM_TEX(node_3094, _AlphaChannel));
    193.                 float3 diffuseColor = lerp((_Splatmap_var.rgb.r*lerp(lerp(node_208.rgb,node_489.rgb,node_777.r),_node_5543_copy.rgb,node_777.g) + _Splatmap_var.rgb.g*lerp(lerp(node_8813.rgb,node_9271.rgb,node_777.r),node_9736.rgb,node_777.g) + _Splatmap_var.rgb.b*lerp(lerp(node_545.rgb,_node_545_copy.rgb,node_777.r),_node_545_copy_copy.rgb,node_777.g)),lerp(lerp(node_85.rgb,_node_2859_copy.rgb,node_777.r),_node_2859_copy_copy.rgb,node_777.g),(_Splatmap_var.a*-1.0+1.0));
    194.                 float3 diffuse = directDiffuse * diffuseColor;
    195. /// Final Color:
    196.                 float3 finalColor = diffuse;
    197.                 return fixed4(finalColor * 1,0);
    198.             }
    199.             ENDCG
    200.         }
    201.     }
    202.     FallBack "Diffuse"
    203.     CustomEditor "ShaderForgeMaterialInspector"
    204. }
    205.  
     
    Ga2Z and Acegikmo like this.
  36. Deleted User

    Deleted User

    Guest

    @Acegikmo

    If i try to convert shallow sea shader to 1.12 version will appear a error in console

     
  37. Andrew_atl

    Andrew_atl

    Joined:
    Sep 21, 2010
    Posts:
    103

    Hey, I recently bought Shader Forge and was looking at earlier posts and was wondering what happened to the instruction counter below the 3D preview? Is it some place else or is there another way to view the stats? thanks.
     
  38. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    @Acegikmo I just wanted to say that, after using SF 1.11+ a ton in the past few days, I think you've done an amazing job with the Unity 5 implementation. I'm able to be selective about which native systems my shaders employ, and its made my transition to U5 a dream.
     
  39. Steven

    Steven

    Joined:
    Dec 23, 2009
    Posts:
    43
    https://www.outube.com/watch?v=OeEYEUCa4tI&list=WL&t=1063

    This little video that Unity put out last year is really the only information I can find about PBR texture maps that isn't a physics paper. But its proposed method doesn't line up with Unitys Standard shader, and I can't figure out how to do it in SF either. They have three maps. A Basecolour(RGB) texture, Normal(RGB), Metallic(R), Occlusion(G), Specularity(B), and Roughness(A).

    The standard shader doesn't seem to have a specular map(In metallic/metalness/rough/smooth), unless it is hidden like the roughness/smoothness map. Is spec redundant in the general scheme of things? Is the PBR workflow solely the realm of texture generation suites?


    And SF doesn't seem to use the spec slot for Metallic either, unless it is the ambient one. And even if it looks ok in the SF viewer/unity preview window, it turns out plain white in the engine.

    Ok, so I was just gathering some screen shots, and when the camera is in isometric view the SF shader brings colour back.



    I hope this isn't too scatter shot, I can barely piece the concepts together so it is hard to explain where I am having trouble with them.
     
  40. Owers

    Owers

    Joined:
    Jul 7, 2012
    Posts:
    39
    The video you linked is presented by a developer from RUST LTD, who have created the Alloy Physical Shader Framework on the asset store. The maps in his presentation are more tailored towards their implementation of PBR through their Alloy framework, not Unity's official implementation. From the way he's described it, the 'specular' map controls the specular levels of non-metallic surfaces only, which is greyscale because non-metallic surfaces typically don't have coloured specularity. I find this pointless though, you're better off using the specular PBR workflow if you care that much about the specular levels of your non-metallic surfaces, but I can understand the benefit since it allows you to to squeeze in a ambient occlusion map while using only two textures instead of three.

    To put it simply, you don't really need to worry about using a 'specular' map, metallic shaders will use an average specular value for non-metallic surfaces, and that is good enough for most things. If you want to use it, you'll need to switch to Specular mode in Shader Forge, combine the specular map and albedo map with a lerp node the using the metallic map, then plug it into the Specular input. That'll give you the result described in that presentation.
     
    Acegikmo likes this.
  41. Steven

    Steven

    Joined:
    Dec 23, 2009
    Posts:
    43
    I really appreciate the reply Owers. Wasn't looking to wrangle spec maps into anything, but was really keen on a workflow laid out in an understandable way. I was barely getting my head around old school rendering and PBR has ruffled my feathers somewhat.
     
  42. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Hey Andrew! So the instruction counter broke in some unity version, 4.5 I believe, and was never fixed since. I ended up removing it in 5.x, because it still wasn't functional. The way you extract that data in 4.5+ is a bit more complex.
    I may look into it again, but, we'll see!

    Thank you! I appreciate it :)
     
  43. Deleted User

    Deleted User

    Guest

    Last edited by a moderator: Apr 5, 2016
  44. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Deleted User likes this.
  45. Deleted User

    Deleted User

    Guest

    Work well in your project, or give some problem? Because i'm in search of a way for improve system also for x and z axis.
     
  46. Deleted User

    Deleted User

    Guest

    However if you want more performance enable slice for all faces.
     
  47. movra

    movra

    Joined:
    Feb 16, 2013
    Posts:
    566
    When I load for example the Pixelated Rotator from the Example Scene into the Shader Forge editor, the node previews seem to be disabled or do not take the UV Coord into account. Some node previews are black, such as the Frac node's, while the nodes after the Noise do not show the expected colors. I reckon that behavior is by design to speed up the loading.

    I can force the generation of the previews by reconnecting the UV Coord, when Auto-Update Node Previews is enabled in the Settings. But I assume there is a way to properly update the node previews manually? Also, maybe there should be an indicator that shows the node previews are not up-to-date?

     
  48. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Odd, not sure why it would do that. Does it even happen when generate node previews is on when opened?
     
  49. movra

    movra

    Joined:
    Feb 16, 2013
    Posts:
    566
    So it's not supposed to happen? Did I miss a setting?

    This behavior occurs with v1.12 in Unity 5, but also with v0.36 in Unity 4.6. Direct3D 11 disabled or enabled doesn't affect it.

    Unity 5 Shader Forge v1.12:



    Unity 4 Shader Forge v0.36 :



    Unity 5 Shader Forge v1.12 DX11 Tesselation after pressing "Open shader in Shader Forge":



    After reconnecting the UV Coord node:



    Unity 5 Shader Forge v1.12 Parallax after pressing "Open shader in Shader Forge":



    After reconnecting the UV Coord node:

     
    Last edited: Mar 24, 2015
  50. Deleted User

    Deleted User

    Guest

    I'm surprised I haven't bought this by now, as I'm not sure when Unity are going to pull their finger out I'm game.

    Thanks for all your hard work @Acegikmo, looking forward to using it.
     
    Acegikmo likes this.