Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. Powdered_sugar

    Powdered_sugar

    Joined:
    Aug 23, 2012
    Posts:
    64
    Good afternoon all.

    I'm trying to figure out a way to accent edges with a Shader Forge shader. I'm playing around with a simple terrain generation program right now, and and wanting to accent the edges to make it easy to distinguish between levels.

    Here's what I have:



    And here is something like what I am looking for:



    I don't believe that the Outline node would work for this since they're hard edges. Has anyone else attempted this with Shader Forge before? The shader right now is a simple gradient from the base of the terrain to the top, I've included an image the node structure with this post. Any help would be greatly appreciated.

    Thanks!
     

    Attached Files:

  2. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    @kr3d Ok, I have managed to get the same effect you are getting, the only thing I would try is not using UV Coord.
     
  3. kr3d

    kr3d

    Joined:
    Apr 13, 2015
    Posts:
    6
    Hmm sorry but I'm not good in shaders. How I can create that shader without UV Coord?
     
  4. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Not sure, I think that is whats causing it, I don't use it very often so I could be completely wrong, but thats the only thing I don't use very often and all the rest I use together quite a lot and I have never had this problem.
     
  5. kr3d

    kr3d

    Joined:
    Apr 13, 2015
    Posts:
    6
    :) Okey, thanks for your time :) Maybe i must wait to next update :)

    EDIT:
    I found problem - dynamic batching.
     
    Last edited: Apr 13, 2015
  6. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    @Acegikmo I'm seeing a very strange bug here: when calling the main diffuse texture of a forward alpha cutout shader "Diffuse" everything looks fine. But if I call it "MainTex" then there's a weird silhouette artifact happening around the edges.



    It's like the vertex animation is forgotten by the background! Again, the only difference between the shaders is the name of the main diffuse texture. :eek:

    Does anyone know what's happening? Also note that the screenshot is from the scene camera, NOT the game camera (which looks the same anyway). So that's not a post-effect artifact.
     
  7. Deleted User

    Deleted User

    Guest

    Someone know how i can achieve this effect? Which texture i must use?

     
  8. frontakk

    frontakk

    Joined:
    Jan 8, 2011
    Posts:
    292
    Hi everyone.
    I made polar coordinate shader, but displayed noise line.
    How to remove noise line?
     
  9. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @frontakk: What happens if you change the texture mode (to clamp) on the texture you're dropping into your "MainTexture" node? Sometimes that fixes small things like in your image.
     
  10. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Pretty sure you can't (easily, there is no checkbox in SF to do this automagically). As far as I know, Unity 5 is using a custom inspector for the Standard shader
     
  11. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Looks like it uses a panning texture that moves with time to distort the UVs. I think a simple perlin noise texture would do the trick.

    Are you sure your texture is in repeat mode and not clamped ?
     
    DMeville likes this.
  12. frontakk

    frontakk

    Joined:
    Jan 8, 2011
    Posts:
    292
    I set to texture mode is "Clamp" , uv scroll animation is stopped.
    And not remove noise line...
     
  13. Deleted User

    Deleted User

    Guest

    Ok, maybe i have fixed all





    If this result is incorrect, pass me the texture...
     
    Last edited by a moderator: Apr 14, 2015
  14. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    You can do this in many ways. Here's one for example:
    SF_lightning_arc.gif
    sf_lightningbolt_4142015.png

    Edited:
    For some reason I forgot to multiply the noise by 2Pi (Tau). If you don't do that the bolt amplitudes will be biased towards the Displacement value's sign.
    That's because the noise returns values in the range of 0 - 1. Sine function gets negative only after Pi.
     
    Last edited: Apr 16, 2015
    DMeville and Deleted User like this.
  15. Deleted User

    Deleted User

    Guest

  16. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    You see the wire in the middle of the graph coming down from the uv calculations and going into the vector multiplication? That one pins the ends of the lightning bolt to their original position. Delete that line and the whole thing wobbles.
    But as said - that's one way to do it. Experiment. Mix a noise texture into the graph. Pan the UVs some more.
     
    DMeville and Deleted User like this.
  17. Deleted User

    Deleted User

    Guest

    Great, thanks...
     
  18. Deleted User

    Deleted User

    Guest

    Hi, is there a way to flip normals of a mesh in shaderforge?its for a double sided shader.
     
  19. Deleted User

    Deleted User

    Guest

    Go to blending, face culling, and choose double sided.
     
  20. Deleted User

    Deleted User

    Guest

    turning face culling off is Not the same as flipping normals, it will not produce proper lighting.
    After a little research i found i have to make two passes for the shader - one for the mesh normal's and one for the flipped meshnormals (code for flipping normals: http://wiki.unity3d.com/index.php/ReverseNormals); Aparenly a less expensive method is duplicate the faces of your model (in modeling software) and flip the duplicated meshes normals, so all the polygons are double-sided.

    I am rather curios about the hair shader in tech demo "the blacksmith" though. looks awesome
     
    Deleted User likes this.
  21. Deleted User

    Deleted User

    Guest

    At this point think that this will be implemented in future versions, with multiple pass (if unity technology won't release their shader editor before new SF).
     
  22. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    In the event that anyone wants them, here's a couple of substances.

    The first creates 1 image with 4 different types of noise and some basic parameters for each:
    SubstancesExample.jpg

    The second is a utility to swazzle images and channels into a new image. So the output RGBA could look like (Image1_G, Image3_B, Image2_A, Image4_Grayscale). It's kind of handy for combining textures for the new Standard shader, but that isn't what it was created for.

    Cheers
     

    Attached Files:

  23. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Have a look at this post in userecho http://shaderforge.userecho.com/topic/295877-two-sided-sign-node/
    I cannot try it at the moment but it looks like you might achieve your desired results with this method.
     
  24. Hoop22

    Hoop22

    Joined:
    Jul 3, 2014
    Posts:
    3
    Hello, all. I want to forge a water shader, but have no idea how to start it.
    A tutorial is totally cool, cause I have searched for it online for a while, but got nothing....
    Could anybody please give me any ideas?
     
  25. DeadNinja

    DeadNinja

    Joined:
    Jun 3, 2013
    Posts:
    39
    You can start by just reading this thread from start, there are few decent shaders lays in deep of it.
     
  26. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I just want to say that Shader Forge is great with U5. Here's some arctic water. It's mostly SF - just had to do voronoi (using the substance I posted a few posts back), normal reconstruction, tessellation, and time phasing.

    SF_ArcticWater.jpg
     
    Acegikmo, Ga2Z and DMeville like this.
  27. Ga2Z

    Ga2Z

    Joined:
    Feb 16, 2012
    Posts:
    68
    It looks gorgeous, could you post a video or an animated gif to appreciate fully?
     
    IFL likes this.
  28. Ryirs

    Ryirs

    Joined:
    Jan 9, 2015
    Posts:
    12
    Hi every one, first i wanted to say that i just got started with ShaderForge and it's nice and intuitive, i'm new to shaders in general but it still makes it easy to enter :)
    I am currently viewing the Gametutor videos that are really nice to get started, and get in a shader oriented mind.
    From what i was told the their volume three with more advanced features is hopefully due later this month.

    That being said i have a little question for my current tests.
    Is there a proper way to check if a map is assigned or not to a texture 2d node and use one input instead of an other ?
    I am "lerping" two maps A and B based on the alpha of C but i want A without B if B isn't specified (not sure it was clear)

    The only "Clean" way i could think of would be to add a "Toggle" node and a "If" node, but that adds an extra manual input i'd like to avoid.

    Am i missing something or would any of you have any idea on the proper way to do that ?
    Thanks.
     
  29. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    There's no way to check that from inside the shader in a sense of "do the lerp if both textures are there, ignore the lerp otherwise".
    What Unity does for a shader to work even without applying a texture to a property is falling back to a default texture behind the scenes - those defaults are either black, gray or white. Or they are flagged as bump in case of normal maps.
    Those parameters can be seen in the Properties block of any of Unity's shaders that use textures.

    So there will always be a texture running into your lerp. Either the one you provided or the fallback texture.
    You cannot detect this stuff from inside the shader. It only operates on colors.
     
  30. Ryirs

    Ryirs

    Joined:
    Jan 9, 2015
    Posts:
    12
    Thanks, guess i'll have to go with the toggle option then :)
     
  31. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Tried to make it a bit more true to life... and I wish the forums supported webm. It doesn't look near as good at low res and low color - I'll put up an HD video after I finish it in a few days.
    insta.gif
     
    twoc46, P1st3ll1 and Ga2Z like this.
  32. Thjellesen

    Thjellesen

    Joined:
    Oct 7, 2014
    Posts:
    23
    Hey
    Is it possible to build a shader with Movie Texture as diffuse and another Movie Texture as alpha with Shaderforge ?
    Thanks in advance
     
  33. Deleted User

    Deleted User

    Guest

    Finally I created my custom RGB Vector Displacement Mapping shader and I'm satisfied. Now I would like to implement HDR eye adaptation effect. I can make the simplest image based effects (for example I made grayscale shader). Maybe someone writes here some ideas ?
     
  34. Tomer3

    Tomer3

    Joined:
    Apr 19, 2015
    Posts:
    2
    Hi!

    Im trying to create basic water reflection on a quad, but have some problem with the projection.

    I use MirrorReflection3 script from wiki, and have set SF shader on a water material. FPS character has a camera which is rendering to texture and this texture should be used to render water reflections.

    Here is my scene with water quad and shader nodes:
    http://i.imgur.com/TXFTnEM.png

    heres another image when the scene is played:
    http://i.imgur.com/G40Htoz.png

    It does seem I have missed something as the view is not mirrored correctly (seen also in camera preview).

    Any help is welcome :)
     
  35. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,145
    I'm trying to recreate the light dir node with a vector4 since I'm working in deferred and I need to set up per-character directional lights. How does the light dir node actually pass values so I can implement it?
     
  36. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    You mean this?
    Code (csharp):
    1. float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
     
  37. dblincoeii

    dblincoeii

    Joined:
    Mar 4, 2015
    Posts:
    19
    Hi all! New to unity3d and shader forge. Shader Forge is a godsend! Can someone explain how to blend the intersection of two meshes?
    Thanks in advance for your help!
     
  38. rdein

    rdein

    Joined:
    Apr 10, 2015
    Posts:
    1
    Hello everyone, I've got an issue here about cel-shading and point lights

    This is the shader I'm using: http://puu.sh/hlncy/9b8674fbb2.shader
    And this is the stuff I'm making atm: http://puu.sh/hl7h5/8ef4df4020.jpg
    The brighter rectangle in the middle is a point light, and as you can see, they are displayed as rectangles. What am I supposed to do here to fix that?
    Thank you.
     
  39. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    738
    Hi everyone, recently started using SF.
    I encountered a certain issue while trying to make a ramped toon shader as pointed on the picture below.

    This is the current ramp texture I am using.
    I tried a lot of things, and I can't seem to fix the issue.
    If anyone is kind enough to guide me to the right way, I would be very thankful!
     
  40. Ryirs

    Ryirs

    Joined:
    Jan 9, 2015
    Posts:
    12
    Hi, i'm trying to make a procedural iris/eye shader, but not too sure where to start from, any one that can point me in the right direction ? :)

    Is there any color replacement node i overlooked ?
     
    Last edited: Apr 21, 2015
  41. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    @Gekigengar
    Have you set your ramp texture to "clamped" instead of "repeat" in your import settings?
     
    Gekigengar likes this.
  42. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Take a look at the DepthBlend node. Also, you can use vertex colors (way faster, i think) for static intersections.

    I can't seem to reproduce that. I ran into similar rectangles when using screen-space ramp shading. Not sure what's causing that on your end. Do you have any other info that might help to recreate it?

    Ugly shading is from shadows in LightAtten - I don't know a good workaround for that. Out of curiosity, why do you have a third channel for the Stroke UVs?
     
  43. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Like this?
    SF_EyeShader.jpg
    What's your target? Deferred/forward? PC/Mobile? Above is deferred and definitely not mobile, but it can be ironed out quite a bit.
     
  44. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    738
    So there is no actual way to fix it?
    Oh well, I guess the players will have to accept it as one of the game's "Aesthetic". :p (NOT!)

    What about the weird black/white dots? How do they appear, and why are they there?

    For the Stroke UV,
    I was trying to achieve this.
    And this is the quote from the original creator.
    I don't know if I am doing it right.
    But I wish to achieve such effect.
     
    Last edited: Apr 21, 2015
  45. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I'm sure there's a way, but I don't know it.
    Like @Marco Sperling said, clamp your ramp. With a repeating texture, sampling with a UV of *,1 will be blended with the *,0 sample unless you have filtering set to none/pixel. Clamp keeps that from happening.

    About the stroke texture, it looks like that image has screen-space strokes, which look awesome in still images but horrible when moving the camera. UV-based strokes have the downfall of requiring each UV island to be proportionally scaled to their 3D area with as little stretching as possible. Even then, each UV seam will be visible. I did a pretty in-depth study to determine the best way to get the stroked look in real-time, and I never found anything that would be feasible to use on a skinned-mesh. That doesn't mean it's impossible, but I'd look into it if I were you.

    TLDR: If you're going for real-time rendering, do you have an example of a game or videos that do it the way you want? If you're going for still images, then screen-space is likely your best bet.
     
  46. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    738
    I will keep an eye out for an answer then.
    Any forums I can go to for shader related helps?

    Ah yes, that really fixed the Black/White dot.
    Thank you Marco & IFL!
    Really helped me out!


    I don't know how this style of outlining and strokes are done, but they definitely look awesome moving in skinned mesh.

    Ofcourse, since I am using it in a game (Instead of a pre-rendered CG),
    I only seek on how to do the strokes, not all of the effects.
    Though, that specular looks very unique #_#


     
    Last edited: Apr 21, 2015
  47. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    For your shadow thingy :
    The "Light Attenuation" node give you access to the shadow map which is a greyscale texture(0=shaded, 1= lit), those stripes things comes in because shadow mapping is really finicky.

    So this is how it currently works : After your basic shading is done, the lerp node gives you a ramp from white to greyish then you multiply that by 0 (when the pixel is in shadow) which darkens your base shading and makes it really obvious.

    What you should be doing is using light attenuation in the calculation of your basic shading.
    The simplest way to do it is by computing the ramp using a bunch of math.
    Here's a render :
    Cel-Shading.png
    That shader should be attached to this post, you can tweak different stuff and I commented most of the important parts.
     

    Attached Files:

  48. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    @Eideren - Thanks for that info.

    @Gekigengar - That is some wonderful art. From this page, it sounds like they do the line shading by hand, as a texture. I tried to find an example of the line-shading changing in different scenes, but it seems to remain constant. Did I miss something? Regardless, Lightwave is a beast at rendering.



    On a different note, after posting that eye shader, I fixed it up a bit...
    SF_Eye02.jpg
    I need to clean it up before sharing it though. It's a mess right now:
    SF_Eye03.jpg
     
    Marco-Sperling likes this.
  49. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    Also, when using light attenuation, you might want to consider multiplying it by 2 and then clamping it back between 0-1, this kills most of the shadow acne at a price of losing some of our "soft shadow" gradient.
    Light Attenuation.png
     
  50. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    738
    I couldn't thank you more, this gives such a beautiful result. (The stripes are effectively destroyed using this solution.)

    But is using math to calculate ramp more efficient (Performance-wise) than using a ramp texture?
    And what if I want to have multiple level of shade?
    What can I do? (Using a ramp texture, I could effortlessly set-up what a darker color of shade at 70 - 100%, and a lighter shade at 30 - 69%).
     
    Last edited: Apr 21, 2015