Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    It is available in the left panel. Open the lighting tab and you'll be able to set the overall Light Mode of the shader. Very important to know because it can affect your performance (PBL) or art style (unlit allows for completely custom lighting).
     
    IFL likes this.
  2. FreakForFreedom

    FreakForFreedom

    Joined:
    Jan 22, 2013
    Posts:
    156
    I think I remember seeing a shader posted here a few weeks back. You should be able to find them with the search. :)
     
  3. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    Does anyone know how to create realistic refracting water droplets on glass in Shader Forge, my attempts over the last few days have been less than effective (I sort of got there but it doesn't look right).

    I am looking for something similar to the Crysis 3 main menu background with the falling water, but more intense.


    The only place I have been able to find this for Unity is here, this is more like what I am looking for, but I want the highlights and predominance of the Crysis version where it is easier to see.
     
  4. sotec

    sotec

    Joined:
    Sep 14, 2012
    Posts:
    34
    shaderTriplanarWithRotation.png

    hi, i'm doing a triplanar material ( with the possibility to rotate (needed in my project), but i fall on a problem, the normal dir i use to make the different faces blend are in world view, and the transform node doesn't seems to work to get the object normal ... any idea on how to do a triplanar mask with the correct normal or with with another input ( a way to get the rotation of the object could be good too)
     
  5. EdwinVargasCort

    EdwinVargasCort

    Joined:
    May 4, 2015
    Posts:
    5
    Nope, no errors just Fucsia and the shader failing to show up correctly on target platform. I had to rework the shader from scratch using channel blending and removing lerp, and that seemed to fix the problem :D the shader works now!
     
    IFL likes this.
  6. azmundai

    azmundai

    Joined:
    Jun 21, 2010
    Posts:
    26
    How do I access a node, a color node in particular, in code?

    Something like :

    go.transform.Find("MO_CrystalA").GetComponent<Material>().color = c;
     
  7. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @azmundai: All the nodes you can access by name are shown as green in the node-graph. If you hover over one of these nodes it will show the "internal name" that this node uses. Usually, if you name a node "Color", the internal name is "_Color". You can access these on the material with the Get/Set methods: http://docs.unity3d.com/ScriptReference/Material.html

    For example:
    gameObject.GetComponent<Renderer>().material.SetColor("_Color", Color.red);
    gameObject.GetComponent<Renderer>().material.SetFloat("_Intensity", 1.0f);
    gameObject.GetComponent<Renderer>().material.SetTexture("_MainTex", mainTex);
     
    IFL and azmundai like this.
  8. azmundai

    azmundai

    Joined:
    Jun 21, 2010
    Posts:
    26
  9. Mekoid

    Mekoid

    Joined:
    Oct 20, 2014
    Posts:
    1
    Hi I am new to SF.
    How can you do the "screen space distortion", like the heat distortion around the fire?
    Can anyone show me how?
    Thanks, BTW, is there a forum for asking this kind of questions?
     
    Last edited: May 7, 2015
  10. FreakForFreedom

    FreakForFreedom

    Joined:
    Jan 22, 2013
    Posts:
    156
    That's quite simple actually, just look at the shader forge example scene (there you will see a glass refraction shader) :)
     
  11. Bvel

    Bvel

    Joined:
    Feb 25, 2013
    Posts:
    37
    I'm hoping someone here may be able to help me. I really just want the standard shader but with a color input that affects only part of the object.

    So I've had a go but it's not right.

     
  12. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    @Mr-Brett
    I don't get a shading difference with the metallic smoothnes workflow. So if we are lucky this might be only in the specular workflow.
    To iron out any mistakes:
    Are you sure you are using the Standard Specular shader on the right furniture?
     
  13. Bvel

    Bvel

    Joined:
    Feb 25, 2013
    Posts:
    37
    Yeah it's a spec shader:
     
  14. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    One thing I noticed - you should multiply that Diff RGB by the gray color, and the Occlusion by 0.75, like the Standard material has.
     
  15. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @Mr-Brett: Sounds like you want a color mask, take a look at this: http://i.imgur.com/V0SnwMr.png

    Basically you multiply your greyscale texture by the color to create a fully tinted texture, then use lerp with that coloured texture and your greyscale texture using the textures mask (diff.A) to control the lerp.

    You can remove the three commented nodes on the right and replace them with a single Texture2D node, I just didn't have a greyscale RGBA texture laying around to use, so I appended a few different textures offscreen to make one. If it causes too much confusion I'll make a clearer image for you! :)
     
    syntystudios and Marco-Sperling like this.
  16. Bvel

    Bvel

    Joined:
    Feb 25, 2013
    Posts:
    37
    Thanks guys!
    That's pretty much solved the too brightness and color issues. I'd just about got the color tinting working but this method has better results and is a lot more elegant.
     
    DMeville likes this.
  17. AkiLap

    AkiLap

    Joined:
    Sep 14, 2014
    Posts:
    24
    I'm making a scene with star system, and got my second SF shader somewhat working :)

    How would I improve this shader to produce multiple rings?
    possibly with some set distances between each other.

    This is the shader, it produces the ring on a single quad in scene:
     
  18. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
  19. AkiLap

    AkiLap

    Joined:
    Sep 14, 2014
    Posts:
    24
    DMeville likes this.
  20. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Am I the only one that is being confronted with
    "WARNING: Shader Unsupported: 'Custom/02shader' - All passes removed"
    when trying to run Shader Forge shaders on iOS?
    This happens to me with Shader Forge 1.13, Unity 5.0.1p2 and Xcode 6.3.1.
    It does work when I check "iOS Metal" in Shader Forge, but without it, the error message will show up and the material will be rendered black. Does that mean only iOS devices that support Metal will be able to render Shader Forge materials?
     
    Last edited: May 8, 2015
  21. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    That's a platform issue - not directly SF's fault other than that it doesn't do the thousands of checks/optimizations to ensure every earmarked specialty case. You can open the compiled shader to check the instruction counts (there is a limit on iOS iirc). You can also check the supported GLSL commands to ensure that everything you're doing fits within what the hardware can handle. And most importantly, if you're not targeting Metal, you should see how much of the fragment you can move over to the vertex shader while maintaining acceptable visual quality.
     
  22. jermaineatl

    jermaineatl

    Joined:
    May 4, 2014
    Posts:
    9
    Hey guys,
    I generally do modeling, Im very new to shaders and i was interested in trying to replicate this shader. I've gotten a grasp of figuring out some of the colors can controlled by post. But i was wondering how to setup the shader in sf to have the rim lighting effect. Hard shadows and the banding effect based off of the normals and im assuming the gloss is faking the specularity?
    Anyways any help would greatly be appreciated.
     
  23. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Thank you very much for your answer and the link!
    It just confuses me, because it did work a while ago. At that point I even used a normal map + a diffuse map.
    Besides the occasional hiccup on iPhone 4S, it worked pretty well.
    Now, even when I just plug in a public color to the diffuse output, it won't get rendered.
    I will take a look at the shader code to see if I can find anything strange, but I'm not really familiar with Cg.
    I guess it's either a problem that came with a recent Unity, Shader Forge or Xcode update.
    Unfortunately, I updated all of them recently. So I can't be more specific on this assumption.

    EDIT:
    Alright, I just took a look into some of the shaders and I guess the problem did show up since Shader Forge version 1.13.
    Because in the first line of working (older) shaders it says:
    // Shader created with Shader Forge v1.12
    whereas those shaders that don’t work say:
    // Shader created with Shader Forge v1.13
     
    Last edited: May 9, 2015
  24. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    When you first tested the shader was it with unity 4 or 5? (As in, was Shader Forge the only thing you updated that broke the shader on iOS?)
    If the change-log is as thorough as I think it is, there shouldn't have been a change due to SF. I've been wrong a couple of times before though. :)
     
  25. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    The shaders that don't work were created in Unity 5 and the older shaders that were created in Shader Forge 1.12 survived the Unity 4 to 5 update without anything strange going on.
    Also, the problem occurs even if I create a completely new project and import a fresh copy of Shader Forge from the Asset Store.
    But I did make several updates (Shader Forge to 1.13, Unity to 5.0.1p2 and Xcode to 6.3.1.).
    It might be an Xcode problem, too. On the other hand, the shaders that I made in SF 1.12 still work nicely. :confused:

    EDIT:
    Maybe I should also point out that after importing Shader Forge, Unity tells me this:
    "API Update Required
    This project contains scripts and/or assemblies that use obsolete APIs."

    Then, when I click "No Thanks", the following warnings will appear in the console (I cannot jump into a script by double clicking on the warnings):

    "Assembly: 'Assets/ShaderForge/Editor/ShaderForge.dll' uses obsolete Unity API (UnityUpgradable)"

    "MaterialEditor: Could not create custom UI from the CustomEditor: '' of the shader. Does the class name include its namespace? And does the class either derive from ShaderGUI or MaterialEditor?
    UnityEditor.AssetPreviewUpdater:CreatePreviewForAsset(Object, Object[], String)"


    I'm not sure if I had to update Shader Forge 1.12 API, too, because at that point I updated the whole project I was working on.
     
    Last edited: May 10, 2015
  26. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
  27. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    @Shushustorm
    You could try deleting SF completely from your project. Close Unity. Restart Unity. Reimport the newest version of SF. Close Unity. Restart Untiy. Just to be absolutely on the safe side that you are running a version with all new files.

    @Vladnes
    Link, video or picture of the desired effect? I won't Google it for you ;)
     
  28. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    Sorry, added a link
     
  29. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    I think he's talking about premultiplied alpha blending. If you look at the following gif it illustrates what he talks about. Setting the Alpha contribution to zero results in an additive blended texture which means the more black the alpha the more additive it gets. The more white the alpha the more it resembles classic alpha blending.

    Shawn Hargreaves talks about it here:
    http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx



    Edit: That AlphaContrib node should have gone into the RGB multiplication, too.
     

    Attached Files:

    Last edited: May 10, 2015
  30. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Well, I did already:
    "create a completely new project and import a fresh copy of Shader Forge from the Asset Store [1.13]."
    I assume that should even be more stable than reimporting SF into an existing project, shouldn't it?
    In that new project I just created a very simple shader and the same problem occurred while running on iOS.
    Maybe I will post some screenshots of the node setups and the actual graphics on the device.
    On the other hand, it's quite unimpressive. It's just a color into the diffuse channel and the object using the shader will render black on the device.
     
    Last edited: May 10, 2015
  31. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Sorry, must have missed that line. Yeah, time for Ace to chime in I guess.
     
  32. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Alright then, thanks for your answer though!

    Here is a comparison between what is being displayed in the editor game tab (left) and on iOS (right):
    screens.PNG

    Also, I attached some more images showing what I used.
     

    Attached Files:

    Last edited: May 11, 2015
  33. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    Thanks, what we need!
     
  34. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Hey guys, I have a question that I *think* is related to shaders..

    I'm trying to render one of my objects with an outline to a transparent render texture (such that the object is rendered and the "background" is transparent), and show that render texture on a uGUI Raw Image component.

    Object in scene view: http://i.imgur.com/Sm6sQjM.png
    Render Texture RGBA channels: http://i.imgur.com/WMas37e.gif
    Render Texture on uGUI Raw Image: http://i.imgur.com/miPwxVw.png

    It's nearly working, but my outline isn't showing up! It looks like the Alpha channel of the render texture isn't being written to by the outline mesh - is there maybe something I need to set in the shader to tell the renderer to write this data too? Or some other way I can achieve this?

    Edit: I figured out how to get it working how I wanted after a fair bit of tinkering (and reading up shaderlab) It was a mixture of a few things. First I turned the ColorMask to RGB on the forward pass in the shader, and turned the ColorMask to RGBA on the outline pass. I also changed the render texture camera Background Color alpha from 0 to 1. This now gave me the proper outline on the A channel, but it was inverted so a simple 1 - tex.a did the trick. Huzzah!

    Edit #2: Looking at the shader code again this morning after some much needed sleep. The final line of the outline pass was
    Code (CSharp):
    1. return fixed4(_OutlineColor.rgb, 0);
    Changing that 0 to 1 is all I needed to do. I feel silly now.
     
    Last edited: May 13, 2015
    IFL likes this.
  35. P1st3ll1

    P1st3ll1

    Joined:
    Dec 13, 2012
    Posts:
    69
    Can someone help me with that please?
     
  36. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Well, anisotropic direction maps are going out of fashion. I recommend using anisotropic gloss maps instead, which is a bit more PBR-pipeline-friendly, and easier to implement in your case as well :)
     
  37. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It works just the same as regular gloss map, except that you have one channel for the U direction, and one channel for the V direction, which is quite straightforward in your case
     
  38. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
    @Acegikmo

    As I understand - you working on the new version shader forge? Shader forge forks fine, but have many limitation compare to ue4 materials as example.

    Two question:
    1) How i make this on the nodes: v = v.vertex.x
    2) _Time.w this is Time*3?

    Thanks in advanced.
     
  39. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Can you elaborate on what the problem is? Also, depending on your approach, switching to edge-length-based tessellation might be easier to control.

    1: I don't think you can set a struct like that. What are you trying to do?
    2: Yes
     
  40. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Well you got me curious there Ace :D I thought glossmaps were supposed to be simply greyscale textures. How would you give anisotropy to glossmaps ?
     
    SpyChar and DMeville like this.
  41. jjason08

    jjason08

    Joined:
    May 13, 2015
    Posts:
    15
    hello,
    I have been using SF for a while and have hit a bit of a wall. I am trying to make a shader that fades with a slider, so I can later do it programmatic) I would like the shader to fade from one color to nothing(transparent), then to another color, then nothing then to a third color. Below is an image that describes the effect I would like to do. At the moment I have a shader switching colors, but not fading in transparency. Any advice or help would be greatly appreciated.


    The white in the image below is suppose to be transparent.
     

    Attached Files:

  42. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Like this....?
    SF_jjason08.jpg
     
    DMeville likes this.
  43. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    about custom lighting any idea how make shader like ori
     
  44. jjason08

    jjason08

    Joined:
    May 13, 2015
    Posts:
    15
    That is very close and a good Jumping off point, however it doesn't seem to behave like I was envisioning. I remade the shader you created and it did the something a little different below with the "yellow" channel. What I was thinking was to fade from one color to nothing to another color.
    The second image I have posted was a shader I created using lerp to just change from one color to another, but they are stark and drastic changes no fade. "I know the nodes are a little sloppy forgive me"


    Also IFL, I am very interested in talking with you more and perhaps learning more how you have become so talented with creating shaders. I am new but I love creating and I dont really have anyone as a mentor. If possible and your interested Id like to learn from you.
     

    Attached Files:

  45. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Is this any help? I'm not sure what effect you're going for so I'm just guessing.
    SF_jjason08_02.jpg

    Feel free to PM me if you want. I'm a noob compared to most of these guys. If you have specific problems setting up node graphs, this thread is your best bet (after the wiki and node list). There's usually always help to be had if you explain your problem (type of shader, what you want it to do, target platform(s), references, etc) and where you're currently at. If you want to learn shader techniques then there's GPU Gems, the CG Tutorial, the Unity CG Wiki-book, some of the Valve publications, and a slew of results if you search Google for whichever CG shader you're wanting to learn about. The Unreal node graphs are also fairly transferable to SF. Keep in mind that Shader Forge, despite all of it's magical awesomeness, doesn't do multi-pass without editing the code by hand.
     
    Last edited: May 15, 2015
  46. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    You mean the glow?
     
  47. P1st3ll1

    P1st3ll1

    Joined:
    Dec 13, 2012
    Posts:
    69
    Actually I just want a smooth transition between tesselated and normal mesh, which I'm not getting with this. And When I switch to edge-length-based tesselation, the shader goes black. =/
     
  48. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    somethink's like that's yes
     
  49. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
  50. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Please Help.
    The right object in the scene below, is a road with a standard Unity3D shader for it, The left object is a road with a shader that was provided by ShaderForge:

    You can see that the reflection of the standard unity3D shader is way realistic than the one that Shader Firge 1.3 made. Notice both of them have normal and specular maps.

    Is there anyway to add that realistic reflection of the standard shader to the Shader Forge's one?

    And how would I tweak the strength of the Normal and Specular maps of a material in Shader Forge v1.3?