Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    How can i create an edge glow with a blue color in the shader i currently have? I get the impression i need to mess with my alpha clip more.
     

    Attached Files:

  2. BigDill

    BigDill

    Joined:
    Jan 1, 2013
    Posts:
    31
    Thank you Ace, Not taken the wrong way, I do understand and I am sorry I needed such basic assistance but it is very much appreciated. I won't ask any non SF questions in the future.
     
    Acegikmo, Zicandar and IFL like this.
  3. KenneyNL

    KenneyNL

    Joined:
    Jun 16, 2015
    Posts:
    8
    Not using deferred unfortunately, changing the models of the voxel isn't possible because the effect should be visible on all meshes. Since the game will support modding in the future, it will import user meshes. Not sure what to do with DepthTextureMode reallly - no idea where to start.
     
  4. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    DDX/DDY are intrinsics of the graphics card; they give you the partial derivatives of the 2x2 pixel block being shaded, and thus cannot be computed per triangle or even changed by unity. On newer cards there are multiple variants of these functions (ddx_fine, etc), and some older cards do not expose them at all, but they are fundamental to how a graphics card draws pixels.
     
  5. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,157
    Can somebody give me a child's guide to DDX/DDY and what they can be used for? Because these things are making me way confused.
     
  6. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    They're used to calculate derivatives (rate of change) of things you otherwise cannot. For instance, if you have a complex vertex deformation, and you then want to have correct normal directions as well, you might be able to do it using ddy/ddx to recalculate the normals.

    They're both in screen space though, and basically tell how "How much does this value change, relative to the screen?"
     
  7. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    There's yet another reason why Shader Forge is awesome: you can play around with stuff you have no clue about, just to see what happens. DDX & DDY can apparently be used to make a ball that shows really crappy outlines of everything behind it.
    Ava_Unity_TPose_DDXDDY_Sphere.jpg
     
  8. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    Is there a chance to get a facing node to detect back faces so that normals can be flipped? I saw some discussion on another site, but can't quite find it again. It looks like in the generated shader it already knows about which side is which, but this doesn't seem to be exposed via a node.
     
  9. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    You could compare a "dissolve" value with your "dissolve mask texture" via step node. 0 on the dissolve value indicating no dissolve. 1 fully dissolved.
    If you do the same thing a second time but now with an added threshold/offset to either your dissolve value or the texture (depends on where you plug the two into the step function) you will get second gradient. Now you can subtract the first one from the second one and you will receive the "edge" of your dissolve effect.
     
  10. Obsurveyor

    Obsurveyor

    Joined:
    Nov 22, 2012
    Posts:
    277
    Can't you already do this with the dot product between the view direction and the triangle normal?
     
  11. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It should be exposed, yeah. I'll add it in 1.18 :)
     
  12. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    I think unity added this functionality in 5.1? (SV_Facing?)
     
  13. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    That is awesome! thanks so much.

    And btw... every time I visit this forum I ask myself the same question. Why is people asking Joachim how to to this and that? I think Joachim decided to develop a tool, not to write a shader coding Bible. I think people should learn by themselves the methods and techniques they need for their purposes instead asking here.
     
  14. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    @David_MG

    In my case, i spend time learning shaders, but sometimes there are deadlines you need to work with and you cant come to a result with limited knowledge and time. The tool is amazing and has taught me much already.

    However sometimes there is simply a need for someone to nudge you in the right direction or tell you about a function/node you weren't aware off before. Respectfully, i understand he's made a tool and does his best to support it, but much like most tools on the store (say NGUI at the time) a community of users will form from all levels of expertise. To exclude people is rather elitist.

    Perhaps creating a forum for the tool itself rather than a unity thread might be helpful for people to share and help each other? I'm much more in favour of stimulating collaboration as opposed to elitism.

    We've all started somewhere.
     
    Last edited: Jul 13, 2015
  15. zyzyx

    zyzyx

    Joined:
    Jul 9, 2012
    Posts:
    227
    +1 for the forum idea (or a slack chat)
     
    Superflat likes this.
  16. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
  17. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
  18. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Ideally there would be a Shader Forge subforum. Perhaps I can talk to Unity and get a Shader Forge topic tag in the Graphics subforum?
     
  19. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Graphics subforum would be cool.
     
  20. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    There is the one over here: http://forum.unity3d.com/forums/shaders.16/
    But it would be nice to have a topic tag for Shader Forge that people can add.
     
    Superflat likes this.
  21. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Yeah I knew that one. Have seen SF related questions over there and answered one or two of them. But a dedicated subforum would be nice... or those topic tags you are speaking of (though I'm not sure what they are and how to use them).
     
  22. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    There's a tag for UNET now in this subforum. You see it on many of the threads :)
    http://forum.unity3d.com/forums/multiplayer-networking.26/
     
  23. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    There's also irc.freenode.net #unity3d, where I'm almost always at :)
     
  24. chrischris

    chrischris

    Joined:
    Oct 18, 2005
    Posts:
    19
    With the nice addition of the matrix nodes, anybody want to take a crack at determining the world position from the Scene Depth value? I've made some attempts based on code snippets found in the forums, but I can't seem to get results that make any sense.

    I've been trying the inverse-projection method, using the following to pass in the relevant matrix, based on several of those snippets:
    Code (CSharp):
    1. material.SetMatrix("_ViewProjectInverse", (theCamera.projectionMatrix * theCamera.worldToCameraMatrix).inverse);
    I've also looked a bit at the Unity-provided Global Fog shader & script, but wasn't sure about reproducing the world-position bits in Shader Forge.

    Here are some relevant threads:
    http://forum.unity3d.com/threads/world-position-from-depth.151466/
    http://forum.unity3d.com/threads/world-position-from-view-space-position-yes-again.246315/
    http://forum.unity3d.com/threads/recreating-world-position-from-depth-algorithm.263435/
    http://forum.unity3d.com/threads/world-position-from-depth-in-non-pp-shader.212647/
    http://forum.unity3d.com/threads/world-position-of-a-pixel-from-depth-texture.97671/
     
  25. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Thanks for pointing me in the right direction! The step node was definitely the one i was after.
     

    Attached Files:

  26. kyleyoungblom

    kyleyoungblom

    Joined:
    May 1, 2014
    Posts:
    29
    Could I get some advice on creating a simple waveform? I've searched quite a bit and couldn't find an example of how to accomplish this, so my apologies if it's already been addressed. I'm trying to achieve something like this, by Tomas Sala:
    gauge.gif

    or this, by Willy Chyr:
    waterfall-splash.gif

    This is the best I've been able to manage, but I'm at a bit of a loss when it comes to offsetting the wave over time:
    sine.gif
    Any advice would be greatly appreciated. Thanks!
     
    Last edited: Jul 14, 2015
  27. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    If you want it to be more of a physically-visual wave instead of just time-based, you need to incorporate (usually add) at least one axis from the fragment/vertex position (UV, local, world, screen, polar, etc) into the algorithm for the wave. Don't forget that you can use multiple waves combined to create a more appealing look for natural effects. :)
     
  28. kyleyoungblom

    kyleyoungblom

    Joined:
    May 1, 2014
    Posts:
    29
    Thanks for the response, IFL. I'm not worried about adding randomness or subtlety just yet though, still working on getting the wave to have... waves! :)

    Right now I'm just able to make a flat line go up and down, but I'm shooting for an oscillating waveform. I know it's probably pretty simple but I'm just starting to learn this stuff :D
     
  29. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Hi all.
    Working on a color picker plane.

    Q: Why do i have to multiply by 1.2? so the top-right Red color looks right?

    Ex:


    Thanks,
    izzy.
     
  30. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    504
    I think because you're trying to desaturate the color yellow (R1G1B0) and map it to full bright red.

    What I think you should do instead is this.
    UV (U) is saturation. Lerp between white and (color) by U.
    UV (V) is brightness. Multiply said lerp from above by brightness(V).
    Grab that, and into emission it goes.

    Though, I'm not sure why you'd do it this way? If you want Hue, Saturation and Brightness options available, you'll need the new Hue Node instead of the (color), and some way to move between hues (value).

    If you don't want to do it with the Hue node, you'll probably need to cater for cases where the input (color) might be a dark bluish gray or something. Maybe normalize the (color) node (stick a normalize node immediately after it and before anything else) so that it's always got a fullbright value that plays nicely with full saturation and brightness values.
     
  31. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Probably because you don't want to use the desaturate node there. Here's a working version:

    sf_newshader_7152015.png
     
  32. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Oh, as a bonus, this will be even more trivial in the next update :)

    sf_newshader_7152015.png
     
    Gekigengar, Murgilod, IFL and 2 others like this.
  33. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
    Awesome. does that also works as a hue shift?
     
    Last edited: Jul 15, 2015
  34. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Yeah you can plug in pretty much anything in there :)
     
  35. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    How to get squares instead of circles? I need to have each pixel has black stroke, the thickness of which is adjustable.
     
  36. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Does this help?
    SF_kyleyoungblom01.jpg
     
  37. kyleyoungblom

    kyleyoungblom

    Joined:
    May 1, 2014
    Posts:
    29
    Yes! Perfect, thank you so much IFL. Adding the panning sin values was what I was missing. Seems so obvious in retrospect. This is very helpful for me :D
     
    IFL likes this.
  38. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Does this help?
    SF_Vladnes02.jpg
     
  39. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    Hi guys I am trying to make a fade out effect in my shaders. Basically I want to use a slider from 0 to 1 to controle the opacity.

    I thought that using a slider conected to the opacity node it will work but I only get weird results. I have tried a lot of combinations with alpha blended and nothing. Do you guys know some tutorials or some method to do that?

    When I use Alpha Blended my shaders breaks

     
    Last edited: Jul 15, 2015
  40. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Pics or it didn't happen. (preferably at 0.25 and 0.5 on the slider)
     
    Last edited: Jul 15, 2015
  41. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    I think you need to define "weird results"
     
  42. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    Yes sorry, I have edited the post
     
  43. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    That's a classic issue with alpha blending in almost any engine out there. Simply "fading" out an object is much harder than it seems. This is something AAA games struggle with as well, even released ones have the artifact visible, even though they try to hide it as much as possible.
     
    IFL likes this.
  44. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    Ah ok I did not know that.
    With the alpha blended mode and a slider connected to the opacity slot I get exactly the effect that I am looking for but I can't fix the strange result of the picture.
    Sooo there is some trick to get some similar result to that fade out effect but with the opaque blend mode or it's impossible?
     
  45. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    opacity at 0,5

     
  46. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    You could make a dissolve shader: http://forum.unity3d.com/threads/sh...sed-shader-editor.222049/page-68#post-2047758

    Or use dithered opacity clip, look under the blending settings: http://forum.unity3d.com/threads/sh...sed-shader-editor.222049/page-53#post-1900547
     
  47. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
  48. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Yes, just make sure all sorting settings are set to alpha clipping
     
  49. KaylMyers

    KaylMyers

    Joined:
    Mar 28, 2013
    Posts:
    33
    Where did everything end up with creating shaders to work with Unity5's Terrain objects? In looking around, it seems like you need to hand edit the code to get them to work properly, But that was a while ago. Did this ever get integrated?
     
  50. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Not really, no. Their terrain system, is, to say the least, odd.
    You'd be better off rolling your own terrain system