Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Shader Forge - A visual, node-based shader editor

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

  1. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    Yeah, I considered switching to this method because it's just so much easier to setup, even with the artifacts.
     
  2. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    251
    yet, another bug...whenever I copy code into a code block, a new code node block has been created. Suprise to see suddenly 10+ new codeblocks when I zoom out...
     
  3. MattyWS

    MattyWS

    Joined:
    Jan 24, 2013
    Posts:
    70
    Is there any reason for the UV Tile node scrolling from bottom to top as opposed to the normal way for sprite sheets (top to bottom)? It still scrolls from left to right, and that's correct.. But starting at the bottom and going up is just strange. :/ Is there any way to change this on my end?
     
  4. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    494
    I assume that's because by default that's how UV's work; you've probably seen the UV cord node, where it's black (0,0) in the bottom left corner and yellow (1,1) in the top right.

    The way we're used to reading/writing (top-bottom, left-right) is 'wrong' for a texture. Even if you tried to flip the Y channel of your UVs, so it would go from top to bottom, it's just be upside down.

    You could remap each row. Use the posterize node on the Y (or V, whatever) channel of a UV input and that should get you off to a start on how you'd do it.
     
    DMeville likes this.
  5. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    In Shader Forge, is it possible to create a global-UV from a shader?

    What I am trying to do, is create a shader where I can have tiling water, and a non-tiling flowmap, created from the total bounding area of the object the shader is on.

    The ultimate product of this would be the ability to tell the shader (from the editor) how to move the water using different colours as other engines do.

    Is this kind of thing doable in Shader Forge, and if so, how?
     
  6. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    Absolutely. You can use a Vector4 property, where X and Y offset, and Z and W scale. Then you can map it using world-space UVs, and have those affected by the Vector4 property.
     
  7. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    How would this be done in Shader Forge itself?
     
  8. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    Use the world position node and append the X and Z values, then scale it by whatever scale you want to use, and offset it by whatever offset you want to use, then plug it into the UV slot of your texture samplers
     
  9. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Going back to something I was doing the other day, is there any way to programatically (in shader) generate cold frosting on glass, which is heavier on the bottoms?

    I have seen this used in many things but it has always been texture-based, similar to my method shown below, but I was hoping there might be a more controllable way of doing this inside a shader.

    GlassWindows_diffuse.png
     
  10. Neolightl

    Neolightl

    Joined:
    Nov 26, 2014
    Posts:
    36
    Hey everyone, I'm currently having an issue with vertex offset and Maya. It seems like when I export my fbx file from maya, the vertex offset is crazy: the object looks like it is exploading.

    BUT

    When I export an obj from Maya, the vertex offset is less explosive - but still not working quite right. Very small values cause a big movement.

    Any ideas?

     
  11. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    It seems that after upgrading to 5.3.0f4 my custom shaders become pinky and not working anymore. Any known bug? When fix will be released? Thanks.
     
    Baldinoboy and Tonks like this.
  12. Tonks

    Tonks

    Joined:
    Jun 5, 2013
    Posts:
    9
    Broken here too, I am wondering if it's down to the change to GGX? Are the CGIncludes right for Shaderforge now?
     
    hopeful likes this.
  13. Tonks

    Tonks

    Joined:
    Jun 5, 2013
    Posts:
    9
    Solved it for me, it's missing a definition for a Gamma conversion. We know the linear/gamma conversion is * 2.2, so I defined:

    Code (CSharp):
    1. half unity_LightGammaCorrectionConsts_PIDiv4 = 2.2;
    And it compiles.

    Now, whether this function is actually supposed to be handling the gamma correction (one would assume so, given the naming) is another question, so I have potentially fixed it by sticking another bug in there...
     
    Em-de-Nem and hopeful like this.
  14. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Hello Tonks,

    where this line should be inserted? Thanks.
     
  15. Tonks

    Tonks

    Joined:
    Jun 5, 2013
    Posts:
    9
    Really, it should be defined 'globally' for the entire shader, but for now I have simply been defining it before each line that needs it (so locally, within blocks).
     
  16. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Thanks, that is beyond my knowledge. I will wait for the fix.
     
  17. Tonks

    Tonks

    Joined:
    Jun 5, 2013
    Posts:
    9
    It isn't hard, don't panic :) For example, find all references to the gamma correction..

    Code (CSharp):
    1. float specularPBL = max(0, (NdotL*visTerm*normTerm) * unity_LightGammaCorrectionConsts_PIDiv4 );
    .. and add a line before it...

    Code (CSharp):
    1. half unity_LightGammaCorrectionConsts_PIDiv4 = 2.2;
    2. float specularPBL = max(0, (NdotL*visTerm*normTerm) * unity_LightGammaCorrectionConsts_PIDiv4 );
     
    Last edited: Dec 8, 2015
  18. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Thanks, Tonks, it worked.
    I cannot decide it is a Unity bug or a SF bug.
     
  19. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    This is a known issue and will be fixed hopefully within the next two hours, otherwise in about 48 hours from now.
    It's not really a bug, it's just that Unity removed some variables that SF shaders were using :)
     
    hopeful likes this.
  20. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Thanks, good to hear that it will be fixed quickly. Shouldn't Unity notice developers on these things?
     
  21. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    That's what the beta versions are for, so either me or the community would test it beforehand!
    The problem with betas though is that things tend to change a lot, even when going from beta to release, so I tend to stay away from them.

    There's a fix planned for now in 1.26 to at least make the shaders compile. It will not match Unity's PBR shaders fully just yet though, since they've switched to GGX.
    I've got a meeting with Unity next week anyhow, they're helping out adapting SF to the new changes, which will come in an update shortly thereafter :)
     
    hopeful, Simie and Tinjaw like this.
  22. Erind

    Erind

    Joined:
    Jul 23, 2014
    Posts:
    56
  23. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    Shader Forge 1.26 is now out!
    Fixed a bug where PBR shaders didn't compile in Unity 5.3
    • Fixed a bug where TextureAsset didn't respect its Tiling & Offset parameters
    • Fixed a bug where you couldn't use the same node in tessellation and displacement at the same time
     
    Baldinoboy and Em-de-Nem like this.
  24. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,523
    Thanks for the quick fix Ace.
     
    Em-de-Nem likes this.
  25. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    251
    heey, despite the new release, I really would love to create some global functions. I tried to work around it by attaching a function to a useless input but the order of the functions seems to be important. So to call my function it must exists before the function where I call it. Any tricks on how to make global code node and use that function on several places?
     
  26. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Hi All,

    don't you know, is it possible to create fur shader with SF? Thanks.
     
  27. CleverNickname

    CleverNickname

    Joined:
    Aug 18, 2015
    Posts:
    16
    Since the last update I'm getting the error "undeclared identifier 'sceneColor'" in any shaders that use the scene color node. Any ideas? Thanks.
     
  28. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    191
    Hey All,

    I am using bill board leaves in my trees, is it possible to create a shader that will rotate the leaves to always face the camera direction? I know there is a node that will give me the view direction but i'm not sure how to turn the billboard?

    Cheers,
    Colton
     
  29. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    It's currently not possible, but I might look into something like this pretty soon.

    It's possible but hard. Fur shaders tend to rely on multi-pass shaders, which isn't possible in SF.

    That sounds bad :(
    I'll have to look into this.

    Try the billboard vertex positioning under the geometry settings
     
    Em-de-Nem and stationx like this.
  30. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Hey Ace. I'm just wondering whats next for SF ? Like what features can we expect further ?
     
  31. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    Mostly bugfixes and smaller features at this point, since I'm no longer on SF full-time.
    I may try to find a way to add basic custom node operator support, but other than that, there are no grand plans at the moment!
     
  32. alteregogi

    alteregogi

    Joined:
    Apr 13, 2015
    Posts:
    8
    Helo guys, currently i'm making a fake fog with gradient shader on sprite material, but i don't know how to change the color that generated from world position, currently disconnected my gradient node ( on lerp ), i can do the gradient color on my sprite, but it's not what i want.

    and trying with world position, i get the result like i want, but the problem is i don't know how to change the default color from world position ( the yellow and red color)
     

    Attached Files:

  33. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
  34. alteregogi

    alteregogi

    Joined:
    Apr 13, 2015
    Posts:
    8
    no problem, found my solution!
    here is my node
     

    Attached Files:

  35. LordMortis

    LordMortis

    Joined:
    Jan 25, 2014
    Posts:
    26
    I've got a shader that was working until we upgraded to 5.3.0f4 and ShaderForge 1.26 and now it's not - I put in the
    half unity_LightGammaCorrectionConsts_PIDiv4 = 2.2; fix and that gets it working in Unity, but I can't load it in Shaderforge - i get this stacktrace:

    NullReferenceException: Object reference not set to an instance of an object
    ShaderForge.SF_GUI.AllowIndieRenderTextures ()
    ShaderForge.SFN_Tex2d.RenderToTexture ()
    ShaderForge.SFN_Tex2d.OnAssignedTexture ()
    ShaderForge.SFN_Tex2d.DeserializeSpecialData (System.String key, System.String value)
    ShaderForge.SF_Node.Deserialize (System.String row, System.Collections.Generic.List`1& linkList)
    ShaderForge.SF_Parser.LoadFromNodeData (System.String data, Single version, System.String& missingNode)
    ShaderForge.SF_Parser.ParseNodeDataFromShader (ShaderForge.SF_Editor editor, UnityEngine.Shader s)
    ShaderForge.SF_Editor.InitializeInstance (UnityEngine.Shader initShader)
    ShaderForge.SF_Editor.Init (UnityEngine.Shader initShader)
    UnityEditor.ShaderForgeInspector.OnInspectorGUI ()
    UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1231)
    UnityEditor.DockArea:OnGUI()
     
  36. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    I'm unable to reproduce this, this is likely a broken installation. Try reinstalling like this:
    http://acegikmo.com/shaderforge/faq/?Q=erroronnewversion#erroronnewversion
     
  37. LordMortis

    LordMortis

    Joined:
    Jan 25, 2014
    Posts:
    26
  38. Deadlyapples

    Deadlyapples

    Joined:
    Dec 30, 2013
    Posts:
    54
    Just a few questions!

    1. Forward vs Deffered and the performance differences and shader limitations etc (which is best in your opinions)

    2. Do you think it is possible to make a game which has no textures and low poly count but is focused on the gameplay, lighting and shaders?

    3. Is it possible to use Shader Forge to create shaders that can make objects look like they are made out of different materials even if there are no actual textures involved?


    Game Concept : Very Low Poly Counts, Gameplay focused, simple visuals but advanced lighting and shading so the GPU is working more on the lighting, shadows and shaders and not the models, animations and textures etc.
     
  39. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    That's a general question that can be answered by googling, but, in short:
    Forward has superior anti-aliasing and sensibly deals with transparency, but doesn't support that many light sources.
    Deferred can support lots of light sources, sacrificing anti-aliasing and lighting diversity, and also steals quite a bit of video memory.

    Definitely. Some games like Kentucky Route Zero and Thumper pulls it off very well. Another game that I know for certain is using Shader Forge for it, is Oberon's Court :)

    Yes, though some simple textures help
     
  40. Deadlyapples

    Deadlyapples

    Joined:
    Dec 30, 2013
    Posts:
    54
    Wow those games look really nice and that Oberon's Court looks great and has 0 textures for the 3D objects! Wow! Yeah my idea is a first person adventure game with no textures because I want it to run as smooth as possible with low poly counts and no textures. Would like to focus more on the gameplay and most of the visual quality could be focused on the lighting. Also if I do expand into multiplayer at some point I want a visual / gameplay link. Think of dayz where you can be sneaky and hide in bushes but then someone just goes along and turns their settings down low and now they can see through bushes. No fun at all, so yeh that is my future plans. A game where the gameplay and graphics are linked and also locked so you cannot increase or decrease the quality of the game other than resolution and post processing effects that have no impact on potential gameplay.
     
  41. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    191
    Thanks Ace, Not sure whats happening but when I toggle the shader between world space and billboard this is what happens. Do any other specific settings need to be set for this to work? Also do I still need to plug into the vertex offset?

    World Space vertex positioning:
    upload_2015-12-11_10-35-30.png

    Billboard:
    upload_2015-12-11_10-36-47.png

    When you move the camera around you can see the leaves, just not green and they don't rotate to face the cam in game. If have also toggled between forward and deferred and many other settings with the same outcome.

    upload_2015-12-11_10-44-9.png

    EDIT : I see whats happening. When I zoom out in the scene view the leaves do follow the camera around they just don't stay in the correct position on the branches.

    Cheers,
    Colton
     
    Last edited: Dec 11, 2015
  42. Glenn-Anderson

    Glenn-Anderson

    Joined:
    Sep 17, 2014
    Posts:
    140
    I'm on 5.3, and I updated several shaders using the new 1.26 version. However, there are a couple that are giving me the error: "syntax error: unexpected token ','. By looking at the .shader file, it's obvious what is causing the error. It's putting the closing parenthesis in the wrong location. I can manually edit it to fix the error, but then when the shader is opened with Shader Forge, the shader is changed to have the error again. Here's a diff showing the issue:

    Shader Forge bug.png
     

    Attached Files:

  43. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    Thanks for the detailed report!
    It looks like this only happens in deferred, so if you are able to run them in forward, switch them over to forward and it should be fine.

    Edit: This has now been fixed in 1.27
     
    Last edited: Dec 11, 2015
  44. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    191
    Here is the closest thing to working I could come up with :S

    upload_2015-12-11_16-30-22.png

    My leaves float in the air, any thoughts?

    Cheers,
    Colton
     
  45. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    251
    heey hello!
    I am using the UV Rotater to rotate some textures, also normal texture.
    The issue: the normals are not rotating correctly. At some point, it looks like the normals are flipped and therefor doesn't lit correct.
    How can I fix this?
     
  46. Deadlyapples

    Deadlyapples

    Joined:
    Dec 30, 2013
    Posts:
    54
    I am trying to set up a terrain shader for well.. the terrain. I am using an asset called PolyWorld for terrain conversion and can use the material provided which is great but wondered if it was possible to make my own terrain shader in shader forge that would work. I have tried but it results in the terrain being pitch black.

    Also is there a way of stopping shaders I have made from being bright when the scene goes dark? I have set up a day and night cycle with another asset and when it goes night the terrain goes dark at the correct time and looks great but anything with a shader forge material applied is still really bring at night time! xD
     
  47. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    251
    @Acegikmo I cant speak for others, but regarding this global function feature...to me, it would already be helpful to have SF include a custom CGIN file. One could write functions over there and just use the normal code block to call for that function. Perhaps would save a lot of work and sounds to me like a small feature to add into SF. But that is me thinking loud.
     
  48. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,523
    Have been working on a new bark,leaf shader and have pretty much finished up and came out with this:



    The trees in the video are tree creator trees with just the custom shader applied. I am very happy with the bending and the shading is a lot better then the normal tree creator shader. Especially since it works at night.

    The shader uses the UV2 values to control main and secondary bending, green vertex color to control edge bending, blue vertex color multiplied by the uv2 to control tumbling(which the palm trees in the video do not have), and everything is multiplied by the red vertex color for randomized bending.



    Can not thank you enough for the Get and Set nodes Ace. Man it helps. Biggest problem is still can not link the shader to a windzone. So it is nice but will not be as easy to work with as treecreator trees.

    Also have a UV4 version of the shader which leaves the UV2 open for lightmapping. That is the other issue I am having is when I select the UV4(uv3) for a UV node the shader is broken in Dx9 mode.

    Here is a screenshot of the error:

     
    Deleted User likes this.
  49. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    This is likely because the meshes are marked and static, and batch, which will kill GPU object positioning. You can force them not to batch by disabling it in the shader settings
     
  50. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    This is pretty tricky, because you're hitting the limit for the number of interpolators in the shader. This usually means that you're using too many different features at once. There are some tricks that I could deploy to make multiple UVs use fewer interpolators. Each interpolator is a float4 value, while the UVs generally only store values in X and Y, so I could pack two UVs into a single interpolator, but this has the downside of apparently being expensive on mobile