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

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    Essentially what I'm trying to do is recreate something similar to this:

    https://github.com/jm991/UnityThirdPersonTutorial/blob/master/Assets/Shaders/DiffuseWorldUV.shader

    Except with a few changes so I can do things like move geometry around the scene without the textures sliding around all willy-nilly or rotating weirdly when I rotate the object. On top of that, I'm using vertex colours to help paint on geometry. Right now I'm using this as my node graph:



    The end goal is to use this to help me rapidly prototype prop textures and levels in Unity without having to go through a messy UV unwrapping/texturing process for things that don't need a lot of detail. This kiiiinda removes a couple of awkward steps from my art passes. As you can see, I'm using the vertex normal direction instead of the world normals, but that leads to all sorts of nasty distortion.

    So I have two questions:
    1. How can I implement worldNormals instead of using regular normals?
    2. How can I solve the problem where rotating the object causes textures to rotate and skew?
    edit: so I read the wiki page on triplanar mapping, looked up some stuff in UDK materials, and completely rebuilt this material and now it works. Kinda. I basically rebuilt 90% of the graph.



    That said, I still have no idea how to combat distortion when rotating the mesh.
     
    Last edited: Dec 22, 2014
  3. neroziros

    neroziros

    Joined:
    Aug 25, 2012
    Posts:
    129
    Hi there! I was wondering if someone could help me with my fresnel problem!
    Fresnel Problem.png
    I would like the shield always looks like in the left image(always facing towards the camera),any suggestions?

    Here is my current node tree:
    sf_aegisshield_12212014.png
     
    Last edited: Dec 22, 2014
  4. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    Is the fact that it's clipping through the wall that's the problem or the fact that it's not facing toward the camera?
     
  5. neroziros

    neroziros

    Joined:
    Aug 25, 2012
    Posts:
    129
    Not facing towards the camera :(
     
  6. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    I'm sure not many people will relate to this but I just wanted to share. This is a custom self-illumination shader that imitates the fog on a distance with accurate self-illumination surface. When you apply fog to your scene, it covers the diffuse and self illumination as well. But in real life light travels through the fog, depending on it's intensity.

    This shader disables the default fog and displays its on with a lerp depth node. So the diffuse gets covered with fog, but not the illumination. Makes buildings and lights relatively more convincing when looking from a distance.

     
  7. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    World normals should simply be the vertex normal direction in world space, which, in SF, would be the normal node, leaving the perturbed checkbox unchecked. To combat distortion, you could transform the normals from world space to local space using the transform node.

    I presume you've got an orthographic camera?
    The fresnel node is using the view vector, which, for some reason, is still different per-pixel when using the ortho. camera. (I'll blame Unity for this one)

    Here's a setup that's using the camera forward direction instead of the view vector:
    sf_newshader_12222014.png
     
  8. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Nice work! Looks great :)
     
  9. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    I'm not sure how to work that in to my new node structure:



    This is what I use right now, so I can move the mesh, but rotating the mesh results in this:





    However, if I put a transform node after the normal direction node, I get this when I try and rotate:



    Neither situation is what I'd like, which is the mesh rotating with its textures properly aligned.
     
  10. Deleted User

    Deleted User

    Guest

    Acegikmo likes this.
  11. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    SF 1.0 When :O
     
  12. Deleted User

    Deleted User

    Guest

    Hope before 25 december :'(
     
  13. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Last edited: Dec 23, 2014
  14. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Hopefully tonight!
     
  15. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    Have you thought about using something like interior mapping on close LOD models?

    http://interiormapping.oogst3d.net/

    It could really help flesh stuff out if you're making a game where you're relatively close to buildings.
     
    Cactus_on_Fire likes this.
  16. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    I'm literally at the edge of my seat... Does it include the realtime arealight reflections ?

    That looks like an amazing solution for detailed buildings. I actually tried the parallax for glass parts at first but it didn't give an accurate effect so I took it off the shader. Although I don't know if SF is capable of doing such a thing and how much gpu it would cost is another question. I can use cutout for the glass and add Unlit planes for the building floors and ceilings but that means a simple box building will have like 10 times the polycount. And since all the buildings in the world is one mesh, it means I have to do each one by hand with different textures and UVs, which sounds like a nightmare.
     
  17. Deleted User

    Deleted User

    Guest

    But there is any problem with unity 5 gi implementation?
     
    Last edited by a moderator: Dec 23, 2014
  18. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Sadly no, they will have to wait just a bit longer!

    Yes, this is the last 1% I'm working on :)

    I would guess 1.0 is done in about three hours from now!
     
    IFL likes this.
  19. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    This might sound weird, but try bypassing the Power node for the normal. I vaguely remember that being an issue when used with the Transform node. (not an SF issue, but a general transforming issue)

    [Edit:]
    Yep! A simple triplanar shader example:
    SF_NormalPowerTransform02.jpg
    SF_NormalPowerTransform01.jpg

    [Edit2:]
    Just realized that this might not solve your issue since your node setup is far different than what I tested. Leaving this post because it might help someone. Hooray for solving problems that probably don't exist!
     
    Last edited: Dec 23, 2014
  20. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    It doesn't look that different from mine, actually. Just a lot more streamlined and efficient in ways I've overlooked. I'll play around with it and see if I can't get it to work with my modified setup.

    edit: Yep! This works! And it's a lot less laggy in the SF editor now that I have the redundant nodes out of the way.





    Now I just need to figure out a way to get the fine control over the blending sharpness back...
     
    Last edited: Dec 23, 2014
  21. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Wow. I'm glad that was the problem.
    Try putting the Power after the Abs or Transform...? I don't actually know if that's a problem...
     
  22. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    It ends up being one. For some reason, there seem to be tiny gaps of pure black in the normals, so when I apply the pow function to them in any capacity, it widens the black areas and instead leaves little spotlights of the existing colours.
     
  23. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Well, this is it, Shader Forge 1.0 is now officially released!
    Time to celebrate!
    https://twitter.com/JoachimHolmer/status/547534633001553920

    New in Shader Forge 1.0:
    • Added node: Object Scale (Unity 5+ only)
    • Added node: Fog Color
    • Added node: DDX
    • Added node: DDY
    • The node flow is now from left-to-right instead of right-to-left
    • You can now make shaders support Unity 5's reflection probes
    • When using Unity 5, Unity 5's PBR method will now be used instead of the old one
    • You can now set per-node variable precision to either Float, Half or Fixed
    • You can now plug in Diffuse Ambient Occlusion into the main node
    • You can now plug in Specular Ambient Occlusion into the main node
    • You can now manually set the internal name of properties
    • You can now use two additional UV channels, uv2 and uv3 (Unity 5+ only)
    • You can now optionally disable the right-hand side node browser
    • The depth node now has a preview icon & data
    • You can now use Alpha without the shader being alpha blended
    • There's now a console, which will warn you about various issues you may have
    - Error when a connected node is missing required inputs
    - Error when property nodes have a name conflict
    - Warnings when not using lightmapping naming conventions
    - Warning when disabling the target renderer required to view the shader on the workstation
    - Warning when using alpha blending with no alpha connected
    - Warning when not using alpha blending with alpha connected
    - Warning when using Unity 5 lightmapping, due to it currently being broken
    - Warning when using PBL without specular
    • Optimized the editor performance of the node tree - especially when you have lots of nodes
    • The default blending mode, previously named Off, is now named Opaque
    • Fixed several issues with lightmapping in 4.x
    • Fixed minor issues with spacing and UVs unnecessarily declaring variables in the generated code
    • Fixed a bug in Unity 5 where fog didn't work at all
    • Fixed a bug in Unity 5 where light probes oversaturated on scaled objects
    • Fixed a bug where lightmapped surfaces didn't receive real-time shadows
    • Fixed a bug where the interface disappeared when pressing return on certain nodes
    • Fixed a bug where you couldn't use copy/paste/cut in the code node
    • Fixed a bug where pressing delete with a text field selected, deleted selected nodes instead of a character
    • Fixed a bug in the toggle node and the normal direction node, where they had incorrect default values on load
    • 20 nodes that unnecessarily defined variables, no longer do so


    (Unity 5 support is still partial though, simply because Unity 5 is still changing a lot, and the fact that the new lightmap system is tricky to work with)



    Thank you all for your patience with this update :)
    It has taken a long time to get this one done, I hope it works out well!
    (Otherwise I'll have a lot of bugfixing to do during this time of the year, being so close to the celebration of Newton's birthday and all)
     
  24. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083


    The fact I can do this right in the editor now is absolutely fantastic.
     
  25. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
    Awsome update, just one thing.

    What do the half/fixed/float presisions mean?

    Side note the bright green text for these is hard to read in the free/light version, I think it really needs to be darker or black. It's just a small thing that would be nice.

    Edit: and what would the DDX/Y be good/used for?
     
  26. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Good catch, never looked at it in the light skin! Thanks :)
     
  27. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
  28. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    So I've been playing around with DDX and DDY and I can see some potential I can use there, though I do have a bit of a problem. Unless I manually go into the shader code and slap #pragma glsl in there, I end up with the standard pink error mesh. Is there a way to force this from the editor?
     
  29. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Yes, using a texture in the vert offset input or using the MIP input of a texture.
    This is now fixed for 1.01 though, thanks :)
     
  30. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    Oh, that's a pretty handy workaround, good to see there's an update to that coming too!
     
  31. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    So, being the rather foolish person I am, I forgot to properly hook up some of my nodes when rebuilding my blending system. Here it is fully functional:



    And in case anyone needs a triplanar shader which supports vertex colours to determine where textures are applied, here's the uncompiled shader. It's SUPER handy for prototyping object and level textures in-situ. I've been using (earlier versions) it alongside Prototype and VPaint and it's been a godsend.

    Code (CSharp):
    1. // Shader created with Shader Forge v1.00
    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.00;sub:START;pass:START;ps:flbk:,lico:1,lgpr:1,nrmq:1,limd:1,uamb:True,mssp:True,lmpd:False,lprd:False,rprd:False,enco:False,frtr:True,vitr:True,dbil:True,rmgx:True,rpth:0,hqsc:True,hqlp:False,tesm:0,blpr:0,bsrc:0,bdst:0,culm:0,dpts:2,wrdp:True,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-505-OUT;n:type:ShaderForge.SFN_Tex2d,id:2,x:34108,y:32049,varname:node_2,prsc:2,tex:fc45551c8c29f814aa9ed6917194a284,ntxv:0,isnm:False|UVIN-29-OUT,TEX-3-TEX;n:type:ShaderForge.SFN_Tex2dAsset,id:3,x:33750,y:32180,ptovrint:False,ptlb:Red Texture,ptin:_RedTexture,varname:node_3,tex:fc45551c8c29f814aa9ed6917194a284,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2d,id:5,x:34108,y:32174,varname:node_4,prsc:2,tex:fc45551c8c29f814aa9ed6917194a284,ntxv:0,isnm:False|UVIN-31-OUT,TEX-3-TEX;n:type:ShaderForge.SFN_Tex2d,id:7,x:34108,y:32298,varname:node_6,prsc:2,tex:fc45551c8c29f814aa9ed6917194a284,ntxv:0,isnm:False|UVIN-33-OUT,TEX-3-TEX;n:type:ShaderForge.SFN_FragmentPosition,id:25,x:32633,y:32747,varname:node_25,prsc:2;n:type:ShaderForge.SFN_ValueProperty,id:26,x:33046,y:33003,ptovrint:False,ptlb:Scale,ptin:_Scale,varname:node_26,prsc:2,glob:False,v1:1;n:type:ShaderForge.SFN_Divide,id:27,x:33231,y:32816,varname:node_27,prsc:2|A-513-XYZ,B-26-OUT;n:type:ShaderForge.SFN_ComponentMask,id:29,x:33447,y:32668,varname:node_29,prsc:2,cc1:0,cc2:1,cc3:-1,cc4:-1|IN-27-OUT;n:type:ShaderForge.SFN_ComponentMask,id:31,x:33444,y:32814,varname:node_31,prsc:2,cc1:0,cc2:2,cc3:-1,cc4:-1|IN-27-OUT;n:type:ShaderForge.SFN_ComponentMask,id:33,x:33444,y:32962,varname:node_33,prsc:2,cc1:1,cc2:2,cc3:-1,cc4:-1|IN-27-OUT;n:type:ShaderForge.SFN_ChannelBlend,id:36,x:34478,y:31999,varname:node_36,prsc:2,chbt:0|M-530-OUT,R-7-RGB,G-5-RGB,B-2-RGB;n:type:ShaderForge.SFN_ObjectPosition,id:470,x:32633,y:32880,varname:node_470,prsc:2;n:type:ShaderForge.SFN_Tex2dAsset,id:478,x:33770,y:32650,ptovrint:False,ptlb:Green Texture,ptin:_GreenTexture,varname:node_471,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2dAsset,id:480,x:33775,y:33004,ptovrint:False,ptlb:Blue Texture,ptin:_BlueTexture,varname:node_479,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2dAsset,id:482,x:33760,y:33405,ptovrint:False,ptlb:Alpha Texture,ptin:_AlphaTexture,varname:node_481,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2d,id:484,x:34109,y:32455,varname:node_483,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-29-OUT,TEX-478-TEX;n:type:ShaderForge.SFN_Tex2d,id:486,x:34109,y:32580,varname:node_485,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-31-OUT,TEX-478-TEX;n:type:ShaderForge.SFN_Tex2d,id:488,x:34109,y:32704,varname:node_487,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-33-OUT,TEX-478-TEX;n:type:ShaderForge.SFN_Tex2d,id:490,x:34111,y:33107,varname:node_489,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-33-OUT,TEX-480-TEX;n:type:ShaderForge.SFN_Tex2d,id:492,x:34111,y:32983,varname:node_491,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-31-OUT,TEX-480-TEX;n:type:ShaderForge.SFN_Tex2d,id:494,x:34111,y:32858,varname:node_493,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-29-OUT,TEX-480-TEX;n:type:ShaderForge.SFN_Tex2d,id:496,x:34113,y:33513,varname:node_495,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-33-OUT,TEX-482-TEX;n:type:ShaderForge.SFN_Tex2d,id:498,x:34113,y:33389,varname:node_497,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-31-OUT,TEX-482-TEX;n:type:ShaderForge.SFN_Tex2d,id:500,x:34113,y:33264,varname:node_499,prsc:2,tex:b66bceaf0cc0ace4e9bdc92f14bba709,ntxv:0,isnm:False|UVIN-29-OUT,TEX-482-TEX;n:type:ShaderForge.SFN_ChannelBlend,id:501,x:34467,y:32541,varname:node_501,prsc:2,chbt:0|M-530-OUT,R-488-RGB,G-486-RGB,B-484-RGB;n:type:ShaderForge.SFN_ChannelBlend,id:503,x:34464,y:32971,varname:node_503,prsc:2,chbt:0|M-530-OUT,R-490-RGB,G-492-RGB,B-494-RGB;n:type:ShaderForge.SFN_ChannelBlend,id:504,x:34461,y:33360,varname:node_504,prsc:2,chbt:0|M-530-OUT,R-496-RGB,G-498-RGB,B-500-RGB;n:type:ShaderForge.SFN_ChannelBlend,id:505,x:34752,y:32712,varname:node_505,prsc:2,chbt:0|M-507-OUT,R-36-OUT,G-501-OUT,B-503-OUT,A-504-OUT;n:type:ShaderForge.SFN_VertexColor,id:506,x:34290,y:32412,varname:node_506,prsc:2;n:type:ShaderForge.SFN_Append,id:507,x:34467,y:32412,varname:node_507,prsc:2|A-506-RGB,B-506-A;n:type:ShaderForge.SFN_Subtract,id:509,x:32873,y:32816,varname:node_509,prsc:2|A-25-XYZ,B-470-XYZ;n:type:ShaderForge.SFN_Transform,id:513,x:33046,y:32816,varname:node_513,prsc:2,tffrom:0,tfto:1|IN-509-OUT;n:type:ShaderForge.SFN_Transform,id:516,x:32644,y:32197,varname:node_516,prsc:2,tffrom:0,tfto:1|IN-532-OUT;n:type:ShaderForge.SFN_Abs,id:518,x:32812,y:32197,varname:node_518,prsc:2|IN-516-XYZ;n:type:ShaderForge.SFN_Power,id:520,x:33017,y:32197,varname:node_520,prsc:2|VAL-518-OUT,EXP-534-OUT;n:type:ShaderForge.SFN_ComponentMask,id:522,x:33215,y:32044,varname:node_522,prsc:2,cc1:0,cc2:-1,cc3:-1,cc4:-1|IN-520-OUT;n:type:ShaderForge.SFN_ComponentMask,id:524,x:33215,y:32197,varname:node_524,prsc:2,cc1:1,cc2:-1,cc3:-1,cc4:-1|IN-520-OUT;n:type:ShaderForge.SFN_ComponentMask,id:526,x:33215,y:32351,varname:node_526,prsc:2,cc1:2,cc2:-1,cc3:-1,cc4:-1|IN-520-OUT;n:type:ShaderForge.SFN_Add,id:528,x:33392,y:32197,varname:node_528,prsc:2|A-522-OUT,B-524-OUT,C-526-OUT;n:type:ShaderForge.SFN_Divide,id:530,x:33560,y:32197,varname:node_530,prsc:2|A-520-OUT,B-528-OUT;n:type:ShaderForge.SFN_NormalVector,id:532,x:32461,y:32197,prsc:2,pt:False;n:type:ShaderForge.SFN_Slider,id:534,x:32644,y:32386,ptovrint:False,ptlb:Sharpness,ptin:_Sharpness,varname:node_13,prsc:2,min:1,cur:1,max:100;proporder:3-478-480-482-26-534;pass:END;sub:END;*/
    5.  
    6. Shader "Custom/Triplanar Test" {
    7.     Properties {
    8.         _RedTexture ("Red Texture", 2D) = "white" {}
    9.         _GreenTexture ("Green Texture", 2D) = "white" {}
    10.         _BlueTexture ("Blue Texture", 2D) = "white" {}
    11.         _AlphaTexture ("Alpha Texture", 2D) = "white" {}
    12.         _Scale ("Scale", Float ) = 1
    13.         _Sharpness ("Sharpness", Range(1, 100)) = 1
    14.     }
    15.     SubShader {
    16.         Tags {
    17.             "RenderType"="Opaque"
    18.         }
    19.         LOD 200
    20.         Pass {
    21.             Name "ForwardBase"
    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 exclude_renderers xbox360 ps3 flash d3d11_9x
    35.             #pragma target 3.0
    36.             uniform float4 _LightColor0;
    37.             uniform sampler2D _RedTexture; uniform float4 _RedTexture_ST;
    38.             uniform float _Scale;
    39.             uniform sampler2D _GreenTexture; uniform float4 _GreenTexture_ST;
    40.             uniform sampler2D _BlueTexture; uniform float4 _BlueTexture_ST;
    41.             uniform sampler2D _AlphaTexture; uniform float4 _AlphaTexture_ST;
    42.             uniform float _Sharpness;
    43.             struct VertexInput {
    44.                 float4 vertex : POSITION;
    45.                 float3 normal : NORMAL;
    46.                 float4 vertexColor : COLOR;
    47.             };
    48.             struct VertexOutput {
    49.                 float4 pos : SV_POSITION;
    50.                 float4 posWorld : TEXCOORD0;
    51.                 float3 normalDir : TEXCOORD1;
    52.                 float4 vertexColor : COLOR;
    53.                 LIGHTING_COORDS(2,3)
    54.             };
    55.             VertexOutput vert (VertexInput v) {
    56.                 VertexOutput o;
    57.                 o.vertexColor = v.vertexColor;
    58.                 o.normalDir = mul(_Object2World, float4(v.normal,0)).xyz;
    59.                 float4 objPos = mul ( _Object2World, float4(0,0,0,1) );
    60.                 o.posWorld = mul(_Object2World, v.vertex);
    61.                 float3 lightColor = _LightColor0.rgb;
    62.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    63.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    64.                 return o;
    65.             }
    66.             fixed4 frag(VertexOutput i) : COLOR {
    67.                 float4 objPos = mul ( _Object2World, float4(0,0,0,1) );
    68.                 i.normalDir = normalize(i.normalDir);
    69. /////// Vectors:
    70.                 float3 normalDirection = i.normalDir;
    71.                 float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
    72.                 float3 lightColor = _LightColor0.rgb;
    73. ////// Lighting:
    74.                 float attenuation = LIGHT_ATTENUATION(i)*2;
    75.                 float3 attenColor = attenuation * _LightColor0.xyz;
    76. /////// Diffuse:
    77.                 float NdotL = max(0.0,dot( normalDirection, lightDirection ));
    78.                 float3 indirectDiffuse = float3(0,0,0);
    79.                 float3 directDiffuse = max( 0.0, NdotL) * attenColor;
    80.                 indirectDiffuse += UNITY_LIGHTMODEL_AMBIENT.rgb*2; // Ambient Light
    81.                 float4 node_507 = float4(i.vertexColor.rgb,i.vertexColor.a);
    82.                 float3 node_520 = pow(abs(mul( _World2Object, float4(i.normalDir,0) ).xyz.rgb),_Sharpness);
    83.                 float3 node_530 = (node_520/(node_520.r+node_520.g+node_520.b));
    84.                 float3 node_27 = (mul( _World2Object, float4((i.posWorld.rgb-objPos.rgb),0) ).xyz.rgb/_Scale);
    85.                 float2 node_33 = node_27.gb;
    86.                 float4 node_6 = tex2D(_RedTexture,TRANSFORM_TEX(node_33, _RedTexture));
    87.                 float2 node_31 = node_27.rb;
    88.                 float4 node_4 = tex2D(_RedTexture,TRANSFORM_TEX(node_31, _RedTexture));
    89.                 float2 node_29 = node_27.rg;
    90.                 float4 node_2 = tex2D(_RedTexture,TRANSFORM_TEX(node_29, _RedTexture));
    91.                 float4 node_487 = tex2D(_GreenTexture,TRANSFORM_TEX(node_33, _GreenTexture));
    92.                 float4 node_485 = tex2D(_GreenTexture,TRANSFORM_TEX(node_31, _GreenTexture));
    93.                 float4 node_483 = tex2D(_GreenTexture,TRANSFORM_TEX(node_29, _GreenTexture));
    94.                 float4 node_489 = tex2D(_BlueTexture,TRANSFORM_TEX(node_33, _BlueTexture));
    95.                 float4 node_491 = tex2D(_BlueTexture,TRANSFORM_TEX(node_31, _BlueTexture));
    96.                 float4 node_493 = tex2D(_BlueTexture,TRANSFORM_TEX(node_29, _BlueTexture));
    97.                 float4 node_495 = tex2D(_AlphaTexture,TRANSFORM_TEX(node_33, _AlphaTexture));
    98.                 float4 node_497 = tex2D(_AlphaTexture,TRANSFORM_TEX(node_31, _AlphaTexture));
    99.                 float4 node_499 = tex2D(_AlphaTexture,TRANSFORM_TEX(node_29, _AlphaTexture));
    100.                 float3 diffuse = (directDiffuse + indirectDiffuse) * (node_507.r*(node_530.r*node_6.rgb + node_530.g*node_4.rgb + node_530.b*node_2.rgb) + node_507.g*(node_530.r*node_487.rgb + node_530.g*node_485.rgb + node_530.b*node_483.rgb) + node_507.b*(node_530.r*node_489.rgb + node_530.g*node_491.rgb + node_530.b*node_493.rgb) + node_507.a*(node_530.r*node_495.rgb + node_530.g*node_497.rgb + node_530.b*node_499.rgb));
    101. /// Final Color:
    102.                 float3 finalColor = diffuse;
    103.                 return fixed4(finalColor,1);
    104.             }
    105.             ENDCG
    106.         }
    107.         Pass {
    108.             Name "ForwardAdd"
    109.             Tags {
    110.                 "LightMode"="ForwardAdd"
    111.             }
    112.             Blend One One
    113.            
    114.            
    115.             Fog { Color (0,0,0,0) }
    116.             CGPROGRAM
    117.             #pragma vertex vert
    118.             #pragma fragment frag
    119.             #define UNITY_PASS_FORWARDADD
    120.             #include "UnityCG.cginc"
    121.             #include "AutoLight.cginc"
    122.             #pragma multi_compile_fwdadd_fullshadows
    123.             #pragma exclude_renderers xbox360 ps3 flash d3d11_9x
    124.             #pragma target 3.0
    125.             uniform float4 _LightColor0;
    126.             uniform sampler2D _RedTexture; uniform float4 _RedTexture_ST;
    127.             uniform float _Scale;
    128.             uniform sampler2D _GreenTexture; uniform float4 _GreenTexture_ST;
    129.             uniform sampler2D _BlueTexture; uniform float4 _BlueTexture_ST;
    130.             uniform sampler2D _AlphaTexture; uniform float4 _AlphaTexture_ST;
    131.             uniform float _Sharpness;
    132.             struct VertexInput {
    133.                 float4 vertex : POSITION;
    134.                 float3 normal : NORMAL;
    135.                 float4 vertexColor : COLOR;
    136.             };
    137.             struct VertexOutput {
    138.                 float4 pos : SV_POSITION;
    139.                 float4 posWorld : TEXCOORD0;
    140.                 float3 normalDir : TEXCOORD1;
    141.                 float4 vertexColor : COLOR;
    142.                 LIGHTING_COORDS(2,3)
    143.             };
    144.             VertexOutput vert (VertexInput v) {
    145.                 VertexOutput o;
    146.                 o.vertexColor = v.vertexColor;
    147.                 o.normalDir = mul(_Object2World, float4(v.normal,0)).xyz;
    148.                 float4 objPos = mul ( _Object2World, float4(0,0,0,1) );
    149.                 o.posWorld = mul(_Object2World, v.vertex);
    150.                 float3 lightColor = _LightColor0.rgb;
    151.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    152.                 TRANSFER_VERTEX_TO_FRAGMENT(o)
    153.                 return o;
    154.             }
    155.             fixed4 frag(VertexOutput i) : COLOR {
    156.                 float4 objPos = mul ( _Object2World, float4(0,0,0,1) );
    157.                 i.normalDir = normalize(i.normalDir);
    158. /////// Vectors:
    159.                 float3 normalDirection = i.normalDir;
    160.                 float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
    161.                 float3 lightColor = _LightColor0.rgb;
    162. ////// Lighting:
    163.                 float attenuation = LIGHT_ATTENUATION(i)*2;
    164.                 float3 attenColor = attenuation * _LightColor0.xyz;
    165. /////// Diffuse:
    166.                 float NdotL = max(0.0,dot( normalDirection, lightDirection ));
    167.                 float3 directDiffuse = max( 0.0, NdotL) * attenColor;
    168.                 float4 node_507 = float4(i.vertexColor.rgb,i.vertexColor.a);
    169.                 float3 node_520 = pow(abs(mul( _World2Object, float4(i.normalDir,0) ).xyz.rgb),_Sharpness);
    170.                 float3 node_530 = (node_520/(node_520.r+node_520.g+node_520.b));
    171.                 float3 node_27 = (mul( _World2Object, float4((i.posWorld.rgb-objPos.rgb),0) ).xyz.rgb/_Scale);
    172.                 float2 node_33 = node_27.gb;
    173.                 float4 node_6 = tex2D(_RedTexture,TRANSFORM_TEX(node_33, _RedTexture));
    174.                 float2 node_31 = node_27.rb;
    175.                 float4 node_4 = tex2D(_RedTexture,TRANSFORM_TEX(node_31, _RedTexture));
    176.                 float2 node_29 = node_27.rg;
    177.                 float4 node_2 = tex2D(_RedTexture,TRANSFORM_TEX(node_29, _RedTexture));
    178.                 float4 node_487 = tex2D(_GreenTexture,TRANSFORM_TEX(node_33, _GreenTexture));
    179.                 float4 node_485 = tex2D(_GreenTexture,TRANSFORM_TEX(node_31, _GreenTexture));
    180.                 float4 node_483 = tex2D(_GreenTexture,TRANSFORM_TEX(node_29, _GreenTexture));
    181.                 float4 node_489 = tex2D(_BlueTexture,TRANSFORM_TEX(node_33, _BlueTexture));
    182.                 float4 node_491 = tex2D(_BlueTexture,TRANSFORM_TEX(node_31, _BlueTexture));
    183.                 float4 node_493 = tex2D(_BlueTexture,TRANSFORM_TEX(node_29, _BlueTexture));
    184.                 float4 node_495 = tex2D(_AlphaTexture,TRANSFORM_TEX(node_33, _AlphaTexture));
    185.                 float4 node_497 = tex2D(_AlphaTexture,TRANSFORM_TEX(node_31, _AlphaTexture));
    186.                 float4 node_499 = tex2D(_AlphaTexture,TRANSFORM_TEX(node_29, _AlphaTexture));
    187.                 float3 diffuse = directDiffuse * (node_507.r*(node_530.r*node_6.rgb + node_530.g*node_4.rgb + node_530.b*node_2.rgb) + node_507.g*(node_530.r*node_487.rgb + node_530.g*node_485.rgb + node_530.b*node_483.rgb) + node_507.b*(node_530.r*node_489.rgb + node_530.g*node_491.rgb + node_530.b*node_493.rgb) + node_507.a*(node_530.r*node_495.rgb + node_530.g*node_497.rgb + node_530.b*node_499.rgb));
    188. /// Final Color:
    189.                 float3 finalColor = diffuse;
    190.                 return fixed4(finalColor * 1,0);
    191.             }
    192.             ENDCG
    193.         }
    194.     }
    195.     FallBack "Diffuse"
    196.     CustomEditor "ShaderForgeMaterialInspector"
    197. }
    198.  
     
    Acegikmo and IFL like this.
  32. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    That's marvelous. Definitely wiki material, if you don't mind doing that.
     
  33. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Figured out how to do custom placement/rotation/size for a square or a texture. I've been meaning to do it for a while but never had a good enough reason. Here it is, very commented, and very unoptimized:
    SF_CustomPlacement.jpg
     
  34. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Nice one IFL!

    Also,
    New in Shader Forge 1.01:
    • Fixed a bug where Tessellation had holes if you used a non-uniform tessellation factor @Seith
    • Fixed a bug where Texture 2D nodes marked as normal maps didn't compile properly @Chaoss
    • Fixed a bug where DDX and DDY sometimes didn't work on OpenGL @Murgilod
    • Fixed a bug where the precision menu of nodes sometimes disappeared
    • The material asset ShaderForgeInternal.mat has now been removed due to version control annoyances
    • Fixed an issue where the precision dropdown menu was almost unreadable in the light Unity skin @DaDarkDragon
     
  35. Deleted User

    Deleted User

    Guest

    Question, what exactly does not work of unity 5 lightmap? Because i have seen nothing of strange.

     
  36. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Directional lightmaps are broken in Unity 5
     
  37. Deleted User

    Deleted User

    Guest

    Aaaah...then it's a problem of unity 5? I always thought was a problem of SF :/
     
  38. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Unity 4 directional lightmaps should work as of SF 1.0 ;)
     
  39. Deleted User

    Deleted User

    Guest

    I understand this, but i was wondering why you have postponed the fix of lightmap in unity 5, because that operating normally for me (or at least i think)
     
    Last edited by a moderator: Dec 25, 2014
  40. Deleted User

    Deleted User

    Guest

    Bug?

     
  41. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Odd. How did you cause that?
     
  42. Deleted User

    Deleted User

    Guest

    During some test with DDX and DDY (i have also used two Append with these)
     
  43. sysper

    sysper

    Joined:
    Oct 11, 2014
    Posts:
    33
    Hi, Thank you for your great Asset!

    I am making 2D game and I would like to modify some of shaders of the sprites.
    How to create a Sprites-Default shader?

    I want to convert below custom shader code to Shader Forge nodes.
    Below shader is for Spine object. (http://esotericsoftware.com/)
    Could teach me how to make nodes with Shader Forge?

    Shader"Custom/SpineAdditive" {
    Properties {
    _MainTex ("Texture2D", 2D) = "black" {}
    }
    SubShader {
    Tags { "Queue"="Transparent""IgnoreProjector"="False""RenderType"="Transparent" }

    CullOff
    ZWriteOff
    LightingOff

    Pass {
    Blend One OneMinusSrcAlpha
    ColorMaterial AmbientAndDiffuse

    SetTexture [_MainTex] {
    Combinetexture * primary
    }
    }
    }
    }

    Thanks in advance.
     
    Last edited: Dec 27, 2014
  44. toxtronyx

    toxtronyx

    Joined:
    Aug 21, 2014
    Posts:
    114
    Which Beta do you recommend? I am still on 14 and ran into severe problems.
     
  45. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    @toxtronyx The last one obviously, why would you use an old build when the newer ones gives you more stuff and correct bugs ?
    @sysper That's a really basic shader, just plug the RGB channel of a texture node into the diffuse and the A(alpha)channel into the other alpha, besides that, the shader ignores lighting, I am not sure that's what you really want so I wont tell you how to do that.
    You can find more tutorials right here.
     
  46. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Like Eideren said - always use the latest version
     
  47. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Hi guys. Quick question:

    Is it possible to create a "scanline" that runs up and down a character vertically in a shader, regardless of how the uvs of the character is set up?

    I know you could achieve this effect using a planar mapping of uvs from the front, but that makes it impossible to texture the character like normal..

    Any ideas?
     
  48. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
  49. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Here you go



    If you want them to go the other way, simply change the panner values to (0.1 , 0) instead of (0 , 0.1)
     
  50. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @DaDarkDragon: Hmmm interesting, this seems to work exactly like what I was trying to do. Thanks man! I admit I looked over this before, but dismissed it because I couldn't see it in action... haha..
    @Cactus_on_Fire: Thanks!