Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    I actually forgot about that one. I'm not sure how long it would take to implement it, as it would mean running the BRDF twice, but, I'll look into it.

    It also depends on how you handle the depth buffer. You might want to fiddle with depth writing too and the depth test mode
     
  2. ptm_oo

    ptm_oo

    Joined:
    Oct 30, 2014
    Posts:
    35
    Hello,
    I'm trying to use lights to reveal other texture, I thought it would be easy.. but no success so far, any ideas please?

     
  3. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Many people understandably try this approach, but it unfortunately doesn't work due to how forward rendering is set up.

    In forward rendering, it renders additively for each light source in the scene, which leads to things like this
     
  4. ptm_oo

    ptm_oo

    Joined:
    Oct 30, 2014
    Posts:
    35
    Thanks for answer,
    So, It comes to.. making the LIGHT TEXTURE with substracted MAIN TEX.
    Light texture can be prepared to have substracted main texture:





    [edit] or in SF it works like this:
     
    Last edited: Jun 20, 2015
  5. Sinaz20

    Sinaz20

    Joined:
    Nov 16, 2009
    Posts:
    53
    Acegikmo,

    Could you give us any information about whether Unity's normal map handling changed from Unity 4 to Unity 5?

    We use object space normal mapping for a particular effect. In Unity 4, we did a particular conversion from our Object space normals to Tangent space in a SF shader.

    In Unity 5, that same conversion only works when a particular object is 2 of the possible 4 cardinal directions it can face. The other 2 are subtley off.

    Knowing more about any potential changes in normal maps between Unity 4 and 5 might help me repair this issue.

    thanks.

    I solved this... it turned out to be a color space issue.
     
    Last edited: Jun 26, 2015
  6. kyleyoungblom

    kyleyoungblom

    Joined:
    May 1, 2014
    Posts:
    29
    I'm trying to make a simple cel shader that adds a tinted shadow to an otherwise flat-shaded model. I'm using vertex colors for the main color of my mesh, but the final result is tinted across the whole model rather than just in the shaded areas. If I replace the vertex color node with a color node it seems to display properly, without affecting the lit parts of the mesh. Any ideas as to why this would happen? Thanks!
    sf_unlitvertexcolorshadow_6262015.png
     
  7. FreakForFreedom

    FreakForFreedom

    Joined:
    Jan 22, 2013
    Posts:
    156
    I'm quite tired at the moment so not sure if I'm talking nonsense... but why are you using the emission slot and not the custom lighting one if you want to tint the shadow?
     
  8. kyleyoungblom

    kyleyoungblom

    Joined:
    May 1, 2014
    Posts:
    29
    Honestly I wasn't really sure what the difference was so I just went with emission because it was more familiar to me. :)
    Unfortunately, that's not what's causing my problem.

    sf_unlitvertexcolorshadow_6262015 (2).png
     
  9. ptm_oo

    ptm_oo

    Joined:
    Oct 30, 2014
    Posts:
    35
    After "Add", I think you should put "clamp 0-1", you've got values over 1 there :).
     
  10. kyleyoungblom

    kyleyoungblom

    Joined:
    May 1, 2014
    Posts:
    29
    Perfect! Thanks so much :D
     
  11. Sinaz20

    Sinaz20

    Joined:
    Nov 16, 2009
    Posts:
    53
    You just want to tint whatever is in shadow-- you might consider putting an IF node in there so you can just tint the bands of the posterization that is black or non-white (looking at your Bands input there.) Also, rather than adding, you might consider a Blend Mode: Screen so that you don't get color values that clip as ptm_oo mentions.

    I made a shader that does something like this, and the IF bit is how I created discrete shadow coloration.
     
  12. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
    In shader forge we can use texture sampler as input. Can i grab texture result from shader? As example - I multiply two texture sampler - and grab result for Blit? If not, can i make this through code? How?
     
  13. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    Or even better, use a lerp node with
    A = shadow color
    B = Light Color or white/lit color
    T = your shading calculation / normal dot light

    That saves computation times, makes the whole thing clearer and can be used with different bands of posterization, a gradual change or any kind of dot product.
    And the calculation wont overshoot the dot product unlike the add node as people have mentioned.

    You can't export or reference computed results from a shader to another one.
    If the resulting texture changes at runtime/often(more than once per 5 seconds I would say), you might want to look into "compute shaders". You could also render the texture to a renderTexture but that costs just way too much for something as simple as that.
    If it doesn't have to be changed that often then change the texture file using the CPU, multi-threading might be necessary depending on the texture resolution and how often you change it.
     
    Sinaz20 likes this.
  14. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    How to tie the lifetime of the particles with the parameter shader? Scripts? Is there a solution?
     
  15. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Not really, but you can read the alpha value of the vertex color. That is the parameter that is being set when you do "Color over lifetime"
     
  16. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    Thanks a lot
     
  17. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    I'm having exactly the same issue. Did anyone find a solution yet? This problem makes all the SSAO assets out there technically unusable if you require vegetation. Currently you have to use Unity's default Screen Space Ambient Obscurance post-processing effect. It's the only solution I know of that renders correct SSAO, including Shader Forge's forward vegetation shaders.

    Except of course there's the rather huge issue that Screen Space Ambient Obscurance looks horrible at anything beyond 50 meters from the camera (it's a static grains festival). With no way to adjust the maximum distance of course (where would be the fun in that).
     
  18. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    How do I fix this shader to it work correctly with the Color over lifetime parameter of the particles? I want that alpha changed from 255 to 0. Now the particles dramatically just die without the soft decay.
     
  19. DaDarkDragon

    DaDarkDragon

    Joined:
    Jun 6, 2013
    Posts:
    115
  20. Morfeuskiev

    Morfeuskiev

    Joined:
    Oct 10, 2013
    Posts:
    122
    @Vladnes Update Shader Forge to latest 1.16 version. It has examples for particle shader when you create new shader.
     
  21. Vladnes

    Vladnes

    Joined:
    Jul 5, 2014
    Posts:
    51
    Thank you, I have found that I need
     
  22. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    IFL and Marco-Sperling like this.
  23. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
  24. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    With the right textures, could I make my own decent water shader (perhaps with things like wave deformation, caustics, rippling etc) with Shader Forge? If yes, how easy might it be?
     
  25. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Water shader is definitely possible. But you might want to split some effects over various shaders (like caustics).
    Have you ever done anything with shaders before? Do you have basic knowledge? Have you been into visual node based scripting before? If so you should be able to put something together within a day or two based on UDK tutorials (they are a great source of information).
    If you are new to this field you might find decent looking water to be a bit of a struggle for your first project.
     
  26. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    It would be my first venture in to nodes. I'm just coming up to speed properly on C# and Unity having done programming in other languages before. I do like the way nodes work.
     
  27. Razouille

    Razouille

    Joined:
    Jan 25, 2013
    Posts:
    44
    Hi,

    Just got a little question about your amazing work : is there any possibility to make incredible shaders working with 2D sprites ? (like the Sprites/Diffuse one)

    Thank you in advance !
     
    Last edited: Jun 30, 2015
  28. pixelquaternion

    pixelquaternion

    Joined:
    Jun 28, 2014
    Posts:
    122
    Hi there,

    Thank a lot for the great deal, i am a happy new customer.

    Regards Peter
     
    Acegikmo likes this.
  29. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    592
    I don't know yet, that i will need this asset, but I couldn't resist for that price. I hope there will be no conflicts with the Alloy shader asset.
     
  30. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    It is possible to make :
    - Sub Surface scattering shaders for skin ?
    - Fast vegetation transluent shaders ?
     
  31. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It should be! There is a 2D shader template you can start you shader with, which is set up properly for 2D. You can then alter it however you like :)
     
  32. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    SSS is definitely possible. The cheapest way is to use the light wrapping input of the main node. Other techniques tend to be quite advanced, even when making it in a node-based editor, but, Google should help you out there :)

    Translucency however, is almost always a pain, and you won't get away from sorting issues without sacrificing something. The easiest way is to use alpha clipping instead of alpha-blended transparency. SF also has dithered alpha clip support, if you want semi-partial transparency :)
     
  33. dev_2051

    dev_2051

    Joined:
    Jul 25, 2013
    Posts:
    92
    Hi,

    Before purchase i wish to know how shaders created by shader forge work for mobile devices(Both 2d/3d) in terms of CPU/GPU load?

    Thanks.
     
  34. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
  35. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    There are a couple features I find that are missing!
    1: ColorMask, we need this to keep the alpha channel untouch while still using alpha blended stuff. Our alpha channel contains how much we should heat distort, then we do heat distortion as part of the post process chain.
    2: ZWrite, I need to be able to turn this on and off.

    Then I have a wish for a feature that might be a little bit more complex.
    The ability to create my own output structure, in this case the 4 textures that are output in deferred, but unlike unity's current deferred mine is slightly modified!
     
  36. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Thanks for the requests! You can already disable ZWrite though. It's in the blending settings, at the very bottom, called "Write to depth buffer" :)

    ColorMask should be straightforward, I can make sure that makes it into the next update!
    Not sure about the buffer setup though, that is, like you said, quite a bit more complex
     
  37. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Well, the buffer setup does require you to create a non-surface shader, but after that it's quite simple on the code side.
    After the in-parameters from the vertex shader, you simply use the out keyword, ex:
    Code (CSharp):
    1. frag (v2f i, out target0 : SV_Target0, out target1 : SV_Target1, out target2 : SV_Target2)
    2. {
    3.        target0 = tex2D(_MainTex, i.uv);
    4.        target1 = tex2D(_Spec, i.uv);
    5.        target0 = tex2D(_Normals, i.uv);
    6. }
     
  38. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It's more a matter of interface. The main node can no longer have sensible labels if you have a custom deferred setup, so I would have to add branching/exceptions to the way the main node works
     
  39. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Or in that case replace the main interface with those labels. I'm aware that not many people would use it, but the few people who are experienced enough to use it will often be forced away from shader forge otherwise.

    On another note, a couple of missing nodes:
    Clip
    Discard
     
  40. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    I will use Alloy perhaps for that task.
    Thanks for your feedback, i already purchased shader forge as this is something that should be standard in Unity, and i couldn't loose this discount opportunity this time :)
     
  41. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Alpha clipping /fragment discarding is done using the Opacity clip input of the main node. You can, however, do it with the code node too
     
  42. AniMoney

    AniMoney

    Joined:
    Sep 28, 2014
    Posts:
    10
    Is there a way to get the camera vector into a node?
     
  43. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Transform a vector 3 with the values (0,0,1) from view to world, using the transform node
     
    AniMoney likes this.
  44. AniMoney

    AniMoney

    Joined:
    Sep 28, 2014
    Posts:
    10
    Splendid. Really glad I bought this while it was on sale, it's way more fun than I expected!
     
  45. BigDill

    BigDill

    Joined:
    Jan 1, 2013
    Posts:
    31
    Bought this yesterday and love it! I am a shader noob so I am sorry if my questions are stupid and get rolling eyes. As an example is it possible to blend a bunch of textures on to a cube sphere mesh and then somehow save the rendered texture output as a new texture of some common format so I could reapply the saved texture using a standard defuse shader at a later phase of my workflow? Reason I ask is to create a workflow using unity alone that will allow me to optimise my output for mobile platforms.

    I have achieved this result in mud box but MB is overkill for what I want to do.

    Thanks for creating such a great unity extension.
     
  46. Ekibyou

    Ekibyou

    Joined:
    Feb 19, 2014
    Posts:
    10
    Hey Ace, I got Shader Forge yesterday and I'm trying some stuff with it.
    Right now, I want to have a crystal ball effect on a plane. I think refraction is going to be the way to go, but I can't seem to get the proper effect. Everything is warping in weird ways with the refraction shader that is in the example assets.
    I've tried several different normal maps, but none of them seem to do the job.

    This is the closest I got:


    This is the level without shader:


    And the normal map on this screenshot:


    It seems to push everything to the top left... I use orthographic camera, so it positioning shouldn't really matter. Any idea?
     
  47. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Make sure it's marked as a normal map in both the texture and the node in the shader
     
  48. Zazibar

    Zazibar

    Joined:
    Aug 22, 2014
    Posts:
    2
    Looks like I missed the sale, bummer. :(
     
  49. Ravart

    Ravart

    Joined:
    Mar 9, 2011
    Posts:
    42
    Not sure, if Shader Forge is at fault, but I hope someone can point me in the right direction. I used the material Phong and Gloss(0.3), strangely I get these artifacts with Gloss. Activating Lightmapping reduces the effect, but it's still occurring! Using PBL as material has a similar effect as activating Lightmapping. Couldn't recreate the effect with Unity PBL.

    I take any input I can get
    Cheers!

     
  50. sotec

    sotec

    Joined:
    Sep 14, 2012
    Posts:
    34
    hi everyone, i got stuck on my shader for a while now, so i'm asking a bit of help ^^'
    i'm doing a triplanar shader with a lot of param ( rotation, auto scaling, etc) , i removed all those options to focus on my little problem : i don't manage to make a proper mask with the object normal :

    triplanarbug.png

    there is an Abs node between the transform and the mask.

    the problem is that in the scene it give me this result :

    wtfbug2.png
    only one face work, but if the object rotate, the texture become dark too . i don't really understand where is my problem.

    thank you ^^