Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Shader Forge - A visual, node-based shader editor

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

  1. Mr_Dan_O

    Mr_Dan_O

    Joined:
    Oct 12, 2013
    Posts:
    347
    There is an other problem, I can't update shader parameters in play mode (for example when I change a color) But when I'm not in play mode, everything works. Do you know what is wrong?.
     
  2. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Why are you on v1.22? If possible, I'd update to get all of the bug fixes.

    Do you have any assets that override the default Unity cginc files? Basically, does that happen with a blank project with just SF and textures imported? Just because the sphere is invisible doesn't mean the shader crashed - it'd actually be purple if the shader code was messed up. What does the alpha channel in that texture look like?

    That's play mode. Shader recompilation is not a stable runtime Unity feature yet. Do you mean the material properties aren't able to be changed? Because that would be a severe issue.

    You just saved me a ton of time today. Thank you!
     
  3. Mr_Dan_O

    Mr_Dan_O

    Joined:
    Oct 12, 2013
    Posts:
    347
    Thanks for helping, I am answering your questions one by one now:

    Yeah actually I meant it just doesn't work as expected
    This is what the alpha channel looks like:
    Yes even in a new project (tested with deffered rendering path and linear color space) that happened :| Look at the image below.
    UPDATE: Weirdly when I refreshed the texture, marked its alpha channel as transparency and reopened the shader in the editor, it is showing me the transparency and the problem got fixed!!.
    I want to do so for my main project to see if the problem get fixed or not.

    UPDATE: I did it and now it seems that problem fixed, but I think there is an other problem. Look at this:
    What is wrong with it now... uh man.

    Exactly, I meant the material properties. Yes it is a very bad issue which I have no idea why that happened.
     
  4. Mr_Dan_O

    Mr_Dan_O

    Joined:
    Oct 12, 2013
    Posts:
    347
    When I used the shader and the 3d model in a new project, the problem is still exist:
    here is the shader on two boxes:
    but when I use an other shader for the objects the are behind the front object, this is what it looks like:
    And here is the same setup for the boxes:
     
  5. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    just wondering... does distancing them fix the Blending?
     
  6. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,202
    I want to gaussian blur a texture in Shaderforge.
    Does anyone know how this is possible?
     
  7. Mr_Dan_O

    Mr_Dan_O

    Joined:
    Oct 12, 2013
    Posts:
    347
    No, unfortunately. But I think I find a temporary solution, if I connect the alpha channel to "Opacity Clip" instead of "Opacity" the problem gets solved. But obviously I can't use alpha blending. Which is fine. Here is a screenshot of the car with the shader, As you can see, with the opacity clip it works fine. There are problems with shadow and lightening for the windshield,though. I hope I'll fix them.

    (The terrain was made by RTP Relief pack)​
     
    Last edited: Jul 12, 2016
  8. Mr_Dan_O

    Mr_Dan_O

    Joined:
    Oct 12, 2013
    Posts:
    347
    Maybe this helps?.

    You might use the technique in the video for the shader you want.
     
  9. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,202
    Thanks very much.
    It looks a little too complicated, I hoped there was a simpler solution.
     
  10. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Hi guys.

    So, I have FINALLY finished at college and have been spending the last few days in Unity (feels so nice to just work on this), and have come across a bug.

    While working on some community shaders which look amazing I might add (more on that in the next few days), I came across a problem.

    My shader is making areas far too dark, to the point where bricks normally visible are just...well...black.

    The first image is with the standard shader, and the second with a custom one, the custom has been attached.

    The "painted" areas are also supposed to be specular and the brick be matte, but it isn't.

    shaderstandard.png
    shadercustom.png
     

    Attached Files:

  11. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    577
    Well thats pretty much what all blur shaders do. Although if you don't want to create a noodle of nodes, you can just duplicate the plane and duplicate a simple blur material and stack them on top of each other. That will blur the already blurred image over it and it won't look glitchy.

     
  12. Wartortle

    Wartortle

    Joined:
    May 21, 2015
    Posts:
    2
    ShaderForge v1.27 and Unity 5.4.0b21 and I'm seeing these errors:

    get_skinIndex is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SFN_ComponentMask'.
    See "Script Serialization" page in the Unity Manual for further details.
    UnityEditor.EditorGUIUtility:get_isProSkin()
    ShaderForge.SF_GUI:get_ProSkin()
    ShaderForge.SF_NodeConnector:get_colorEnabledDefault()
    ShaderForge.SFN_ComponentMask:.cctor()
    UnityEngine.ScriptableObject:CreateInstance(Type)
    ShaderForge.SF_EditorNodeData:CreateInstance()
    ShaderForge.SF_Editor:AddNode(SF_EditorNodeData, Boolean)
    ShaderForge.SF_Node:TryCreateNodeOfType(String)
    ShaderForge.SF_Node:Deserialize(String, List`1&)
    ShaderForge.SF_Parser:LoadFromNodeData(String, Single, String&)
    ShaderForge.SF_Parser:parseNodeDataFromShader(SF_Editor, Shader)
    ShaderForge.SF_Editor:InitializeInstance(Shader)
    ShaderForge.SF_Editor:Init(Shader)
    UnityEditor.DockArea:OnGUI()

    and

    get_skinIndex is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'SFN_Append'.
    See "Script Serialization" page in the Unity Manual for further details.
    UnityEditor.EditorGUIUtility:get_isProSkin()
    ShaderForge.SF_GUI:get_ProSkin()
    ShaderForge.SF_NodeConnector:get_colorEnabledDefault()
    ShaderForge.SFN_Append:.cctor()
    UnityEngine.ScriptableObject:CreateInstance(Type)
    ShaderForge.SF_EditorNodeData:CreateInstance()
    ShaderForge.SF_Editor:AddNode(SF_EditorNodeData, Boolean)
    ShaderForge.SF_Node:TryCreateNodeOfType(String)
    ShaderForge.SF_Node:Deserialize(String, List`1&)
    ShaderForge.SF_Parser:LoadFromNodeData(String, Single, String&)
    ShaderForge.SF_Parser:parseNodeDataFromShader(SF_Editor, Shader)
    ShaderForge.SF_Editor:InitializeInstance(Shader)
    ShaderForge.SF_Editor:Init(Shader)
    UnityEditor.DockArea:OnGUI()

    Any update on a potential fix, please?

    Thanks,
    Roc
     
  13. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279
    Hi I hope this doesn't seem like too much of a simple question. I am new to shaders and also shader forge. I am trying to alter the example refraction shader in the examples. I want to see if i can change the direction of the refraction as it seems to go to the left of the screen. do minus X the more i increase the refraction amount.

    How can i change this to be on the Y or preferably the Z axis?

    Thanks
     
  14. Mr_Dan_O

    Mr_Dan_O

    Joined:
    Oct 12, 2013
    Posts:
    347
    Well, for the glossiness problem, I've made some changes. Here you can see in the image below that the glossiness for the water pattern - which I think you meant this as "painted" - is more glossy and other parts are matte (or have less glossiness). Hope this may help.
    The shader has been attached to this message, Also there were some problem with the metallic UV and fixed it.


    @Wartortle I recommend not to use 5.4 till they release final version of it. There are problems with it and SF. Thus your logs are helpful for the ShaderForge author if you send him these feedbacks.

    As much as I know, refraction only manipulates UV (thus it is only available in X and Y direction) so you can use a Vector2 and then use very very small numbers and see the result. For making the workflow faster, Use two "Sliders" and "Append" them and then connect it to the "Refraction" input. Reminder: Use small numbers. Hope this helps.
     

    Attached Files:

    Last edited: Jul 13, 2016
  15. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279

    As much as I know, refraction is only manipulates UV (thus it is only available in X and Y direction) so you can use a Vector2 and then use very very small numbers and see the result. For making the workflow faster, Use two "Sliders" and "Append" them and then connect it to the "Refraction" input. Reminder: Use small numbers. Hope this helps.[/QUOTE]


    Thanks for the input .. will give it ago shortly. Thanks
     
  16. Mr_Dan_O

    Mr_Dan_O

    Joined:
    Oct 12, 2013
    Posts:
    347
    I'm trying to make this water drop post-effect, it is just a refraction:
    For this, I used this tutorial:
    So everything is okay: will show more updates soon.
    EDIT:
    Here is a result, yup too dense and sharp and small drops.. Will fix it.
     
    Last edited: Jul 14, 2016
  17. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,202
    Thanks. But I wanted to blur a texture2d-node and not a part of the screen.
     
  18. Mr_Dan_O

    Mr_Dan_O

    Joined:
    Oct 12, 2013
    Posts:
    347
    So here is the water drops shader - just fixed the errors, I think is okay. What do you think? I've used the flipbook technique and UVs for refraction. I'd like to know how to make a procedural drops,though.





     
    Last edited: Jul 14, 2016
  19. Wartortle

    Wartortle

    Joined:
    May 21, 2015
    Posts:
    2
    @D4N005H Thanks for the feedback but we've been using the 5.4beta (various versions of it) for a while as we needed certain features for things.
     
  20. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    The fast way to do it is to select a higher Mip level on the texture2D node. It looks very meh, but it works and is simple.
     
  21. eros-dadoli

    eros-dadoli

    Joined:
    Oct 17, 2015
    Posts:
    8
    is there a way to do things like that on shader forge?

    Here is the video from allegorithmic channel "how to use substance with unreal terrain"


    Thanks in advance :)
     
  22. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    All of a sudden all my Shader Forge shaders appear transparent in low lighting.
    What do I do now?
    screen_1920x1080_2016-07-16_14-29-48.png
     
  23. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    181
    Hey Shader Forge Forum,

    I have a tri planar shader for our ground (floating mesh islands) and we are noticing black lines and other artifacts along edges in the mesh when looking at certain angles/further distances, is there anyway to fix this?

    Cheers,
    Colton

    upload_2016-7-17_23-48-51.png
     
  24. S-Miyahon

    S-Miyahon

    Joined:
    Jun 30, 2016
    Posts:
    12
    Hi, I'm trying to make a 3D model squash and stretch only by modifying the vertex offset in Shader Forge. (Just a constant loop via sine wave.)

    You wonderful people wouldn't happen to know how or if this can be achieved?
    I tried everything I know, but alas I'm merely an artist... :(
     
  25. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    577
    You can do it easily with vector displacement maps but you'll have to experiment with it to figure out exactly how SF uses them. Simply multiplying them with the normal node might not be enough.
     
  26. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    285
    How can I get Scene Info like the Depth, to be used on Post Effects?

    I tried all these but nothing works... I can only get the "_MainTex" data.

    I expected that if I make a Texture2D called "_CameraDepthTexture" unity should assign the depth to it... but nothing givesme anything.

    If I could also get more info from the objects in scene like the UV coordinates or Normals that would be awesome to make some Image Effects.

    is it possible to get that kind of info in shaderforge?

    upload_2016-7-18_14-4-30.png

    ------------ Edit ----------

    I would like to get some of these render passes, I guess at least Depth and Normals should be obtainable, if the UV coords could be get also or other info that would be great.

     
  27. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    285

    Basically they're painting different materials right?

    One of the official tutorials does something like that with vertex color blending.

    I used pretty much the same technique to do this



    That uses the R value of the Vertex Color to blend between rocks and water, and also blends the glossiness and normal maps.

    I later took it a little further and added Vertex Color Painting with Particles, because before I was using ProBuilder to Paint.

     
  28. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    285
    Also another question, Does anyone have any idea on how to make ShaderForge compatible with Curved World ?
     
  29. eros-dadoli

    eros-dadoli

    Joined:
    Oct 17, 2015
    Posts:
    8
    Great asset!!!
    But my question is:Can i use this type of technique on a unity terrain?
     
  30. fusecore

    fusecore

    Joined:
    Oct 3, 2013
    Posts:
    16
    Hi, I'm trying to make clouds pan over my skybox material.
    What would be the best way to manipulate the View Reflection to make them appear to pan?


    My best attempt with code node


    This doesn't do the trick unfortunately.
     
    Last edited: Jul 19, 2016
  31. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Ooo, that looks VERY cool.

    Would you consider releasing the shader and script, I had all but given up trying to paint wetness with particles.
     
    daville likes this.
  32. VirtualVassal

    VirtualVassal

    Joined:
    Oct 5, 2015
    Posts:
    13
    Question to @Labyrith-Studios, and bear with me.

    I've spent about a year in Unity/Cinema 4D; one man studio, so I'm eager to cut down on my workload where I can.

    My question is in combining shaders; I have the Toony-Colors pro shaders which I really like, and I'm looking to combine those with the functionality of the default Unity Tree Shaders (which enables my trees to be affected by the wind forces).

    Would Shader Forge help at all with this? I know it's primarily used for creating new shaders, but I'm not eager to delve into the code to combine these two shaders (as a one man studio, I use Playmaker and other node-based shortcuts where I can).

    Thanks again; either way, I'll likely be picking up Shader Forge pretty soon. It looks incredible.
     
  33. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Hi Raknill, itneresting question.

    Assuming "Toony-Colors Pro" shaders were NOT created with SF (or do not have the SF data), you would most likely have to study up on ShaderLab syntax and work out exactly how they work, and do the same for the tree shaders.

    Once you have all this it shouldn't be too hard to replicate in SF, again I don't know how those shaders were set up or created so reproducing them would be something you would have to do by workout out how they worked and looking for similar solutions/setups in SF.

    If you hunt through the pages on this thread (I know there are a lot of them and it takes forever, but we have all had to do it at some point) you will find several toony shaders I remember seeing a while ago.

    If there don't suite your purpose, try "combining" them with other on the forum, for tree and other alpha nature stuff I recommend Smooth Grass (which you could combine with a toon shader from the forums).
     
  34. VirtualVassal

    VirtualVassal

    Joined:
    Oct 5, 2015
    Posts:
    13
    Thanks for the reply! I figured I might have to work out something from scratch using SF, which is probably for the best in the long run (always good to learn).

    Looking forward to messing around with the plugin soon.
     
  35. MrPaPaBear

    MrPaPaBear

    Joined:
    Apr 25, 2015
    Posts:
    3
    @Acegikmo Hey can you or someone else explain the math behind the WorldAlignedTexture Node from the Unreal Engine to me ?
     

    Attached Files:

  36. Bonsai017

    Bonsai017

    Joined:
    Oct 22, 2015
    Posts:
    3
    Has something in the SF UI changed? Updated to v1.27 and the "Open in Shader Forge" button in the Inspector has disappeared. Am i missing something? Still have to use Unity 5.3.3f due to a running project. Thanks guys.
     
  37. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    285
    Hey Sure :) was not that hard so hard to do that... I pretty much followed Unity's Documentation on this two topics How to change vertex color from a mesh and also How to detect particle collision callback

    I came up with this script (the Script needs to be on the emmiter, shuriken):

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class DetectCollision : MonoBehaviour
    6. {
    7.     public float paintForce = 0.1f;
    8.  
    9.     public ParticleSystem part;
    10.     public ParticleCollisionEvent[] collisionEvents;
    11.     void Start()
    12.     {
    13.         part = GetComponent<ParticleSystem>();
    14.         collisionEvents = new ParticleCollisionEvent[16];
    15.     }
    16.  
    17.     void OnParticleCollision(GameObject other)
    18.     {
    19.         int safeLength = part.GetSafeCollisionEventSize();
    20.         if (collisionEvents.Length < safeLength)
    21.             collisionEvents = new ParticleCollisionEvent[safeLength];
    22.  
    23.         int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents);
    24.         Rigidbody rb = other.GetComponent<Rigidbody>();
    25.         int i = 0;
    26.         while (i < numCollisionEvents)
    27.         {            
    28.             SetVertexColorClosestTo(collisionEvents[i].intersection, other);            
    29.             i++;
    30.         }
    31.     }
    32.  
    33.     int FindClosestVertex(Vector3 toThisPosition, Vector3[] fromThisVertices)
    34.     {
    35.         float distance = Mathf.Infinity;
    36.         int index = 0;
    37.         for(int i=0; i< fromThisVertices.Length; i++)
    38.         {
    39.             if(Vector3.Distance(fromThisVertices[i], toThisPosition) <distance)
    40.             {
    41.                 distance = Vector3.Distance(fromThisVertices[i], toThisPosition);
    42.                 index = i;
    43.             }
    44.         }        
    45.         return index;
    46.     }
    47.  
    48.     void SetVertexColorClosestTo(Vector3 toThisPoint, GameObject fromThisObject)
    49.     {
    50.         Mesh mesh = fromThisObject.GetComponent<MeshFilter>().mesh;
    51.         Vector3[] vertices = mesh.vertices;
    52.         int closestIndex = FindClosestVertex(toThisPoint, vertices);
    53.        
    54.         Color[] colors = new Color[vertices.Length];
    55.        
    56.         int i = 0;
    57.         while (i < vertices.Length)
    58.         {
    59.             if(closestIndex == i)
    60.             {
    61.                 colors[i] = new Color(mesh.colors[i].r + paintForce, mesh.colors[i].g + paintForce, mesh.colors[i].b + paintForce, mesh.colors[i].a);
    62.                 if (colors[i].r > 1)
    63.                 {
    64.                     colors[i] = Color.white;
    65.                 }
    66.             }
    67.             else
    68.             {
    69.                 colors[i] = mesh.colors[i];
    70.             }
    71.             i++;
    72.         }        
    73.         mesh.colors = colors;        
    74.     }
    75.  
    76.  
    77. }
    78.  
    I don't think that method is anywhere close to be optimized XD, but here's how it works.

    After reading those two doc pages, I had a way to find if each particle is colliding with "something", but I didn't know what vertex I was touching, just the object and the point of impact.

    So then I loop through all the vertices of the object and compare their distance to the point of impact (this is the part I'm sure is not optimized), and then I find the vertex Closest to the point of impact... and then just Apply the Code for changing color, basically I add some value like 0.1f to the R channel of the vertex color, and I clamp it to 1.

    But in order to do that, Look like I can't change the color to just one vertex, I have to get and set the full array... So I pretty much loop again to all vertices and change the only one I need.

    XD so... yeah I'm sure the code is NOT optimized at all since I do a lot of usless work:

    - Loop through all particles to see which one is colliding.
    - For each colliding particle I Loop through all the vertex of the model to find the closest one to the point of impact.
    - Then I loop again through all the vertices and do nothing to all except for the one I need to change.

    so for each particle I do like 100 calculations :v

    If anyone want's to optimize that and share it that would be cool :D
     
  38. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    285
    I just realized you also asked for the water shader after I hit Reply XD

    Here it is:

    sf_wetsurface_7122016.png
     
  39. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    285
    I Cleaned up a little my graph...

    sf_wetsurface_7282016.png
     
  40. Deleted User

    Deleted User

    Guest

    Maybe I was able to create the sin city color filter (but do not know if it bugged, try it yourself).






     
  41. Ravart

    Ravart

    Joined:
    Mar 9, 2011
    Posts:
    42
    I have created a shader for my sprites, but I fail to apply "Order in Layer" to the shader (so it's overdrawn by other sprites). So far google didn't give me the required solution. Hope someone can help me out! Cheers

    EDIT:
    I got it to work with an hand written shader:
    Tags {
    "RenderType"="TransparentCutout"
    "Queue" = "Transparent"
    }
    Pass{
    ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha
    }

    But something inside a shader forge shader prevents this solution to work ? What do I have to change?
     
    Last edited: Aug 1, 2016
  42. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    7,242
    Is there any way for me to download an older version of Shader Forge? I'm transitioning back to Unity 4 for a project so I need to be able to download 1.06.
     
  43. floAr

    floAr

    Joined:
    Oct 14, 2013
    Posts:
    5
  44. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,311
    Last time I tried this method I could not get the normal maps to work, no matter what I tried it would turn black. I'd love to able to make terrain shaders using Shader Forge, with normals maps that is...
     
  45. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    How to increase the size of endlessly repeating the texture of the center? As an example
     
  46. willpower

    willpower

    Joined:
    Oct 6, 2013
    Posts:
    53
    Any idea how to fix this issue with using double sided face culling and unity forward rendering pass (doesn't occur in deferred)?

    cullingIssue.png
     
  47. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Does anyone here know how to alter the refraction so only things after x distance are refracted? Trying to stop the window frame from getting refracted and looking like it's been melted...
     
  48. kdm3d

    kdm3d

    Joined:
    Jul 20, 2012
    Posts:
    15
    The way I've been fixing this is to hand edit the code afterward. Add another pass before the first with nothing in it but ColorMask 0. This will block out any front facing polys from rendering when they are occluded by the same model.
     
    willpower and IFL like this.
  49. willpower

    willpower

    Joined:
    Oct 6, 2013
    Posts:
    53
    Thanks I will give that a shot.
     
  50. Augmented_Island_Studios

    Augmented_Island_Studios

    Joined:
    Feb 16, 2012
    Posts:
    60
    The only thing I can think now is that you could use a depth blend node to control refraction, not sure if it would work as you wanted to but is the easiest thing to try.
     
unityunity