Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    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. deadlycrow

    deadlycrow

    Joined:
    Feb 10, 2014
    Posts:
    130
    anyone else is getting just a black screen doing a "Blit" trying to apply a post effect shader made in shader forge???
     
  2. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
  3. deadlycrow

    deadlycrow

    Joined:
    Feb 10, 2014
    Posts:
    130
    @DMeville it does not work :S, the shader start working but if i close unity and re open it, it is black again
     
  4. JamesThornton

    JamesThornton

    Joined:
    Jun 26, 2015
    Posts:
    51
    Can SF create the following shader (please read carefully!)

    - Base texture
    - Emission Map
    - Reveal Emission Map along an alpha gradient using _Cutoff
    - Rendered in opaque queue
    - Runs on mobile

    Examples of _Cutoff with alpha gradient:

    I only want to reveal an emission map over a base texture in this manner (along an alpha gradient). NOT a cutout shader like shown here.


    A different example of a texture being revealed along an alpha ramp using _Cutoff: (post 6) http://forum.unity3d.com/threads/health-bar-reveal-shader-with-1-drawcall-1-texture.125843/


    Thanks for any assistance!
     
  5. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    486
    You mean something like this?

    simpleshader124r1243513451.jpg

    This is just using some random textures in my project. So the caustics texture has no alpha, but it'll work using the A output instead of the R output if you have a texture that does have it.

    Something like this took about 15 seconds in all honesty, and it should work on mobile (set to easy mode BP lighting, Single Dir Light, etc). Renders like normal with the rest of the opaque geometry (SF will default to that if you don't plug any alpha input into the shader).

    If you want, some things you might want to add or change compared to mine:
    Instead of R output from Emission Gradient, use A (obviously)
    After the Step node, multiply the RGB from the Emissions Grad with the output from the step node, then you can have a coloured emission. (this is cheap, you could probably do it!)
    Instead of the step node, which will give you a solid binary 1 or 0 with the emissions and a hard edge, you can do some more advanced tricks to make a smoother blending outline transition for the emissive parts. (this is a bit more complex, and if you're after superfast shaders I wouldn't worry about it).
     
    hopeful, JamesThornton and DMeville like this.
  6. JamesThornton

    JamesThornton

    Joined:
    Jun 26, 2015
    Posts:
    51
    @Jesus That is super sweet, thanks so much for posting! I've been struggling to code this damn thing for 5 days.

    In this project, hard edge is fine, but a smooth transition could be useful later. Glad to know it's possible.

    Really appreciate that
     
  7. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    7,178
    @Acegikmo Is there a way to make the outline width take a vector3 other than cheating it? Right now I have this shader here:



    The idea is that the width of the outline never changes despite camera distance and object scale. I can get it to work by making it so that the multiply value takes two floats and then changing one of the floats to a vector3 but that seems a little cumbersome.
     
  8. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,249
    You don't need a Vector3 outline input for that though. If you only have uniformly scaled objects, use objscale.x as a scale parameter. If you want to support both, I'm pretty sure you can scale a value based on the normal direction and the scale in that direction.
     
  9. Smileys

    Smileys

    Joined:
    Feb 27, 2014
    Posts:
    32
    I have a problem with my VertexColor shader but i really dont know how to fix this.
    OSX 10.11
    Unity 5.3 (OpenGL 4.1)
     

    Attached Files:

  10. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I don't have that shader anymore, but I remember how much of a pain it was to perfect. You have to edit the shader after it's made in SF so that it includes a backface cutout pass, a cutout pass, and an alpha-blended pass. It's basically 3x the pass count, which might not be worth it depending on the project. You also have to have proper vertex-ordering so that the hair closest to the scalp is rendered (in the alpha-blended pass) before the outer hair. If you want to see a great implementation of hair in Unity5, check out Unity's version available on the Asset Store. It's a bit wonky with blonde hair, if I recall correctly, but it works well. It still has its limitations though.
     
  11. Deleted User

    Deleted User

    Guest

    I noticed that many people, have difficulty to obtain a portal system, without using evil MirrorReflection script. So I have started to work on a alternative way, and (for now) this is what that I have obtained:



    In pratice a similar result to stencil buffer, with SF shader and a few script lines for remapping UV. That seems allowed me to obtain (unexpectedly), the common portals system that I mentioned.

    If all goes according to my expectations, I will post the asset as usual :D
     
    Last edited by a moderator: Jan 22, 2016
    FreakForFreedom, hopeful and DMeville like this.
  12. deadlycrow

    deadlycrow

    Joined:
    Feb 10, 2014
    Posts:
    130
    can you affect some slider value with particle shuriken system? and how?
     
  13. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
    @deadlycrow what are you trying to do?

    You could read the vertex colours in your shader, which can be set with the colourOverLifetime and startColour on particle systems. Maybe something like that would work?
     
  14. env_warby

    env_warby

    Joined:
    Nov 22, 2013
    Posts:
    23


    Does anybody know if its possible to implement this with pbr shaders ? I really want all of my spot and pointligths specular "disc" to be wider than it is by default -_- if something is 100% smooth the specular highlight its so small its invisible.
     
  15. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Is it possible to create a 3D-esque grid effect for a face?

    I want to create something similar to the "screen space" grids in Halo 5.
    What I want to be able to do , is have a grid, and have the points where the edges meet into a point (on the grid texture)
    extend "down into" the face, so it looks like it is going infinitely down according to that faces angle.
    http://xboxdvr.com/gamer/Labyrith/video/14121459
     
  16. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,423
    Trying to simulate a scrolling LED text marquee. Can something like this be done in ShaderForge?
     
  17. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    486
    That's something I'm doing for my Utility Shaders pack. If you tell me what LED resolution (number of LEDs high by wide) I could send you a pre-release version.

    Also is this for mobile or PC? How detailed would you want this?
     
  18. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Great work with this Portal thing, any progress towards release? Looks amazing, always surprised at what this community comes up with :D
     
  19. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,423

    Wow, this is awesome.
    Platform is PC,
    Resolution is low res, 9 LED's tall by 1-200 LED's wide.
    Not sure about the detailed amount.
    email > bach44 at gmail
    Thanks again
     
  20. Deleted User

    Deleted User

    Guest

    I just now made some fixes to the uv mapping, and the system of movement for the portals cameras. The only drawback for now is this:



    In practice the camera view is more smaller than the screen resolution, when you look out from a specific range. (at least that's what I understand) :(

    Edit: I finally found a solution, the problem was related to the aspect of cameras (not equal to those of Main Camera), and CameraPos node (setted on Tiled instead that on Normalized) in the shader made by SF. Rendering now works with any resolution :)

     
    Last edited by a moderator: Feb 3, 2016
    daville and DMeville like this.
  21. Ace_1999

    Ace_1999

    Joined:
    Jun 11, 2014
    Posts:
    30
    I have a question on trying to make a render texture's UV match up with the screen space.

    Anyway the gist of it is I have a shield bubble mesh that I'm trying to make "invisible" by using a screen space shader over the bubble. What I'm trying to do is figure out how to map the render texture so for any shield bubble it matches the pixels up with the view space without the shield bubble's distortion. So it should render the shield bubble invisible.

    The reason for doing this is to have a deferred decal project onto the "invisible" render texture shield mesh for on-hit shield effects.

    Anyway is there a way to get the shield bubbles to render the render texture to map on with the regular 16:9 camera window?

    Alternatively an on-hit script that could work with a Shader Forge forward rendered shader would be a nice replacement for this convoluted render-texture shield mesh deferred decal approach.

     
  22. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    486
    LED T1.png

    OK, here we go

    Create your material, assign this shader, fill out material properties to your liking.

    IMPORTANT: the text file must be an image that is 9x256. You may have to manually disable (to nearest power of 2) in the texture import settings, and make sure the texture filtering is set to POINT, not bilinear. The texture can be black and white, grayscale, or full RGB. Alpha is not used. In the future for the USV bundles I'll probably make it comparible with 8x256 and add some more stuff, but for now...

    The LED grid display is 9x100 LEDs. It'll scroll and repeat (make sure texture is set to repeat not clamp).

    Backing Panel Color, Metallic and Roughness all do basically what they say on the lid. The holey backing plate is made in the shader, not using a texture

    You can use the color to tint. It's set to double, so for 'correct' output set it to mid gray. You can also color the text image, and it'll show up correctly.

    Pixels per second is basically scroll speed.


    If you want a 9x50 LED grid, you can easily do that by creating a plane in Maya/Blender, and only using the left half of the UVs (go into UV editor, move the right two towards the centerline).

    Also bear in mind to scale the default plane. To maintain aspect ratio for default grid, I used 1m wide by 0.09m tall.
     

    Attached Files:

    DMeville and JamesThornton like this.
  23. Qiang

    Qiang

    Joined:
    Feb 9, 2015
    Posts:
    7
    I just want to know, Why didn't you just create a help page of left pannel of ShaderForge. Just like how to use Blend Mode, Stencil Buffer, Auto Sort, and so on. I Wonder the reason, do you just want to intentionally increase the difficulty of study?
     
  24. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
    @Qiang SF is a big project, and while things like that would be helpful, they also take time to make - time that arguably would be better spent improving SF, adding features, etc. That's why there's forums where you can ask questions and other Shaderforge users can try and help! :)
     
  25. Eric-Chadwick

    Eric-Chadwick

    Joined:
    Mar 26, 2012
    Posts:
    20
    Is there a way to have the emissive ingredient in a Shader Forge shader emit light into an Enlighten lightmap? I am baking GI non-directional lightmaps.

    Can the emissive strength for lightmapping be different from the emissive surface contribution? Just so the mesh surface doesn't get blown out.

    Thanks!
     
  26. lolgc

    lolgc

    Joined:
    Feb 7, 2014
    Posts:
    1
    Hi
    I just want to ask two questions, which might have already been asked and solved during the last 100 pages:

    How do I fix the coloring of the diffuse texture in a way that it matches the coloring/shading of the Unity standard Shader?



    The left cube is made with the Unity Standard Shader, and the darker right one is based on a simple diffuse shader created in Shaderforge. For some reason, the SF generated shaders are always darker. I want it be the same color as the Unity Standard Shader (for obvious reasons^^).

    The second thing is related to the depth blend. Coming from the Unreal Engine, the effect of the depth fade node inside the Material Editor of UE seems to be totally different:
    I use it as the Alpha Value for the Lerp Operator. The idea is to get foam working. I also need depth fade working for my other shaders.

    So I would be very greatful, if someone could help me out :D
     
    Chaosgod_Esper likes this.
  27. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    486
    lolgc

    Are you using the Shader Forge default Standard (PBR) shader? Or is that a legacy style shader.

    The other thing to check is that you've got the same (or rough-ish) values for the material. I think by default the values are different to what the Unity Standard shader materials 'pre-load' with.
     
  28. Poopenheimer

    Poopenheimer

    Joined:
    Jul 22, 2015
    Posts:
    4
    Hi,

    I've been interested in Shader Forge for awhile and have been on the fence on whether to get it. I decided that I want to give it a try, but I do have a few questions before clicking "Checkout" if that's ok :)

    Are the properties/nodes like the texture input accessible through script? For example: If I were to generate a perlin noise texture during runtime, could I plug it into a node to achieve a blend of textures? Here's a video reference to show what I mean -
    . I'd also like to apply the previous question to existing nodes with parameters, using the perlin noise as an example, if a texture is already plugged in, could the variables like the frequency of the perlin noise be changed at runtime through script?

    Thanks for all the help, it is a beautiful asset package!

    -Amos
     
  29. Qiang

    Qiang

    Joined:
    Feb 9, 2015
    Posts:
    7

    At least you have to add some tooptips for properties.
     
  30. fengshuifever

    fengshuifever

    Joined:
    Nov 28, 2013
    Posts:
    15
    A REALLY silly question but is the Component Mask the same as the Detail Mask within Unity's standard shader?
     
  31. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,249
    You can use it as such if you define it to be used that way in the shader, but component mask is more general purpose, and is used for a lot of things
     
  32. Ravrav

    Ravrav

    Joined:
    Aug 10, 2013
    Posts:
    4
    hi.
    is there a way to use a normal map with billboard particles? the unity standard shader (cutout) does not work properly either in this case, but maybe there is something you can do to fix this within shader forge.
    thanks in advance.
     
  33. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    507
    Hi,

    Thanks for this amazing - must have - asset.

    I would like to know how can I import old shader into shader forge like this one :

    Code (CSharp):
    1. Shader "appadvisory/curvedShader" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    5.     }
    6.     SubShader {
    7.         Tags { "RenderType"="Opaque" }
    8.         LOD 200
    9.         Cull Off
    10.    
    11.         CGPROGRAM
    12.         #pragma surface surf Lambert vertex:vert
    13.  
    14.         fixed4 _Color;
    15.         sampler2D _MainTex;
    16.  
    17.         half _Bend;
    18.         half _BendFreq;
    19.         float _ZOffset;
    20.         float4 _CameraOffset;
    21.  
    22.         struct Input {
    23.             float2 uv_MainTex;
    24.         };
    25.  
    26.         half2 CalcOffset(float zPos)
    27.         {
    28.             // sum up some sine waves to create a wiggly tunnel shape
    29.             half z = 0.01 * _BendFreq * (zPos + _ZOffset);
    30.             half4 sins = sin(z * half4(1.0, 1.77, 0.57, 0.31));
    31.             half xOffset = (1.0 + sins.z * (sins.x * sins.y)) - (sins.x * sins.z) + sins.w;
    32.             half yOffset = (sins.z * sins.y) - (sins.x * sins.w);
    33.             return _Bend * half2(xOffset, yOffset);
    34.         }
    35.  
    36.         void vert (inout appdata_full v)
    37.         {
    38.             // offset the world space positions of the vertices
    39.             float4 worldP = mul(_Object2World, v.vertex);
    40.             worldP.xy += CalcOffset(worldP.z) - _CameraOffset.xy;
    41.             v.vertex = mul(_World2Object, worldP);
    42.         }
    43.  
    44.         void surf (Input IN, inout SurfaceOutput o)
    45.         {
    46.             // Albedo comes from a texture tinted by color
    47.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    48.             o.Albedo = c.rgb;
    49.         }
    50.         ENDCG
    51.     }
    52. }
    53.  
    Thanks a lot for your help.

    Best regards,

    AB
     
  34. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    728
    Hello, is there a way to get the front direction of a mesh in Shader Forge? I looked at all the Geometry Data nodes and there's everything from world position to scale, normals, etc... but I can't see anything related to the orientation of the mesh/transform.

    Edit: Oh, it looks like it works if I just use a Vector3 node with 0, 0, 1 (seems to default to object space).
     
    Last edited: Feb 3, 2016
    hopeful likes this.
  35. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    8,773
    Is the burn shader shown in the sample videos available in the latest version of pack ?

    Thanks
     
  36. Deleted User

    Deleted User

    Guest

    Ok I have found a tutorial (with package), useful for obtain a clipping plane (working with unity 5) equal to position and rotation of a plane (portal in my case). If anyone is interested, this is the link:

    http://www.toxicfork.com/194/per-object-clipping-planes-shader-in-unity3d-5

    In the next days I will try to implement it in my project.

    P.S = Unfortunately my version of shaders created with SF (that of the cruet project), had some problems with the position and rotation values, so I could not use it :(
     
    Last edited by a moderator: Feb 3, 2016
    hopeful likes this.
  37. jackishere

    jackishere

    Joined:
    Mar 1, 2014
    Posts:
    22
    Hi I'm trying to get the SF default post effect to work, currently it's only showing black image on my screen

    I use this on my main camera
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {

    Graphics.Blit(source, destination, testMaterial);
    }

    can anyone tell me the proper way to do it?
     
  38. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    486

    There's no 'easy import this into shaderforge' button.

    But what you can do is work through it one bit at a time. Let's start with a new, default PBR shaderforge shader graph.

    The color, for instance, is very simple. It's just texture multiplied by a color, into the top slot. You can probably leave metallic and glossy sliders alone, unless you want textures for them as well, but that's very easy.

    You'll need some variables, for Bend, BendFrequency, etc, and a Float4 (or Vector4 in SF) for that last one. Then hook them up together piece by piece like in the code.

    It can be worth working 'backwards' and starting with the end (something goes into vertex offset) and seeing what it requires from the line of code above it and then above that and so on and so forth.

    A very good tip I have is to not be afraid to plug things into emissive. Always have a normal (value of 0) near the main input node, and plug that into color, metal and gloss, then plug whatever you want to understand into emissive. It can be one channel (you get B&W image) or it can be RGB or even RGBA and it'll help a lot to visualize whats going on.
     
  39. Deleted User

    Deleted User

    Guest

    Look here: http://forum.unity3d.com/threads/sh...sed-shader-editor.222049/page-99#post-2453479
     
    Last edited by a moderator: Feb 4, 2016
  40. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    486
    Possible bug found:

    When making an opaque shader with no alpha transparency or anything, I found the following issue with the Unity SSAO camera. The SSAO would render 'through' the material, if I was using vertex offset. Happened when the shader was drawn using forward rendering; changing the camera and shader to deferred, or by removing the vertex offset (and nothing else) fixed it.

    But you couldn't have Forward camera, shader, and vertex offset on or SSAO would be borked.
     
  41. jackishere

    jackishere

    Joined:
    Mar 1, 2014
    Posts:
    22
  42. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
  43. mkandersson

    mkandersson

    Joined:
    Oct 5, 2012
    Posts:
    21
    Hi, I'm having some weird problems with my Billboard shader. I'm not that experienced with shaders so I might be doing something really wrong but I have no idea what that is. If anyone has the time to help me out, I'd really appreciate it! :)

     
    Last edited: Feb 8, 2016
  44. Deleted User

    Deleted User

    Guest

    Last edited by a moderator: Feb 5, 2016
  45. Juruhn

    Juruhn

    Joined:
    Jun 25, 2013
    Posts:
    13
    Hi all ..

    Neat program, lots of fun.
    But got stuck with something and wondering if this is doable in SF.

    We got an avatar that is using the fresnel input for the alpha. (client designers choice).
    We are going add 3D objects inside this avatar later on. The avatar stands in front of a custom background (not black but some animated gradient)
    So alpha is important.

    Using fresnel as the alpha result:




    The normal facing the camera gets less opaque, that is logic, but, the result we are after is that the model is not see-through, in other words, we don't want to see the faces on the other side of the model.

    My theory:
    Check from the camera if a face is occluded by another face and don't render that one. (hidden line effect)
    Only thing is, how? Is this possible in SF? I couldn't find any examples of this, or any hidden line feature within one shader.

    How would I approach this to get the required result?

    Thnx !

    Hidden line example with transparency but not rendering the faces on the other side of the model:

     
    Last edited: Feb 5, 2016
  46. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    486
    You should be able to hack around this.

    If you have the depth available, and a shader that writes to Z buffer (which may cause funky results), you should be able to compare the depth (not sure if this is in meters or in 0-1 or logarithmic, plug it into emissive and do whatever you need to to get it in meters; remember you can use view parameters I think to get shortcuts for near/far planes) to the distance between (world position) and (view position).

    If the distance is <= depth, then Alpha = whatever you're doing.
    If the distance is > depth, then Alpha = 0.

    Again, rendering transparent objects effectively as solid CAN cause funny artifacts, especially if it's in front of something else that's also transparent. And SSAO and other effects will pick it up as solid.
     
  47. AndyP-123

    AndyP-123

    Joined:
    Jun 14, 2013
    Posts:
    2
    I'm trying to write a shader that takes the rgba channels of an input texture2d, scales and offsets each channel by a different amount, then combines them and generates a normal map from it. I can do the first and last part separately just fine, but I can't seem to pass the output of the first section of the shader into the tex parameter of the texture2d node I'm using in the second part of the shader (the one that turns the greyscale image into a normal map).

    1. Is it possible to pass rgba data into a texture2d node from something other than a texture asset node? If not, why?
    2. Is it possible to do uv operations without using a texture2d node and modifying the uv input?
    3. Would I be better of just making different normal maps and using the normal map blend node to blend them? It requires more textures, but the node tree is much simpler... would it offer better performance?

    Any help would be much appreciated.
     
  48. Deleted User

    Deleted User

    Guest

    Ok, done for now.



    This is what is still missing to complete the project:

    1) A "universal" clipping plane shader (in this case something that cut a mesh, also if this is rendered with multiple materials and different others shaders) for objects. Or in alternative, find a flexible (as much as possible) way for generalizing the clipping.

    2) Recursive rendering without Texture2D (and related heavy ReadPixels/Apply istructions, if possible).
     
    Last edited by a moderator: Feb 10, 2016
    toxicFork and hopeful like this.
  49. Braldye

    Braldye

    Joined:
    Apr 26, 2011
    Posts:
    54
    I would assume you are taking the rg and ba channels and repacking the normal map to get 2 normal maps in one or you are using the rgba channels seperatly to reconstruct normal maps of each one interdependently from 0-1 height data to get 4 normal maps out of one texture. eather way you should be able to perform all your operations after the texture2d node. if you are trying to create an atlas of all your normal maps I personally would do that outside of the shader in PS or something. If you could drop screen shots of what you are trying to do I could potentially build you a simple code node to simplify things for you.
     
  50. Juruhn

    Juruhn

    Joined:
    Jun 25, 2013
    Posts:
    13
    Hi Jesus, thank you for your reply.

    I've tested it out, but the effect is more a custom clipping in z distance than the effect I am looking for.
    The faces that are behind a face should not be rendered, but those further in z distance that are not behind a face should. (with the fresnel alpha effect applied to it).

    Graph:
     
unityunity