Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Thanks! That works beautifully!

    But I also noticed another issue: apparently single-sided meshes do not cast a shadow anymore when lit from the back.

    I seem to remember (but I can't find the thread) that someone already came upon this issue and that it is the new default behavior in Unity 5.0. Is that correct? Is there no way anymore for a single-sided mesh to cast a shadow when lit from the back?
     
  2. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    I'm trying to get a "inner glow" like effect for a model - and while plugging in a fresnel node works really nicely it's not perfect. I noticed that the closer the object is to the RIGHT side of the view, the fresnel is stronger on the right side of the model, similarly for the left/top/bottom too. I think is is because of fresnel uses the view direction to calculate it.

    The fresnel looks perfect when the object is centered in the view though. So I'm wondering if there are any tricks to turning fresnel into an object inner glow, which looks the same regardless of where on the screen the object is.

    Maybe with a custom node setup to create fresnel, and manipulating the view direction node with *something*. Anyone have any ideas? :)
     
  3. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Here's an update to my force field effect with one of the minor gameplay mechanics (impossible physics ftw!).
    SF_ForceField05.gif

    I've had the same issue but never managed to fix it. I'd like to know a fix as well.
     
  4. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Ah, that looks like a bad bug. It's forcing dithering to be on for some reason, which can be turned off in the blending settings. I'll look into it!

    Try defining your own view vector, that's relative to the object position rather than the fragment position.
    dot( normalize( viewPos - objPos ), normal );
     
  5. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    And just to be thorough: @larsbertram1 's suggestion of removing the Cull Off line from the "ShadowCaster" pass also takes care of the tessellation problem which affects Shader Forge's tessellation shaders! No more back faces showing the skybox!! :)
     
  6. ng93

    ng93

    Joined:
    Aug 31, 2012
    Posts:
    40
    Hi, I know nothing about rendering/shaders so sorry if this is a stupid question. I'm using Unity 5 and am really liking the new deferred rendering, reflection probes and physically based shading. Does Shader Forge support these? Thanks
     
  7. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Preliminary support is in, meaning it's currently broken, simply because Unity 5 is a shapeshifting hydra at the moment, so I can't catch up all the time! But it's coming soon :)

    The new deferred system is not in, the PBR is mostly in, and the reflection probes should work
     
  8. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,144
    Are the edge glows procedural or baked into the vertex colours or a texture somehow? Or are you accessing the geometry shader somehow?
     
  9. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Vertex colors mixed with procedural noise (same as faces, to make some shimmer when the camera is closer to the edge fragments). I was doing all of the shader procedurally before I realized that I could use a single set of vertex colors for the white edges (0,0,0), colored sides (R, G, or B), and grey backfaces (0.334, 0.334, 0.334). Basically, it's vertex colors + color math + procedural noise.
     
  10. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    I've been working on this:



    What do I need to think about when trying to make sure I can support different scaled objects with this? It looks great with the 1 unit cube but if I apply it to anything larger, the alpha clip is scale proportionally and eventually just looks like a straight line.
     
    DMeville likes this.
  11. ng93

    ng93

    Joined:
    Aug 31, 2012
    Posts:
    40
    Thanks, regarding PBR, if I start using Shader Forge now will it be difficult to transition existing shaders to PBR once it's available?
     
  12. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,144
    As long as your scaling is uniform across xyz (so you're always scaling directly), you can just use a code node with return unity_Scale.w; in it and use that value to multiply by. That's for now, at least. When Unity 5 comes out, Shaderforge will have its own scale node that works across x, y, and z independently if you need.
     
  13. Indiefreaks

    Indiefreaks

    Joined:
    Nov 12, 2012
    Posts:
    89
    Is it possible somehow to create a Skybox procedural shader with SF as I'm not very much happy with the one provided by Unity5?

    Thanks
     
  14. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    This help?
    SF_Indiefreaks_U5bSkyShader.jpg
    Not sure about the sun - there's probably a defined variable for it though.

    For what it's worth, the scale node is already usable in U5 beta. And it's awesome for solving tons of issues.
     
    Last edited: Jan 25, 2015
  15. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    I thought this would work but it has the same problems as before, damn.
     
  16. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,144
    I'm mostly iffy on recommending stuff that uses beta software just because of the issues that can come from that, especially when it comes to production shipping.
     
  17. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    Thanks @Acegikmo, Shader Forge is awesome :)

    Only took around three days to grasp the basics and get the first version of my first, real shader up and running (not counting the mad scientist experiments). 125 textured voxels using a tilemap and the red vertex.color channel. The basic stuff still needs a bit of tweaking, some (light) toon shading effects, and a few other tilemaps for blending and normals etc.



    Some thoughts after my first few days with Shader Forge:
    • A help menu or something similar in the editor that explained the hot-key system, how to disconnect node and how to select multiple nodes would have helped a lot. Maybe there is more?
    • "Outline Width" isn't behaving like expected... I'm guessing atm that it is related to normals
    • Seems like "outline width" only wants to accept a float but you can trick it into accepting anything by connecting floats to a multiply or divide (probably works with more nodes) and then connect it to "outline width" in the main body. The next step is to replace the floats with whatever you want... maybe a value 3? Throw in some other stuff like a time modulated cos curve etc... the fun part is that it still renders an outline but it can have some really funky appearance and behavior... like exploded outline pieces that spin and bounce against the shape :D Makes me wonder if it should be able to accept other data except floats?
    • "Value4" gives you direct access to the X,Y,Z,W components while other value types doesn't. Feels a bit inconsistent and I had one or two cases when I would have loved to get direct access to inner components of other value types to clean up the graph a bit.
    • Shader Forge sometimes make Unity respond very slowly when I exit SF. Only solution so far has been to restart Unity and had to do it once from the task manager. Haven't figured out what is causing this.
    (Shader Forge v1.04 & Unity 4.5.0f6)
     
  18. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Thanks, glad you like it!

    That's in the readme.txt

    I presume you're referring to the outline splitting on hard edges - this is expected, and can somewhat be fixed if you smooth shade the entire mesh, and bake the hard edges into a normal map instead.

    A float is enough to make the effects you describe, apart from the spinning :)
    The float doesn't have to be the same value all over the mesh. Try sin( UVcoord[ U ] ) + 1 for example.
    I guess it could somewhat work like the Vertex Offset input, allowing you to define a vector. But it would be super hard to make spinning triangles!

    You can use the component mask node to access the individual channels

    No idea what would cause that I'm afraid :(
     
  19. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    :oops: But no one reads, readme files ;)

    Figured that it was something like that going on... just didn't get expected results on a pair of meshes but then I know what to do with them... time for some investigation in Blender.

    Missed that one, thanks :) Still trying to memorize all the nodes and consider all their possibilities.

    I'll let you know if I can figure something out... haven't been able to isolate the cause and reproduce it in a controlled way. Still, minor problem when I consider what SF teaches and accomplishes for me.
     
  20. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Hi guys, I'm trying to get a texture to follow my player while orienting to the player's front direction and I'm having difficulties. So far I've been able to come up with this:



    The player position is fed via a script which updates the PlayerPos Vector 4. The texture (a V-shaped ripple) follows the player without problem but I cannot manage to orient it properly.

    So in other words the CompMask is outputing valid UV data and the rotator node's result seems correct but I don't know how to combine the two. As you see I've tried with an Add or Multiply node but it doesn't work.

    Also, for a reason I don't understand I have to negate the player rotation (the W component of PlayerPos) for the rotation to make sense.

    (And in case you're wondering: the player's rotation is based on the player's localEulerAngle.y * Mathf.deg2Rad)
     
  21. davysw

    davysw

    Joined:
    Jul 15, 2014
    Posts:
    17
    Hey I need help getting PBL to work with this semi simple shader I built. Also just the shaderforge stuff in general. I am using unit 5 version 18 and here is a screenshot of what I have going on. I thought I had everything checkboxed correctly, but maybe I'm still missing stuff? Thank you! (both items are static, etc. I can't get it to work on this, but I can get it working on stuff with the unity 5 PBL shader on it)


     
  22. JohnyK

    JohnyK

    Joined:
    Jun 13, 2014
    Posts:
    13
    Hello!
    I am searching for a similar effect! I would be grateful if you could attach the full graph screenshot!

    Kind regards,
    John.
     
  23. KaylMyers

    KaylMyers

    Joined:
    Mar 28, 2013
    Posts:
    33
  24. JohnyK

    JohnyK

    Joined:
    Jun 13, 2014
    Posts:
    13
  25. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    In the shaderforge editor I often find myself adding nodes between two nodes already connected, and reconnecting the inputs/outputs.

    Like this:
    1) http://i.imgur.com/mc7M2bk.png
    2) http://i.imgur.com/J6FOwMr.png

    I've used some other graph editors that autoconnect the inputs/outputs when you add a node "in between" two others, is there any shortcuts to doing something like this in shaderforge?

    It's not a big deal, and just a small time saver but would be a cool feature maybe at some point :)
     
  26. Monkee

    Monkee

    Joined:
    Sep 3, 2012
    Posts:
    8
    Hi guys, I'm developing for iOS and just made my first shader using SF 1.04 since upgrading from 0.36.
    During the build process I am now receiving a lot of shader errors such as:

    Shader compiler: internal error compiling shader snippet type=1 platform=5 Error polling external process
    Shader compiler: internal error compiling shader snippet type=1 platform=9 Error polling external process

    The new shader I made just comes out black on the device,and has the specific error:

    Shader error in 'TestShaders/ShaderForrge/CloudShader': Internal error communicating with the shader compiler process.

    This happens with any and all targets selected mainly opengles. Even pumping in just a vec 3 into emission with everything turned off, and force opengles 2.0 selected does nothing. I have checked the build settings and cannot figure out why.

    I have searched online and found nothing of help. We are using Unity 4.5.5f1. Nothing has changed with our project other than upgrading shader forge, which I have had no problems in the past updating.

    All other shaders made previous to 1.04 work fine and compile however :/

    Is anyone else having any issues like this? Hope I can revert back to SF 0.36 and all will be well.
     
  27. davysw

    davysw

    Joined:
    Jul 15, 2014
    Posts:
    17
    I'm also having a problem getting normal maps to display on my shader, I have the textures set correctly in unity, but it's not working. using version 5.18, thanks
     
  28. AlanGreyjoy

    AlanGreyjoy

    Joined:
    Jul 25, 2014
    Posts:
    192
    How can I achieve this with shader forge? Been at it for hours now :(

     
  29. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    This might be useful to you:

    (he talks about realtime at 25 mins or so)
     
    Play_Edu likes this.
  30. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,349
    Is this pre-baked AO ? Or a shader that does it in real time ?
     
  31. AlanGreyjoy

    AlanGreyjoy

    Joined:
    Jul 25, 2014
    Posts:
    192
    The youtube video? That's some scripting and shaders. I have been that route, didn't like it.

    The picture is from a program called MagicaVoxel. It's a free and open source program. So I assume its real time.

    Got Shader Forge to see if I could do it with it... but no luck.

    I even baked AO in blender and imported into unity. What's really odd... its that in the SF material window... it looks reaking fantastic.. but looks terrible in game.
     
  32. AlanGreyjoy

    AlanGreyjoy

    Joined:
    Jul 25, 2014
    Posts:
    192
    So this is what I have... and you will see what I mean. It looks perfect in the shader forge, than it just turns to poo in game.

     
  33. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    Yeah but in MagicaVoxel can totally fake that AO(and so can you) because all of the voxels are in a regular, known positions, they're either off or on and I think the light source is in a fixed position. You could just blend a specific AO map for each visible face, depending on adjacent voxels. MagicaVoxel is open source anyway, so just go look and see what they do? It even looks like they have a path raytracer now(which is what that video I posted discusses).
     
  34. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,349

    The shader should have the vertex input, maybe ShaderForge preview takes it into account by default, but Unity does not.
     
  35. Monkee

    Monkee

    Joined:
    Sep 3, 2012
    Posts:
    8
    Yep reverted back to SF 0.36 and new shaders work on the iOS device again. Aww this is a bummer as I was looking foward to using the new float precision settings in the latest 1.04 version :(
     
  36. Monkee

    Monkee

    Joined:
    Sep 3, 2012
    Posts:
    8
    Sorry for spamming. Retried installing 1.04 after uninstalling 0.34 then restarting, reinstalling 1.04 restarting. Now it works. *scratching head.
     
  37. AlanGreyjoy

    AlanGreyjoy

    Joined:
    Jul 25, 2014
    Posts:
    192
    I don't know...

    But I am about to move back to unreal. Better in every which way... and cheaper per month. I really don't care about the 5% thing.
     
  38. nooklp

    nooklp

    Joined:
    Nov 14, 2013
    Posts:
    8
    Hello, guys, is there any possible way to rotate cubemap around the axis using nodes? Im was trying to use vector4 as DIR input of cubemap, but it doen't work...
     
  39. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    Hi, I think my brain had a meltdown so I was hoping someone could give me a push to fix the last problem.

    My triplanar shader with a tilemap is working to 99%, the only problem left is the thin line that appear between the tiles. I'm guessing that this is an error introduced by the three "frac" nodes that I use to clamp the world coordinates into a range of 0.0 -> 1.0... if I understand it right... frac will only give me 0.00001 to 0.99999999 (you get the idea)... is this correct?

    If so, is there a better way to clamp the world coordinates into a 0.0 to 1.0 range?

     
  40. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I'm not sure what the use-case of your shader is - what are you using it for? I might be able to help, but I'm lost with trying to figure out what your goal is and what your needs for the shader are.
    In the SF window, you don't have the color map set. I also don't see the AO (at all) in the scene/game view shot you posted. Also, instead of the Blend/multiply node, just use a Multiply node. Your node graph looks fine other than that.
    Unreal is a great engine, but there's not as much of a difference between UE and Unity as what most people like to suggest - you just have to know your tools and the workflow. That said, any talk unrelated to SF isn't really on topic here, especially since SF isn't even created/managed by Unity.
     
  41. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    @IFL - Not doing anything super strange... just projecting tiles onto a procedural terrain. It basically takes the red, vertex color to calculate the tile that should be used from a tilemap. It then projects that tile onto the position of the vertex in the mesh.
    I have definitely proven to myself that I got brain lag at the moment... probably because I manually filled an array earlier with 250 entries of X values... :D I did fix some small mistakes in the shader since the image and applied it to a mesh and it is working to 99%
    The only problem is that a line appear every meter where the mesh doesn't receive any texture. This is happening because I used the frac node to bring down the position value... it is kind of working but it only bring down values to a range of 0 to 0,99999999 (I think). That is why that line is appearing in the mesh every one meter... urgh... my little brain doesn't want to work with the math to do it the old way *sigh*
     
  42. Michael-Thomas

    Michael-Thomas

    Joined:
    Jul 8, 2014
    Posts:
    20
    I've been trying to work with a Shader Forge shader not so different from the vegetation shader that's included in the examples. In doing so, I've been seeing some weird artifacts where somehow the waving vegetation (in my case, grass) blocks the shadows that would otherwise be being cast behind it.

    In an effort to reduce the variables, below is a minimal case using the included example vegetation shader on each of two Quads along with a Cube and a Plane using Unity's Default-Diffuse material and a single directional light with shadows enabled (either hard or soft exhibit this). I'm using Shader Forge 1.04 and Unity 4.6.2. Of note, the artifact appears to not occur if either there is only one of the two vegetation Quads or if both are at a rotation of 0,0,0. (Note: the screenshot is taken with a version of the vegetation shader where the wind multiplier is increased from 0.016 to 0.16 to exaggerate the artifacts. This artifacts are present with the lower value, they're just harder to see in a screenshot)

    vegetation-artifacts.png

    Has anyone seen these kind of artifacts before? Is this a known bug in SF? Are there any good workarounds?

    Thanks!
     
  43. Indiefreaks

    Indiefreaks

    Joined:
    Nov 12, 2012
    Posts:
    89
    Hi guys,

    I want to make a simple skybox but I can't seem to understand which nodes I'm missing and where I should plug them so that I get it working.

    Any clues or advice where I should look ?

    thanks
     
  44. mittense

    mittense

    Joined:
    Jul 25, 2013
    Posts:
    168
    I'm using Unity 5 and wondering how I tick the little box that says "Reflection Probe Support" — it seems constantly greyed out.

    (and this gets old real fast: "
    'ambientOrLightmapUV' : no such field in structure; 'xyz' : no such field in structure; '' : unsupported construction; 'assign' : cannot convert from 'vec3' to 'structure' at line 300 (on OpenGL)")

    (Which I just comment out that line in order to get that shader to compile).
     
  45. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    On the previous page, I posted a very simple sky. It was in response to you. Guess I should tag or quote who I'm responding to. ;)
    I'll take another look at your shader tomorrow. Let me know if you figure it out before I get back to you.
     
  46. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    @IFL - Thank you, I have of course been working a lot on this myself... Triplanar with a tilemap... I know this kind of thing should be possible, EQ Landmark is after all doing it. The more I thought on it, the more I got certain that the "frac" was the problem... so I have begun to turn the positioning on its head. Instead of using frac, I have begun to rework the world position... (work in progress below). Shaders and all of this isn't a strong point of mine but I tend to be able to solve stuff with enough time :)

    The idea is to basically look into the world position and change it into a range of 0.0 - 1.0... like UV:s. I do this by checking if the current world position is an even or uneven number and then add the fraction back, modified if necessary.
    • Even - Even numbers are 0, the remaining fraction counts up toward the next, uneven number.
    • Uneven - Uneven numbers are 1, the remaining fraction counts down toward the next (ex 1-0.3), even number.
    This creates a range 0 -> 0.5 -> 1.0 -> 0.5 -> 0.0 and repeats endlessly... the distance between 0.0 and 1.0 in world space is currently 1 meter...

     
  47. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    Update: Things are looking up, the artifact of the missing texture pixels at every 1 meter is removed and the texture is tiling now.



    I cleaned up that mess of nodes by writing my own function that combined all of it into a single node. Much easier to understand as well :D... previously had paths that crossed, crossing, cross paths.... o_O

    Some texture tiles on different axises isn't completely agreeing with each other at the moment... could be my fault or could just be that it is a Triplanar shader but I had the feeling that they aligned much better in the past.

    All of this isn't optimized to 1%, my goal so far has only been to get it working which it currently seem to do :oops: This now need some serious cleaning and testing to see how it perform in real, procedural mesh scenarios but I wouldn't have gotten this far without Shader Forge and previous posts with similar shader graphs.
     
    IFL likes this.
  48. chrissanders

    chrissanders

    Joined:
    May 24, 2013
    Posts:
    106
    I cant wait to get my hands on this.
     
    IFL likes this.
  49. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    You're awesome. I'm sure you already know this, but fully optimizing the shader means taking it out of SF entirely. Let me know if you need any help with optimization.


    @Acegikmo & everyone - Is anyone else having an issue with opening the compiled source of a shader with SF in your project? I keep getting the following error when I try: (SF v1.04 & Unity5)

    TargetParameterCountException: parameters do not match signature
    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:188)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    UnityEditor.ShaderForgeInspector.OpenCompiledShader (UnityEngine.Shader s)
    UnityEditor.ShaderForgeInspector.OnInspectorGUI ()
    UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1132)
    UnityEditor.DockArea:OnGUI()

    Is there another way to open the compiled shader in the beta?
     
  50. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    @IFL - Thanks :) But I am definitely not great at shaders... this is the start of my first, serious home-cooked shader and I borrowed some ideas and solutions from previous posts, analyzed and finally merged it all with my own work on top.

    Why should I optimize the shader outside of Shader Forge? Is there something I don't know about? I could of course do some work on the code myself to make sure that everything is performing optimally but I am more wondering if there is some problem that SF is introducing?

    I was at the moment thinking more on merging the three function nodes into one, maybe add a scaling factor so that it is possible to define if a tile should be 1x1m or 0.2x0.2m etc... then add the final nodes/code for tile selection that is currently missing (hacked it because my test tilemap only got a single row ;)).

    That is probably going to the final, public version that I share in the wiki.

    The final version for my game might though get a bit more complex. I am curious and want to try making my tiles into layers that can all be controlled independently... One diffuse only go color tiles... then add a black and white detail tile on top and finish it of with a true detail tile... think blue-grey tile... with a black and white tile that contains the rock layer and the final layer adds some green growth to it all. Normal maps will definitely be added and maybe a AO texture for better shadows :)

    My computer is probably going to kill me in my sleep for even attempting this :eek: