Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    523
    @Acegikmo Here is a simple repro. I should have included it in my last post. I'm using Sonic Ether's SSAO but it does it with any SSAO I've tried.

     

    Attached Files:

  2. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    570
    There's a great thing called Shader Forge wiki that helps in a lot of cases with basic questions like this:
    http://acegikmo.com/shaderforge/wiki/index.php?title=UV_Scaling_&_Offset
    Simply put: use the UVCoord node and ADD a vector2 to it. That offsets your texture coordinates.
     
    Last edited: Jun 1, 2015
  3. SpaceRay

    SpaceRay

    Joined:
    Feb 26, 2014
    Posts:
    386
    WOW!!! I see that these thread has already 77 pages!! great for the popularity and success of thew package, but bad for reading all the 77 pages to begin to understand and learn about this awesome and amazing software

    My question is how to begin and start learning about how to use and make your own shader with Shader Forge? Where to start first?

    Of course that I know that the first is to go to the Shader Forge Wiki and see the tutorials

    http://acegikmo.com/shaderforge/wiki/index.php?title=Main_Page

    But then after there are a LOT of topics in different categories shown on the main page, so should I follow this order or how would be suggested to do it?

    I have bought this some time ago but have not tried to use it yet until now.

    I have a lot of experience in using the Node Based Filter Forge software and it seems that this is something similar in some way, you just have to learn what each node do, and then build the shader with the different components.

    Thanks for any help and congratulations for making this great software that seems very useful, helpful with great potential when you learn to use it

    best wishes
     
  4. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    570
    I get the feeling that some very basic questions have not been answered by now - neither by the wiki nor by this thread.
    Perhaps we should put some more beginner orientated chapters on the wiki?
    Like:
    What is a shader?
    How does a shader operate?
    What data does a shader have access to?
    How can I pass data to a shader?
    Of course you can read about these topics in the Unity documentation as well (and you should to make the most out of SF - since it was made for Unity). But it seems a lot of people would like to get basic information and concepts like these from your product's documentation, Acegikmo.
     
    SpaceRay likes this.
  5. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    Would be perfect Wiki material :)
    It's touched upon in here: http://acegikmo.com/shaderforge/wiki/index.php?title=What_is_a_Shader?
     
  6. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,295
    Does anyone know how to modify the Vegetation demo shader to use Wind Zones?
     
  7. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    934
  8. gfunk

    gfunk

    Joined:
    Mar 17, 2015
    Posts:
    23
    Hey guys, I have a problem with transparency. I have a black and white opacity map, but when I plug it in, it
    makes the whole hair mesh semi transparent - which I don't want. Hopefully you can see the problem on the attached images. The transparency map should mask only the tips of the hair - the uv's are mapped correctly... Any help would be much appreciated! Thanks!

    edit: I also just noticed that even if I don't have anything plugged into the opacity slot, the mesh is still semi transparent! Any idea what could be going on here?

    fail_1.png nodesetup.png
     
    Last edited: Jun 2, 2015
  9. mimminito

    mimminito

    Joined:
    Feb 10, 2010
    Posts:
    779
    I am quite new to writing shaders, but I was wondering if anyone could help me write a "split alpha" shader? This would be taking a texture, splitting it in half (horizontal) and then using the bottom half as the mask, so anything black is transparent and the rest is white. Any ideas how I can achieve this in Shader Forge?
     
  10. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    570
    @gfunk
    Sorting semi-transparent objects is not trivial. Hair sorting especially is a big thing in gaming industry. Basically the renderer (not the shader, I am talking about the CPU side) is looking at the pivot point of a mesh to decide if it is closer to the camera or further away from it than another mesh. This dictates the rendering order. If your hair is made of one single mesh the renderer just sends it off to the GPU which then has no concept of the hair layout either.
    What you'd need to do is split the hair into multiple meshes that share the same material. But each hair strand would have to be carefully crafted - so that their pivot points indicate which strand covers which. Sounds awful? It is.
     
    gfunk and Ryirs like this.
  11. Ryirs

    Ryirs

    Joined:
    Jan 9, 2015
    Posts:
    7
    Hi, i have a noob optimization question regarding how shaders behave in general.
    I'm currently currently doing some lerp/multiply between maps and colors and i was wondering if the computation happens every frame or since there are no changes on the input, is it cached somehow ?

    Thanks.
     
  12. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    570
    @Ryirs
    Happens every frame (per fragment/pixel or vertex). If you know your scene won't change for a couple of frames you could work with rendertargets - let the camera render into it, deactivate the camera until it is needed again in the future and just display that target for the time being.
    Otherwise the renderer will just throw anything the current camera sees to the GPU which happily chucks away the old frame and presents to you the new one.

    Most often you won't need these kind of optimizations, though.
     
  13. mimminito

    mimminito

    Joined:
    Feb 10, 2010
    Posts:
    779
    So, ive given it a go and ive gotten quite far, but have an issue. As you can see from the node tree below, I have it working with a texture that I apply via the editor. But when I play a movie back, the transparency works but the video is black, like the other texture below. Any thoughts? I am using VTP to play the videos inside the editor.

    sf_splitalpha_622015.png Screen Shot 2015-06-02 at 11.37.35.png
     
  14. mimminito

    mimminito

    Joined:
    Feb 10, 2010
    Posts:
    779
    Fixed it! Here is the new node tree:

    sf_splitalpha_622015.png
     
    Marco-Sperling likes this.
  15. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    To add on to this, if you don't want to split the mesh, you have to have proper vert order - the lower layers must have a lesser index. It's actually pretty easy to set the vert order in Blender (Menu: Mesh/Sort Elements) once you see how it works. With correct vert order plus a two-pass shader (clip with depth, alpha-blended), you can get great hair results.
     
    Marco-Sperling and gfunk like this.
  16. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    570
    gfunk likes this.
  17. gfunk

    gfunk

    Joined:
    Mar 17, 2015
    Posts:
    23
    Thank you guys so much for your inputs.
    Made me become aware of the issues I haven't thought of before or even knew they existed!

    However, my issue still persists. I made a very simplified scene with only one plane
    and a sphere behind it to illustrate my point. As you can see from the node setup, the opacity isn't even plugged in,
    yet the plane is still transparent? It is a bit confusing to me, just can't figure it out.

    fail_2.png sf_new_hair_sf_632015.png
    The following image is with the opacity texture plugged in - still partially transparent (not good).

    fail_3.png
    Texture settings of the albedo, nothing special here I think:

    texture_settings.png

    Any ideas what I could be doing horribly wrong?
    Is this still a sorting issue? Thanks guys, as always!
     
    Last edited: Jun 3, 2015
  18. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    570
    This looks more like a bug in SF where it didn't set the blend settings back to opaque when you unplugged the alpha texture from the opacity slot.
    You can check the blend mode in the left panel of SF. Let us know about your results when you've checked that setting.
     
  19. gfunk

    gfunk

    Joined:
    Mar 17, 2015
    Posts:
    23
    If you please check out my previous post, you'll see a screenshot which also includes the blending options.
    I went through almost every combination there, didn't make much of a difference!
     
  20. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    570
    I saw that setting, yes. But since you modified the shader by unplugging the alpha/opacity texture (as seen in your last post) the blend settings must have changed. If SF did in fact recognize the unplugging...
    Have you tried closing and reopening SF? I remember that I had similar issues with the blend mode not catching up changes made to the opacity slot in the main node. Usually "turning it off and on again" solved the issue.
     
  21. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Are the sphere and plane a single mesh? If so, your sorting is wrong. This is the blending panel that actually makes a difference when you're working with transparency:
    SF_BlendingPanel.jpg
    Did you post a screenshot of your shader's blending panel?

    It's pretty simple to create a single pass cutout shader in SF, create a single pass alpha blended shader in SF, and then combine the two passes in a multi-pass shader. If you do that, you don't have near as much to worry about with alpha sorting. ;)
     
  22. dblincoeii

    dblincoeii

    Joined:
    Mar 4, 2015
    Posts:
    19
    Ok I thought this would be easy (and I am probably making this really hard), but is there a way to use shader forge for text materials? I add a shader forge material to my text and it turns into blocks. Thanks in advance for your help!
     
  23. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    570
    Best advice I can give due to limited time:
    take a look at the text shader that ships with Unity. I guess there's some UV trickery involved when sampling glyphs from the texture atlas. Or maybe that atlas has to follow a naming convention (_MainTex e.g.).
     
  24. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    Shader Forge 1.14 is now live!

     
  25. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,295
    What exactly is Sky?
     
  26. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    That's the region of the atmosphere and outer space seen from a planet's surface
     
  27. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    To answer your question properly - Sky is a preset you can start out creating a shader with, which has this configuration:
    • Its blending and sorting is set to that of a sky shader, which means it will render behind everything else, and can be used as the sky material in your scene. GI will read the sky values properly too.
    • It's set up to be previewed in the inspector as a sky, so it won't render a sphere with a sky-look on it.
    • It has quite an elaborate example setup for how to create sky color blending and a sun, that will dynamically update if you rotate the directional light in the scene.
     
    Last edited: Jun 4, 2015
  28. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    570
    So with the particle presets do we have access to light vectors in particle space? Can we do normal mapped particles now? Curious to try it out, can't because of other stuff to do atm.
     
  29. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    Nope, that's still an issue. They're just presets, there's nothing special about them other than that :)
    Might come in the future though
     
  30. dblincoeii

    dblincoeii

    Joined:
    Mar 4, 2015
    Posts:
    19
    That's sort of what I thought too. Not sure how to get the glyphs into shader forge though
     
  31. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    1.15 is out! Bugfix + property tags, so you can now hide properties, among other things :)
     
  32. Monokel

    Monokel

    Joined:
    Jun 6, 2013
    Posts:
    1
    Thanks for this really great tool! I do have one question though.
    Is it possible to alter the color of a texture pixel after all the lights have been rendered?
    I do need the following behaviour:
    I have a mesh with a very basic shader that only applies a texture, normal map and diffuse lighting, no specular or other fancy stuff. This works as planned. But after all the lights ahve been added i want to limit the brightness of each pixel to be less then or equal to the brightness of the corresponding pixel on the texture.
    I tried the attached shader but since lighting is shaded per lightsource the result still gets brighter. Even more if there are more lights.

    Is there a possibility to add another shader at the very end?
    Or, is it possible to get the number of lights, so i could aprroximately limit each light to one nth of its resulting brightness?
     

    Attached Files:

  33. MaleficMax

    MaleficMax

    Joined:
    Jul 3, 2013
    Posts:
    5
    Hi all!
    I made a water shader using Shader Forge. Here it is:

    Here is a nodes screenshot:

    But I have a little question.
    Now, because of depth, the upper edge of water (water surface) is absolutely transparent. It is OK, but if I want the upper edge of water (0 mm distance) to have some starting transparency, other from 100%? How can I achieve it?
     
    Murgilod and IFL like this.
  34. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    483
    remap after the depth blend from 0-1 to 0.1-1 or something, then clamp to 0-1 (if needed).

    There's more advanced functions where you can have the blend be smooth but sharp, like from 0-0.1 in the first 0.05, and then 0.1-1 in the remaining 0.95 so that you can have the water take effect immedialtely but not have a sharp and harsh edge.


    Is there going to be a way to sample the grabpass on non-standard UV coords? I think with Strumpys you had to feed it the screen position UVs, but it then allowed you to alter that. Like if I wanted to multi-tap blur or manually distort multiple samples of the grabpass, would I be able to do that?
     
  35. bluemoon

    bluemoon

    Joined:
    Dec 14, 2012
    Posts:
    84
    I see the Shader Forge supports lightmaped shaders but does this include dynamic lightmaps as well?


    Thanks

    Travis
     
  36. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    7,889
    Hi,

    I imported the latest pack in the latest Unity version and the vegetation shader does not work

    Appears pink and says

    Shader error in 'Shader Forge/Examples/Animated Vegetation': Too many output registers declared (12). When no output register has been declared with the semantic 'psize0', 11 o# registers are available. When an o# register has been declared with the semantic 'psize0' (same as 'psize'), 12 registers are available. at line 77 (on d3d9)

    Compiling Vertex program with DIRECTIONAL SHADOWS_SCREEN LIGHTMAP_ON DIRLIGHTMAP_COMBINED DYNAMICLIGHTMAP_OFF FOG_EXP2

    Thanks for any help on this
     
  37. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,295
    In Shader Forge, is there any way to Parallax Blend (Like tesellation but doesn't add geometry)?

     
  38. layola

    layola

    Joined:
    Aug 6, 2013
    Posts:
    94
    how to convert this shader to shader forge node view?
    Code (CSharp):
    1. Shader "Daikon Forge/Default UI Shader"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex("Base (RGB), Alpha (A)", 2D) = "white" {}
    6.     }
    7.  
    8.     SubShader
    9.     {
    10.         LOD 200
    11.  
    12.         Tags
    13.         {
    14.         "IgnoreProjector" = "True"
    15.         "RenderType" = "Transparent"
    16.         "Queue" = "Overlay"
    17.         "PreviewType" = "Plane"
    18.     }
    19.  
    20.         Pass
    21.         {
    22.  
    23.             Cull Off
    24.             Lighting Off
    25.             ZWrite Off
    26.             Fog{ Mode Off }
    27.             Offset -1, -1
    28.             ColorMask RGBA
    29.             Blend SrcAlpha OneMinusSrcAlpha
    30.             ColorMaterial AmbientAndDiffuse
    31.  
    32.             CGPROGRAM
    33. #pragma vertex vert
    34. #pragma fragment frag
    35.  
    36. #include "UnityCG.cginc"
    37.  
    38.             struct appdata_t
    39.             {
    40.                 float4 vertex : POSITION;
    41.                 half4 color : COLOR;
    42.                 float2 tex : TEXCOORD0;
    43.             };
    44.  
    45.             struct v2f
    46.             {
    47.                 float4 vertex : POSITION;
    48.                 half4 color : COLOR;
    49.                 float2 tex : TEXCOORD0;
    50.                 float2 clipPos : TEXCOORD1;
    51.             };
    52.  
    53.             sampler2D _MainTex;
    54.             float4 _MainTex_ST;
    55.  
    56.             v2f vert(appdata_t v)
    57.             {
    58.  
    59.                 v2f o;
    60.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    61.                 o.color = v.color;
    62.                 o.tex.xy = v.tex.xy;
    63.  
    64.                 // Clip region:
    65.                 //    _MainTex_ST.xy = size of clip region
    66.                 //    _MainTex_ST.zw = clip region offset from center
    67.                 o.clipPos = v.vertex.xy * _MainTex_ST.xy + _MainTex_ST.zw;
    68.  
    69.                 return o;
    70.  
    71.             }
    72.  
    73.             half4 frag(v2f IN) : COLOR
    74.             {
    75.  
    76.                 half4 color = IN.color;
    77.  
    78.                 // Determine whether the current pixel is within the clip region.
    79.                 // If it is not, set the pixel's alpha to zero.
    80.                 float2 clipFactor = abs(IN.clipPos);
    81.                 if( max( clipFactor.x, clipFactor.y ) > 1.0 )
    82.                     color.a = 0.0;
    83.  
    84.                 return tex2D(_MainTex, IN.tex.xy) * color;
    85.  
    86.             }
    87.  
    88.             ENDCG
    89.  
    90.         }
    91.  
    92.     }
    93.  
    94. }
     
  39. Ace_1999

    Ace_1999

    Joined:
    Jun 11, 2014
    Posts:
    30
    Alright, a probably simple question: I'm trying to do a fade out over a set number of seconds (non-looping) effect.

    Currently this shader has some pulsing lights but I'm also wanting to have it completely fade out or turn off the glow map after a set number of seconds.
     
  40. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    For this, you need to use C# to control when to start the fade, using material.SetFloat("_MyValue", 0f), and similar
     
  41. tcn5150

    tcn5150

    Joined:
    Dec 1, 2012
    Posts:
    15
    Hey guys,

    Is SF compatible with Unity 5.0.2f1? Every time I try to recompile a shader (or press "return to menu") I get:

    NullReferenceException: Object reference not set to an instance of an object
    ShaderForge.SFN_Tex2d.SerializeSpecialData ()
    ShaderForge.SF_Node.Serialize (Boolean skipExternalLinks, Boolean useSuffixPrefix)
    ShaderForge.SF_EditorNodeView.GetNodeDataSerialized ()
    ShaderForge.SF_Evaluator.SaveShaderAsset ()
    ShaderForge.SF_Evaluator.Evaluate ()
    ShaderForge.SF_Editor.DrawPreviewPanel (Rect r)
    ShaderForge.SF_Editor.OnGUI ()
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

    This happens even with the example shaders as well - no changes are saved. Yes, this happens only (so far as I've noticed) when there's a Texture2D node in the graph.
     
  42. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    That seems rather serious. Strange that it doesn't happen in 5.0.1 - I'll have to look into this as soon as I can
     
  43. tcn5150

    tcn5150

    Joined:
    Dec 1, 2012
    Posts:
    15
    I'm actually getting the same error in Unity 5.0.1f1. Just by importing SF, and attempting to compile one of the included shaders with a Texture2D node.
     
  44. chasepettit

    chasepettit

    Joined:
    Oct 23, 2012
    Posts:
    42
    Anyone happen to know if it's possible to create a shader that renders properly in a uGUI canvas? Just starting from the 2D preset, I can get something that will appear when the Canvas is in "Screen Space - Camera" mode, but its draw order is always behind all other UI elements. In "Screen Space - Overlay" mode, there's nothing visible at all.

    EDIT: Appears to be a LightMode or rendering path issue. Modifying the shader code to remove the LightMode tag or set it to "Always" seems to fix the issue...as long as I don't need anything lit, I suppose.
     
    Last edited: Jun 9, 2015
  45. gfunk

    gfunk

    Joined:
    Mar 17, 2015
    Posts:
    23
    Is it possible to disable shadows per shader rather than per object?
     
  46. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    This has now been fixed in 1.16, which is releasing soon. Currently struggling with 5.1 changes :)
     
  47. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    1.16 is now out, it has some crucial fixes for issues caused by 1.15!
    • Fixed a bug where the noise node and the rotator node would sometimes spawn an invulnerable UV coordinate node
    • Fixed a bug where some shaders using Texture nodes didn't load
    • Fixed a warning when using Tessellation
    • Adapted to Unity 5.1 changes
     
  48. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    523
    Hey @Acegikmo I'm wondering if you had any info on this issue with SSAO and forward rendered alpha clip shaders. Please forgive my unrelenting persistence.
     
  49. Monkee

    Monkee

    Joined:
    Sep 3, 2012
    Posts:
    8
    Hi guys,

    Just a quick question, im working on an iOS/Android title, with each update of shader forge, do I need to go through each shader and recompile them? I noticed I had to do this moving from Unity 4 to 5 as was having issues with fog, but is this required every time SF is updated? Cheers
     
  50. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,228
    It's a tricky problem that may not have a solution, but, I'll look into it!

    If you make a major transition, as from 4.x to 5.x, then yes, definitely.
    For minor transitions, I recommend recompiling them, but it's usually not required
     
    djweinbaum likes this.