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. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    I have opened yet another new project, uninstalled Unity and reinstalled the latest version, downloaded and installed SF and still the same problem.
    I feel like I now have a series of shaders I have made and a completely useless project now as I can't really do anything now.
     
  2. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
    Maybe @Acegikmo has some idea. Might be a bug, but it seems pretty isolated to something on your machine/version of SF or something, no one else has mentioned similar problems and I can't reproduce it. Sorry :(
     
  3. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
    @RogueCode See my post about post effects on the SF forum - http://neatcorporation.com/forums/viewtopic.php?f=6&t=383

    You have to open up your shader code and manually delete the "Meta" block of code. Someone mentioned adding the EnableCameraDepthInForward.cs component to your camera might fix it, but I haven't actually tried that yet.

    Deleting the meta block fixes the black screen though. You'll have to do this after every change you make in SF.
     
    RogueCode likes this.
  4. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
    @PeteLaChatte Yep that's totally doable. Not sure if there's any tutorials out there though, but it should be easy enough by just modulating the vertex positions with some noise/waves.
     
  5. RogueCode

    RogueCode

    Joined:
    Apr 3, 2013
    Posts:
    210
    @DMeville Thanks so much for the quick reply! That indeed fixes it :D
    Is the default post-effect meant to be upside down or have I done something else wrong?
     
  6. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
    @RogueCode I don't think it should, but you should be able to flip it. Try this: Plug the UV Coord.v -> One Minus. Plug the UV.u and One Minus into an Append and plug that Append into the Remap.

    Not sure if having the post effect upside down will cause issues later though, not sure why it would do that.
     
    RogueCode likes this.
  7. mimminito

    mimminito

    Joined:
    Feb 10, 2010
    Posts:
    780
  8. Deleted User

    Deleted User

    Guest

    Can you share nodes tree? :D
     
  9. Deleted User

    Deleted User

    Guest

    @DMeville

    About ShaderForge, I think that a new version it's necessary (last version was released 3 months ago), but @Acegikmo must still release something :(
     
    DMeville likes this.
  10. RogueCode

    RogueCode

    Joined:
    Apr 3, 2013
    Posts:
    210
    Thank you, that worked :)
    Still have no idea why it happens, but it works for now.
    EDIT: Just found something interesting. Only the _MainTex is flipped, a second texture is fine. So I just flipped the UV's of the texture input node.

    I was getting sick of having to remove the meta pass from the shader on every modification so I made a quick editor script that you might find useful too.
    It will add a menu in Tool > Remove meta pass from shader and you just need to hit go each time you want to remove the pass from your shader.
    (hacked together and not well tested btw)
    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using System.IO;
    4. using UnityEditor;
    5.  
    6. public class RemoveMetaPassFromShader : EditorWindow
    7. {
    8.   Shader _selectedShader;
    9.  
    10.   [MenuItem("Tools/Remove Meta Pass from shader")]
    11.   private static void ShowWindow()
    12.   {
    13.     GetWindow(typeof(RemoveMetaPassFromShader));
    14.   }
    15.  
    16.   void OnGUI()
    17.   {
    18.     _selectedShader = EditorGUILayout.ObjectField(_selectedShader, typeof(Shader), true) as Shader;
    19.  
    20.     if (GUILayout.Button("Go"))
    21.     {
    22.       var path = AssetDatabase.GetAssetPath(_selectedShader);
    23.       var shaderText = File.ReadAllText(path);
    24.       var lastPass = shaderText.LastIndexOf("Pass {");
    25.       if (!shaderText.Substring(lastPass).Contains("Name \"Meta\""))
    26.       {
    27.         Debug.Log("Looks like there is already no meta pass.");
    28.         return;
    29.       }
    30.       var openBrackets = 1;
    31.       for (var c = lastPass + 6; c < shaderText.Length; c++)
    32.       {
    33.         if (shaderText[c] == '{')
    34.         {
    35.           openBrackets++;
    36.         }
    37.         else if (shaderText[c] == '}')
    38.         {
    39.           openBrackets--;
    40.  
    41.           if (openBrackets == 0)
    42.           {
    43.             var metaPass = shaderText.Substring(lastPass, c - lastPass + 1);
    44.             shaderText = shaderText.Replace(metaPass, String.Empty);
    45.             File.WriteAllText(path, shaderText);
    46.             break;
    47.           }
    48.         }
    49.       }
    50.       AssetDatabase.Refresh();
    51.       Debug.Log("Removed meta pass successfully.");
    52.     }
    53.   }
    54. }
    55.  
     
    Last edited: Mar 9, 2016
    DMeville likes this.
  11. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    283
    I guess this should be kinda simple but.... how to make something like this?


    16213976368_16d111e0db_b.jpg 2797108-whitenight_screen2.jpg
     
  12. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
    @daville check out the toon shader in the example scene. that should give you a start
     
  13. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    559
    recon0303, Deleted User and DMeville like this.
  14. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
  15. mrowton

    mrowton

    Joined:
    Oct 28, 2015
    Posts:
    5
    I have a seat for version 1.08 however, I can't update to the latest. After the switch to support unity 5 do I need purchase a new licence?
     
  16. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,206
    You may need to install a newer version of Unity. Not all plugins will be available in their latest updated form on older versions of Unity.
     
    DMeville likes this.
  17. layola

    layola

    Joined:
    Aug 6, 2013
    Posts:
    94
    how to use both uvtile node and rotate node for atlas ?
    may be there are some bug when use uvtile and then rotate ,the result is wrong.
    any help?
    Would anyone know how to do both rotating and then offsetting the UV's? I'd be much appreciative of anyone's help!
     
  18. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Does anyone know how to use the Post Effects shader preset, what do I do with the shader to get it on the camera?
     
  19. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
  20. gururk2

    gururk2

    Joined:
    Feb 10, 2016
    Posts:
    1
    crystl.png

    GUYz pls help me..........
    i need make the crystal glow inside the glass spear using shader forge
     
  21. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Does SF come with translucency support (seeing light through leaves for example, or light through quartz)?
    If so, does anyone have an example of this working with sub-surface artifacts?
     
  22. elizeusz

    elizeusz

    Joined:
    May 2, 2012
    Posts:
    49
    Hi, how i can control shader forge slider parameter over life time in shuriken particle system. In UDK there was something like dynamic parameter module for doing this. How can i do this in unity ?
     
  23. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
  24. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
    If you don't need vertex colours on the particles, read one of the vertex colours in SF and use that to power your slider. Then in the shuriken particle editor edit the "colour over lifetime" gradient to however you want the slider to animate
     
    elizeusz likes this.
  25. elizeusz

    elizeusz

    Joined:
    May 2, 2012
    Posts:
    49
    Thank You i will try both and see which one is the best :)
     
  26. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Using the triplanar example (First Image), is it possible to cover each tile over a 2-unit area instead of 1?

    My this I mean have the texture spread over 2 units per tile instead of 1?

    Also, the texture stays where it is when the object is moved? Is there any way to remove this?
     
  27. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
  28. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    486
    Start with a custom lighting graph. Mess with Light Attenuation; remap it from (0-0.05) to (0-1) and clamp that. That'll get you black and white solid lighting (no falloff).

    The other thing you want to look into is the Unity post effect called Edge detection. Make a copy of it you can mess with. Maybe instead of black lines on a white background multiplied over the view, you want white lines over black, added to the view?


    You can choose a rotate-around-this-point input for the rotator. You will need to adjust this based on what tile you're using.

    You'd want to to the atlasing first, then clamp to that tile (important here, so you don't get bits of the neighbouring tiles when you rotate).

    Then find the center of that tile in UV position (for a 2x2 tile sheet, the top left would be 0.25, 0.75), then rotate around that maybe.

    You guys are both looking for sorta the same thing here I think.

    The best bet would be to use a custom lighting model, and to turn double-sided on.
    There's some Light Wrapping and other lighting options, check the shader forge (what does this node do) website; just right click on a node in SF in Unity and you'll find it. The examples are right at the top. Also check the first page of this thread.

    Other things you can do are to (again, using a custom lighting model), change from the default Normal(dot)LightDirection. You can do that, and negate(Normal)(dot)LightDirection, and that will get you backface lighting.

    Other things to consider are not doing any Normal-based lighting at all. If you replace N.L in a SF node graph with a value of 1, and rely solely on light attenuation and color, you get what sorta looks like fog or smoke or a very fine or hazy jelly. Go on youtube and look for SF Custom Lighting tutorials, you'll know it when you see it.

    More advanced things, like rendering an inside-out ambient occlusion map (invert normals, bake AO), will get you basically a jello-thickness map; where the black areas will transmit the most light 'through', and white areas will get only lit from the side you're viewing it from because it's too thick to see any light on the other side.

    If possible, try to maintain some semblance of physically based, good-looking-in-all-conditions rendering, and you'll likely have to work the specifics of that out yourselves.

    The easiest way to do this is if you have a particle that fades in for the first 10% of it's life, then fades out over the last 10%. That way, you can animate alpha over lifetime to be (0) at birth and (1) at death, and, in shader forge, you can grab vertex alpha, then remap Vertex.Alpha from (0 to 0.1 into 0 to 1), and (0.9 to 1 into 1 to 0), lerp between those by Vertex.Alpha, and clamp the result. Send that into the transparency input. That's fairly easy, and by getting Vertex.Alpha anywhere else in the shader, you have the particle's age (from 0-1).
     
    daville and DMeville like this.
  29. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    486
    Divide worldposition (presumably all of it, but you can do individually XYZ if you want) by 2.

    If you want the texture to 'move' with the object, instead of using world position, use object position.
     
  30. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    543
    ^ from march 7
    Please help.
     
  31. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,206
    I have no idea what you're asking for. My guess that's why no one else has answered, as well.

    Be more specific about what you want to do.
     
    Last edited: Mar 16, 2016
  32. bigSky

    bigSky

    Joined:
    Jan 31, 2011
    Posts:
    114
  33. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
  34. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Sorry to bother you, but I tried to attach this to my main scene to test with my character controller, and my player walks right through it, not passing through it as a portal would but passing physically through the face.
    I also have an issue with movement, where the border of the portal being rendered in the frame (the red frame if looking through the blue for example), jitters when moving as if it isn't being updated as often as the camera.
     
  35. nikokoneko

    nikokoneko

    Joined:
    Feb 20, 2015
    Posts:
    27
    Is ShaderForge supposed to be compatible with 5.4 beta maybe? I am running on 5.4.0b6 and it doesn't work with any project (including an empty new one). Sometimes it will crash right after the shader has been loaded, and sometimes it doesn't crash but no mesh is displayed in the preview window (skybox does get displayed, but none of the meshes, including sf_meshes. I know 5.4 is beta and no plugin is expected to support beta versions of Unity , just checking out if anyone else has this problem, and if there is a fix to this...
     
  36. dMobiLab

    dMobiLab

    Joined:
    Feb 3, 2015
    Posts:
    3
    I got a interesting Shader for UE4. Below is the Shader tree. I want to convert it to unity is it possible?

    and the link to the post is here

    Stuck with Mask(B), Object Bounds and Param(0.5) nodes.

    Edit: it fakes fluid in a container
     
  37. b0kkie

    b0kkie

    Joined:
    Jul 16, 2013
    Posts:
    2
    @Eideren Hi, I've found your version of a parallax shader for shader forge on page 50 of this thread.
    It works very well, though I have to invert my heightmap for it to show correctly.
    Is there a way to adjust your code block so I could avoid inverting my heightmap?
    Currently lighter values go inwards and darker values go outwards, it would be amazing if this would be vice versa.
    Hope you can help me out. Thanks.
    B0kkie
     
  38. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    295
    Well, how would you go about changing values from 0=>1 to 1=>0 ? You would do a simple 1-value, right ?
    Well, you can do the same thing here, for both lines starting with "float tex = tex2D(..." you can change it to "float tex = 1.0f-tex2D(..."
     
    DMeville likes this.
  39. b0kkie

    b0kkie

    Joined:
    Jul 16, 2013
    Posts:
    2
    Thanks, that made perfect sense. Working like a charm!
     
  40. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Anyone know how to actually attach a "Post Effect" shader to a camera?
     
  41. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
  42. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    I think Param is just a Value node, Mask would be Component Mask and I think you'd have to bring in Object Bounds yourself.
     
    DMeville likes this.
  43. dMobiLab

    dMobiLab

    Joined:
    Feb 3, 2015
    Posts:
    3
    Thanks Obsurveyor
    here is the node tree but not able to connect clamp to opacity.
     
  44. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    403
    @dMobiLab You missed the Component Mask (B) on your World Pos - Object Pos!

    The reason you can't connect is because you're trying to plug in a three channel output into a one channel input (opacity), and it doesn't work. You can see how many channels you're using per connection by the number of lines between the nodes. What the component mask does is it allows you to extract one (or more) channels individually. In this case both the channel masks in the UE4 Graph are masking out the B channel, so if you click the - beside the R on the bottom of the component mask you can choose the B channel and use that. You can also right click on any of the nodes and click "What does <node> do?" to bring up the docs for that specific node!
     
    Last edited: Mar 18, 2016
  45. dMobiLab

    dMobiLab

    Joined:
    Feb 3, 2015
    Posts:
    3

    Thankyou @DMeville
    Able to create the Shader (still buggy but works fine for our project)
    Here are the Screenshots


    Shader Tree
     
    KWaldt, Seith and DMeville like this.
  46. moure

    moure

    Joined:
    Aug 18, 2013
    Posts:
    184
    Hi, don't own shader forge and i was wondering if it has moved to GGX shading model?
     
  47. AkiLap

    AkiLap

    Joined:
    Sep 14, 2014
    Posts:
    24
    Hi,

    I have some problems replicating the fog shader to ShaderForge from here:
    http://www.iquilezles.org/www/articles/fog/fog.htm

    namely this one:

    Code (CSharp):
    1. vec3 applyFog( in vec3  rgb,      // original color of the pixel
    2.                in float distance, // camera to point distance
    3.                in vec3  rayDir,   // camera to point vector
    4.                in vec3  sunDir )  // sun light direction
    5. {
    6.     float fogAmount = 1.0 - exp( -distance*b );
    7.     float sunAmount = max( dot( rayDir, sunDir ), 0.0 );
    8.     vec3  fogColor  = mix( vec3(0.5,0.6,0.7), // bluish
    9.                            vec3(1.0,0.9,0.7), // yellowish
    10.                            pow(sunAmount,8.0) );
    11.     return mix( rgb, fogColor, fogAmount );
    12. }
    Here is my node tree and SF settings:

    This is my scene, and as you can see the effect stays blue even when I'm looking at sun:

    Here is a reference of how it should look like:

    Any help appreciated!
     
  48. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    Anyone know of a way to setup a random picking system?
    I want to have a grid system of 2 units to a tile (instead of the default 1 unit) and set a random set of textures to each grid place.

    An example of this would be Portal 2, where the walls were textured using random grids that used a series of textures and placed them randomly around the grid depending on it's size.
     
  49. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    486
    This is easy enough.

    There's a noise function in SF, which can be used for this. Take your worldspace coordinates like you would for any other triplanar mapping shader, and, use the FLOOR node on each X, Y and Z, append two of them at a time (XY and plug that into the NOISE node. Lerp between XY, XZ and YZ like you would any other triplanar shader, and output that to emissive.

    You should see solid-colored grayscale squares on the walls, floor, etc. You can scale these like you would scale the textures on a triplanar shader divide worldspace by 'texture size in meters'.

    The final step is to take an atlas of tiles (say 4x4) and work out a way to select between them using that noise. Look into the UV atlas node. Remember, the grayscale noise is from 0-1, so if you need 1-16 (in a 4x4 sheet) just multiply the noise by 16.

    Bonus points if you alter the UVs of some tiles as well, by mirroring them left-to-right for the walls, or rotating them for the floor tiles, also based on the noise.
     
    DMeville likes this.
  50. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,321
    I have managed to set this up relatively well.

    I have the noise set up correctly (I think), and have worked out how to "atlas" textures (a lot of trial and error), but I cannot work out for the life of me how to get the last bit working, where the textures are selected by the noise.

    I am hoping @Acegikmo or someone else may have an idea on how this can be done.

    P.S. My atlas is also a few pixels out (I can see small lines of the other tiles but I think this is just the texture not being perfect).
    sf_randomselect_3212016.png
     

    Attached Files:

unityunity