Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. snowcult

    snowcult

    Joined:
    Feb 6, 2014
    Posts:
    295
    How would someone go about creating something like this?

     
  2. NapalmRain

    NapalmRain

    Joined:
    Mar 3, 2013
    Posts:
    29
    I think you should look at it
     
  3. sundance

    sundance

    Joined:
    Mar 19, 2014
    Posts:
    52
    Looks like a simple triplanar.
     
  4. Sinaz20

    Sinaz20

    Joined:
    Nov 16, 2009
    Posts:
    53
    I need a little clarity on how the refraction node works and what it expects as an input. I studied the example asset, but I couldn't really make heads or tails of how the normal mapping was actually affecting the refraction and how to dissect the shader so I could customize it to my needs.

    I can't even figure out how to realize a simple refractive volume... like, if I just take a sphere and want it to create a simple clear glass refraction effect based on the mesh's actual normals and maybe a refraction index slider... can anyone give me a little direction?

    Much appreciated.
     
  5. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @Sinaz20: It took me a bit to understand how refraction works, but maybe this gif and screenshot will help:

    http://i.imgur.com/m1accAn.png
    GIF: http://i.imgur.com/63C7xHp.webm

    I'm using the SF_Noise texture, with the checkbox on the texture inspector "create normals from greyscale".
    The Refraction input takes a Vec2 to tell the shader how to distort the image. Where (0,0 is no distortion). It's important to note refraction still happens when Alpha is 0, if you don't want refraction to happen in areas where alpha is 0, make sure you change the Vec2 accordingly. (like in my example lerping with the "Alpha" texture)

    Hope that helps!
     
    The_Least likes this.
  6. Sinaz20

    Sinaz20

    Joined:
    Nov 16, 2009
    Posts:
    53
    @DMeville Thanks, that does kinda help. I figured out that the vector2 seems to represent the strength of a 2D offset in screen coordinates, but I can't figure out how to transform it to the tangent of an object's surface. I'd like to try to build a basic refractive shader that does not rely on an input texture to generate the surface normals.

    ...how can I make an object approximate a lens?
     
  7. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Hey everyone, apologies for not following this thread closely these last few weeks :(
    I appreciate the amount of people helping each other out here, so thanks a bunch for that as well!

    As some have already mentioned, I've got a ton of work to do preparing for GDC, so it has been hard to keep up with everything, especially Unity 5 support in SF since it's changing with every update. That said, Shader Forge 1.05 is now out, which makes PBL shaders work in Unity 5 RC3, and it also fixes that dithering bug!

    Not sure what you mean by #1, you can't modify mesh data and apply it. If you want to throw in absolute positions rather than a relative offset, it's possible by using the transform node and the world position node. I can't remember the setup exactly though.
    As for #2, this has been fixed in 1.05, as mentioned above :)

     
    elbows and DMeville like this.
  8. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    Thanks very much for the update :)
     
  9. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Woo! Unity 5!

    I'd like to try this out (I 5R3 installed, OSX) so I've downloaded the latest SF. Is there an example of how to recreate something like the Unity 5 standard shader in SF?

    I've never played with PBL before, so I don't really know what I'm doing - but as soon as I turn on the PBL Light mode on the shader and plug a texture into diffuse I get a pink material, and a few errors:


    Code (CSharp):
    1. Shader error in 'Shader Forge/Teleporter': '_LightColor0' : redefinition at line 36 (on opengl)
    2.  
    3. Compiling Vertex program with DIRECTIONAL SHADOWS_OFF LIGHTMAP_OFF DIRLIGHTMAP_OFF DYNAMICLIGHTMAP_OFF
    4.  
    5. Shader error in 'Shader Forge/Teleporter': 'ambientOrLightmapUV' :  no such field in structure; 'xyz' :  no such field in structure; '' : unsupported construction; 'assign' :  cannot convert from 'vec3' to 'structure' at line 105 (on opengl)
    6.  
    7. Compiling Vertex program with DIRECTIONAL SHADOWS_OFF LIGHTMAP_OFF DIRLIGHTMAP_OFF DYNAMICLIGHTMAP_OFF
    8.  
    9.  
    10. Shader error in 'Shader Forge/Teleporter': 'UnityStandardGlobalIllumination' : no matching overloaded function found at line 107 (on opengl)
    11.  
    12. Compiling Vertex program with DIRECTIONAL SHADOWS_OFF LIGHTMAP_OFF DIRLIGHTMAP_OFF DYNAMICLIGHTMAP_OFF
    What did I do wrong!
     
  10. SpaceRay

    SpaceRay

    Joined:
    Feb 26, 2014
    Posts:
    455
    I have been searching for a very long time some plugin, script or shader that could paint ONLY ALL the edges of a 3D object, as I have seen and tried many of the available ones in the Asset store for highlighting, toon shader, and camera effects, BUT they do not find and paint ALL the edges of any object ONLY the outline. Also have seen many glow assets BUT they need to have a glow map, and do not know how to make a glow map.

    I have bought Shader Forge and want to know if there could be a way to make a shader that could find or detect all the edges of a 3D object and use an emission color to pain a line on all those edges of the 3D object

    I have found that there is a Wirframe Shader available BUT it will paint ALL the polygon wires and not only the edges http://forum.unity3d.com/threads/wireframe-shader-the-amazing-wireframe-shader.251143/



    As shown above the Wireframe shader does NOT work as I want it, so I wonder if there could be some possible way to make it with Shader Forge that is so powerful and versatile and can be built many things.

    I also have other more complex 3D models that are buildings and other objects, and I would like that ONLY be painted the EDGES SHAPE and not ALL the polygon wires that makes the 3D model.

    I also would like to have a glow added to that wireframe line (I have Unity Pro) so I could get something like the logo name of the game Orborun shown below

    Thanks very much for any help

     
  11. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Nothing, that's my fault :)
    Try enabling/disabling lightmapping/light probes



    The graphics card has no concept of the edges you're talking about. GPUs render geometry on a per-triangle basis, regardless of how the normals are pointing, so this is a more complex thing that one might think.
    You're going to have to do it the hard way, using CPU preprocessing or baking the edges to a texture.

    The grid you posted at the end is fairly easy to make though. You can use the worldPosition node, the frac node, the abs node, and some multiplying to make that.
     
    DMeville likes this.
  12. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    I think whenever you import something into Unity, it interprets your poly or quad models into triangles. It's not a problem with the shader, it's basically a Unity feature.
     
  13. OnePxl

    OnePxl

    Joined:
    Aug 6, 2012
    Posts:
    307
    To the renderer it's all just a bunch of connected points in 3D space. It cannot see the shape of the object, let alone correctly interpret which edges are outlines of a model or just corners in the middle of the object.

    You can't even say: "well, just render a line where each angle is more than 85 degrees", you'll still get false positive lines on the inside of your model.

    To humans it's easy to see, but for a computer: no chance.
     
    Last edited: Feb 28, 2015
  14. The_Least

    The_Least

    Joined:
    Jan 21, 2015
    Posts:
    27
    To get this look you'd need either some very fancy scripting to tag and highlight the specific edges that you want to stroke, or take the simpler approach: UV Map and paint the textures manually. Personally, I'd paint the textures.
     
  15. ryan chen

    ryan chen

    Joined:
    Jan 21, 2015
    Posts:
    7
    如何让2D失真?
    大家好!因此,如何使失真这样

     
  16. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
  17. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    So, I'm at GDC now!
    If you want to meet up, throw me a tweet @JoachimHolmer, and we can probably meet up! Other than that I'll be in the Quixel/Marmoset booth on Wed/Thu, and in the Unity booth, with Shader Forge, on Friday!
     
    zyzyx and chiapet1021 like this.
  18. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Hi, does anyone know if there's a way to get meshes with a SF shader to NOT be affected by the sun (directional light) when they are completely occluded (in the shadows and hidden from the sun)?

    This is driving me crazy. Is it a bug in the SF shaders, or is a limitation of Unity? Currently a mesh with a SF shader gets lit by the scene's directional light, even though it should not!


    Edit: Mmh. I think I have an idea about what's going on and it's not SF-related; I'll investigate tomorrow...
     
    Last edited: Mar 3, 2015
  19. Deleted User

    Deleted User

    Guest

    Unity 5 final has been released, hope that @Acegikmo update SF after GDC
     
    chiapet1021 likes this.
  20. KaylMyers

    KaylMyers

    Joined:
    Mar 28, 2013
    Posts:
    33
    Been messing with a triplanar shader here. Problem is, It projects the same texture on both the positive and negative on each axis. Is there a way to project a different texture on the positive and negative side of each axis? More of a 6 axis shader than a triplanar I guess... Attached is my tree. sf_triplanarterrain_332015.png
     
  21. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @H92: He updated it for 5R3 earlier this week, has things changed so much in the final version to break it again? My download is still going, but I hope it still works!

    @KaylMyers: I was doing something kinda of related the other day, except I wanted to have a texture on only one side of a cube (rather than all 6 but I'm sure this method could work with different textures on all 6 sides).

    If you take the Dot product between an axis ((0,1,0) = +y, (0,-1,0) = -y, etc) and the normal direction (or in your case, your first component mask node) it will return a value based on how "similar" the vectors are. You could clamp this to [0,1] and it should give you the value you're looking for. Do this 6 times for every axis direction and you should be good. I think (I haven't tested this in your case, but I'll put together something in a second, now I'm curious!)

    EDIT: HEXPLANAR SHADER! (is that a thing?)

    sf_hexplanarshader_332015.png
     
    Last edited: Mar 4, 2015
  22. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Alright, just for the record that problem was resulting from two things: first, in Unity 5 back-facing planes don't cast a shadow anymore. And second, my directional light's shadows intensity was set to 0.9 instead of 1.0. :)
     
  23. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Can you clarify?
    From my understanding the shadow collector pass would render the geometry as the light "sees" it. If what you say is true then Unity 4 and earlier versions did not cull backfaces within the shadow collector pass which would have been really expensive. So this new handling should be "a good thing".
     
  24. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Yes, the new handling is a good thing; you just need to be aware of what it entails!

    So to clarify: a poly plane facing a light (its normal pointing towards the light) will cast a shadow. A poly plane rotated with its back to a light (its normal pointing away from the light) will cast no shadow. It wasn't the case in Unity 4; poly planes were casting shadows by default, whether or not their normals were pointing toward a light.
     
  25. KaylMyers

    KaylMyers

    Joined:
    Mar 28, 2013
    Posts:
    33
    It is now! I'll throw it into my pipeline and see how it works. Thanks for your help!
     
    DMeville likes this.
  26. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Made a shader that simulates the wind weaving the grass. The weaving texture operates on the world-space UVs so the grass movement will fit the rest of the grass no matter where you put it. There is also a function that automatically freezes the bottom part of the grass, so you don't have to vertex paint or anything.

    Sorry for the low quality vid :\
     
  27. KaylMyers

    KaylMyers

    Joined:
    Mar 28, 2013
    Posts:
    33
    @DMeville Hexplaner system works great. I had to modify it a bit to use textures instead of colors, and adding world space uv projections. Also added spec, bump, and gloss. The tree is a bit of a nightmare to look at, but it works great! Thanks for your help!
     
    DMeville likes this.
  28. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,137
    Go into your mesh renderer and set "cast shadows" to "two sided."

    This one tripped me up too.
     
  29. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749

    if i said 'take my money', would you take it? ive been essentially reading white papers and allsorts to fix my grass woes, theres a very good asset for grass but it's a little tricky to get looking quite natural.. that there is absolutely superb, esp for my stylised needs.. does it scale up well?
     
  30. Deleted User

    Deleted User

    Guest

    Final version of Unity 5 is RC4, and no, all changes in SF 1.05 works also in this version, but broken lightmap warning in console is still present, so maybe we must waiting an another update.
     
    Last edited by a moderator: Mar 4, 2015
    DMeville likes this.
  31. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    I think it looks a bit wavy rather than windy :p If you scale it up on one side it kinda screws up, but scaling it uniformly will keep the flow pattern. There are two different wind modes which you can lerp with the slider, so you can have huge waves brushing the grass and small tweaks at the same time.

    Here's the prefab with the shader, textures and setup :)

    http://www.mediafire.com/download/sft08jevv7n86fq/Plant+Wind+Forge.unitypackage
     
    DeadNinja, Acegikmo, OnePxl and 3 others like this.
  32. Jebus

    Jebus

    Joined:
    Sep 17, 2011
    Posts:
    18
    Hi all,

    I'm after a way to make a billboard shader with Shader Forge. I've done some searching and it seems this question has been asked a few times, but for this particular issue nobody gets a response which is a bit strange.

    I've tried a few things but the most obvious way to me would be a view direction into a transform node, then plugged into the vertex offset slot. What am I missing here? I'm guessing it's much more complicated a problem than I think.
     
    Last edited: Mar 5, 2015
  33. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    you are a saint!
     
  34. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    @Cactus_on_Fire no lies thanks an absolute bunch for that - that kind of vegetations extremely hard to get nicely done, but that things pretty versatile, very fast! And it'd be pretty trivial to build out an environment in max or suchlike pruning and tugging the mesh around to go along with larger foliage. Cheers a ton for that. Going to run a variety of my grass/undergrowth maps through it and feel the love, interested in how versatile it can get, actually. I'd imagine you'd get more 'waving' in a windy fashion rather than undulating with diff meshes.. its given me a lot of ideas. Also i wonder if using more choppy wind textures could suggest more turbulent atmosphere

    Actually i'll probably spend some time running some of the great, and free noise library by Jester through as windmaps, could be interesting
     
  35. dranelol

    dranelol

    Joined:
    Jan 24, 2014
    Posts:
    5
    I could've sworn I've seen this here before, but I might be crazy: how would I be able to recreate a screen-space curved horizon effect like in this shader (what I'm most interested in is recreating what's seen starting at 0:46)

     
  36. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Yep, that approach can work in some cases but there are a couple of drawbacks with it (those are just the ones I met but there's probably more):

    - Drawcalls will go up of course. It's a brute-force thing and sometimes the overhead cost will be too much (which is why Unity chose to go this way by default).

    - It will lead to nasty visual artefacts with tessellation shaders (so that wasn't a solution for me).

    - Unfortunately it still doesn't get rid of light-leakage issues when two poly planes join up with a light shining behind. So you still have to create another encompassing geometry set to "Shadows Only" (less drawcalls overhead) so that the planes are properly shadowed (which was part of my problem).
     
  37. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    No probz man :) I literally just saw the triplanar shader a few posts above and came up with this.
     
  38. Deleted User

    Deleted User

    Guest

    How i can make this? There is a code or something else?

     
  39. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    This may have been asked, but how is your unity 5 implementation? Does this support unity 5s reflection probes and gi?
     
  40. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Yep, everyone here is waiting for full Unity 5.0 support in Shader Forge. Joachim (the developer) is still at GDC but he said he's going to start working on it as soon as that's over.
     
    Acegikmo and kurylo3d like this.
  41. Deleted User

    Deleted User

    Guest

    No, reflection probe and partial (i think) lightmap is ready to be use in Unity 5 final with SF 1.05:

    For get the first is sufficient to connect two sliders to specular (metallic) and gloss (smoothness)
     
    Last edited by a moderator: Mar 5, 2015
  42. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    What do u mean forget the first? forget the first what?
     
  43. Neolightl

    Neolightl

    Joined:
    Nov 26, 2014
    Posts:
    36
    Hey everyone, I've been making a game in unity 5 beta and transferred to the release candidate today.

    Most of my shaders are broken besides a triplanar shader that I made and I am getting very strange lighting in my scenes that highly differ from what I was getting in the Beta. On top of that, allot of the shaderforge shaders that I've made no longer have the Shaderforge control panel that you would use to open the node-based editor window.

    Please help me out!

     
  44. Deleted User

    Deleted User

    Guest

    The first thing i have said (reflection probe), however look this examples:

    Lightmap with 1.05:



    Metallic with reflection probe and SF 1.05:



    The unique thing that not fully working is the Lightmap, that will fixed in coming version.
     
    Last edited by a moderator: Mar 5, 2015
  45. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,137
    Ah yeah, I can see how this would be a problem. Right now I'm doing all my lighting with bakes so these factors kinda slipped my mind since my geometry is almost entirely static
     
  46. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Mmh. I'm sorry for bringing bad news but I'm afraid this could mean those shaders were corrupted. There was a bug in one of the previous versions of Shader Forge that would cause node's IDs to get messed up (duplicated). As a result Shader Forge would not recognize the shaders anymore.

    The most recent version of SF doesn't have that issue anymore, but any shader that got corrupted is irretrievable unless you fix the node ID issue manually in the shader's header (which is what I had to do).

    But it could also just mean you need to install the newest version of SF. First, delete your Shader Forge folder (but make sure to backup any shader you got in there) and then install the new version. Then cross your fingers and see if the problem persists...
     
  47. Neolightl

    Neolightl

    Joined:
    Nov 26, 2014
    Posts:
    36
    Thanks for the heads up Seith!

    What is the shader ID?
     
  48. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    You're welcome! Actually it's the node ID. Shader Forge creates a network of nodes. Each node has a number ID. And when two of the nodes get the same ID things get out of whack; the network no longer makes sense and SF can't read it.

    It is very complicated to fix manually unless you know your shader's network by heart.

    Just for the record I'm not positive this is your situation. The issue could come from something unrelated...
     
  49. RockSPb

    RockSPb

    Joined:
    Feb 6, 2015
    Posts:
    112
    There is no deffered render support in Unity 5 anymore?
     
  50. deadlycrow

    deadlycrow

    Joined:
    Feb 10, 2014
    Posts:
    166
    PLEASE make it adaptable to unity5 shading system, the standard shader really sucks and i have some amazing fake PBL shaders and they work a lot better than standard shader and the poor reflection probes, but sadly my shaders just turn bright pink in unity 5 :(