Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Does this help?
    SF_2DShadow.jpg
     
  2. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    This isn't EXACTLY spherical, but it's a similar approach...
    SF_2DPunch.jpg
     
  3. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    Wow, thank you very much for taking the time to help me with this. I'm trying to replicate what you did and have everything set up but for some reason "Custom Lighting" is grayed out and I can't connect the Lerp node to it. Any idea what I'm missing?

    I am getting an error in Unity's console: Incompatible types: Type A: VTv1 Type B: VTvPending
     
  4. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Lighting panel on the left side of the SF editor, Unlit/Custom. Also, in the Blending panel, first setting should be Alpha Blended. Sorry for not mentioning these things earlier.

    That error isn't important if I recall correctly. It just shows up sometimes when connecting or deleting nodes. If you get hundreds of them, then it's a problem.

    Let me know if you have any other questions.
     
  5. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    Thanks again for the support. The other issue I'm running into now is that I'm not sure this shader setup will work because I'm using 2D Toolkit for my sprites.... This shader is wanting a texture, is there a way to have this shader work with a sprite rather than texture?
     
  6. RockSPb

    RockSPb

    Joined:
    Feb 6, 2015
    Posts:
    112
    Hello again! Is it possable to create any alternative light transmission node in deffered mode?
    Without this effect grass look ugly and flat(

     
  7. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Hello, is it possible to get a mesh's orientation in Shader Forge (like the front direction of the object)? I see nodes for accessing object position, scale and normal direction but nothing about orientation...
     
  8. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I don't know 2D Toolkit, but this should be really easy since sprites use materials and materials use shaders. Change the name of the shader's TextureAsset node from Texture to MainTex. If you don't have a material created that uses your shader, create one and assign it to the sprites. I'm not sure what that would look like using 2D Toolkit, but that's the gist of it.

    You can access the model-matrix _Object2World in the code node. It's not friendly though. I don't know another way.
     
  9. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    Hmm yea might not work out with 2D Toolkit because it combines multiple sprites into an Atlas texture, which seems to really screw up the shader. When I do a standard Sprite component that Unity provides it appears to work pretty well, but the dropshadow gets cut off I assume because the texture is cropped right around the character. Anyway to resolve this other than maybe having more transparency around my image content?

    Here is a example of the cut off:
     
  10. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @rxmarccall: Just an idea, may or may not work :p. You could try scaling down the UV's every so slightly - it would shrink your image a bit but should give more room for the shadow to not be cut off.

    No idea about the atlases though.
     
  11. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Thanks! I'll investigate... :)
     
  12. k2_akihiro_takamoto

    k2_akihiro_takamoto

    Joined:
    Feb 18, 2015
    Posts:
    1
    Do you have a plan that corresponds to unity5?
     
  13. oguzhan-uglu

    oguzhan-uglu

    Joined:
    May 4, 2014
    Posts:
    11
    hi , i trying make a snow effect like a this video
    but result tragedy :( tragedy2.png tragedy.png
     

    Attached Files:

  14. scedric

    scedric

    Joined:
    May 13, 2013
    Posts:
    4
    Hello,
    I created a shader to have a constant vertical gradient per object (object position and rotation independent).
    The shader works perfectly as long as there is only one object using it. If I duplicate the object, the shader "breaks".
    Any idea?
    Thank you,
    Cedric
     
  15. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    First, you should update Shader Forge. Second, can you describe what doesn't look right? I can't tell from your images.

    How may draw calls do you have with those 5 quads? I'm betting dynamic batching is the culprit.
     
  16. scedric

    scedric

    Joined:
    May 13, 2013
    Posts:
    4
    Thank you IFL, it is the dynamic batching that causes this issue. Is there a way to disable the dynamic batching by object?
     
  17. oguzhan-uglu

    oguzhan-uglu

    Joined:
    May 4, 2014
    Posts:
    11

    i updated but not solved. simple question " how i make a snow effect shader?"

    vertex color blending and uv tiling process not work plane or sphere or cube. only worked sf_vertex_color_hexagon
     
  18. KaylMyers

    KaylMyers

    Joined:
    Mar 28, 2013
    Posts:
    33
    The default plane/sphere/cube primitives in unity don't have vertex colors on them. You'll need to bake that info into your mesh with your modeling software of choice.
     
  19. oguzhan-uglu

    oguzhan-uglu

    Joined:
    May 4, 2014
    Posts:
    11
    iusethis.png
    Should I not use it?
     
  20. KaylMyers

    KaylMyers

    Joined:
    Mar 28, 2013
    Posts:
    33
    IFL likes this.
  21. oguzhan-uglu

    oguzhan-uglu

    Joined:
    May 4, 2014
    Posts:
    11
    like this okey i understand
    but still do not know how to do snow effect?
    Is there any tutorial?

    likethis.png
     
  22. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    There's quite a few ways depending on the effort that you're willing to spend, but I'm not sure which would work the best for you. Here's a couple of the easiest...
    1. Create a script that makes each object's material unique (not shared). Basically, just assign an instantiated version of the material to each object that you don't want batched.
    2. Assign a non-uniform scale (1.0001, 1.0, 1.0) to each object. This may not work anymore depending on your version of Unity, but it's worth trying since it's easy & fast.
    If you want other options, I have several others.


    There's a few examples in this thread if you don't mind taking the time to look.


    I could spend almost every waking moment on polycount. That place is wonderful. Also, I'm a fan of your work. You're awesome.
     
  23. scedric

    scedric

    Joined:
    May 13, 2013
    Posts:
    4
    You made my day :) thank you very much for your help. I'll probably go for the material instancing since we already use that on the characters.
     
  24. KaylMyers

    KaylMyers

    Joined:
    Mar 28, 2013
    Posts:
    33
    Thank you!
     
  25. KaylMyers

    KaylMyers

    Joined:
    Mar 28, 2013
    Posts:
    33
    I've seen this question asked many times, but never answered. I've been searching half the day already and, like the steering wheel on my jeans, its drivin' me nuts!

    Any ideas on creating projector materials in SF? That is, materials to use with Unity's projector component. I cant be the only one trying to find this info.
     
  26. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @IFL,
    Do you have any idea about the issue I posted about above in regards to the drop shadow shader solution you helped me out with?
     
  27. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    If I remember correctly, you have to edit the shader by hand to get it to properly act as a projector shader. Just look at the built-in additive projector shader - that's where I figured out how to do it. It's a few lines added and maybe a few lines to modify.

    The atlas issue?
     
  28. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @IFL,
    The atlas issue I assume can't be worked around, so I'm looking at possibly just using unity's sprite system instead. But you will notice a graphic I posted up above of the dropshadow being cut off because of the edge of the image boundary.
     
  29. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Oh, right. @DMeville was right with how to fix it (multiply UVs by 1+x, then subtract x/2), but you also have to make sure that the padding is adequate to compensate for the distance that you want the shadow to appear. Material shaders only affect where the mesh is. You can also do the effect as an image effect if you have Pro.
     
  30. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    I'm not sure I can take that route as my sprites need to be the exact size they are and can't be shrunk down at all. I do have Pro, how do I set up the effect as an image effect?
     
  31. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    It's not easy, and it's not feasible if you're targeting mobile. PM me so we don't get this thread any more off-track.
     
  32. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    Sure, sorry. My project is for mobile so I'm just going to be doing drop shadow before hand in photoshop, thanks for your insights.
     
  33. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @rxmarccall: Could you use vertex offset to scale the geometry up first, before scaling the image down slightly? Resulting in the image being the same physical size, just the quad it's on slightly bigger? Idk if that's feasible, just an idea though.
     
  34. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @DMeville
    Thats an idea, ill give it a try tonight. I also was starting to go away from the shader based drop shadow route because it also is not consistant between images of different sizes and shapes as seen here:

    Would be nice to get it working but seems like theres a few problems that are making me want to take another route. I also can't use 2D Toolkit which would be nice.
     
    DMeville likes this.
  35. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Two questions:
    1. Is there a way to modify the incoming vertex, instead of using an offset value?
    2. Every time I edit my shader, the dithering turns back on. This is annoying...is it a known issue with alphaclip textures, or just me?
    Thanks!
    JC
     
  36. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    I really wish I had at least some sense of when Shaderforge may be really useable with latest Unity 5 releases again.
     
  37. KaylMyers

    KaylMyers

    Joined:
    Mar 28, 2013
    Posts:
    33
    On his website, Ace says hes busy with GDC prep at the moment, then its on to U5 implementation.
     
  38. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Yes, I think there was also a desire from Ace to wait for Unity 5.0 to be officially released so that there are no more fundamental changes (as is always the case with beta releases).
     
  39. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Hey guys, I have a question regarding glows. I understand that glows are done with the bloom post-fx, and all pixel values > 1 get "bloomed", but that seems to loose all the details on a mesh/diffuse texture - is there any way to battle this?

    For example; I'd like to give a nice soft glow around this object:
    Screen Shot 2015-02-20 at 5.17.41 PM.png

    But ramping up the glow multiplier in my shader results in something like this:
    Understandably, this is because i'm just adding values to my diffuse texture to have them go beyond one, but is there any other way to get a glow?
    Screen Shot 2015-02-20 at 5.20.56 PM.png

    Ideally, I'm trying to get something like Photoshop's outer glow fx, but maybe that's not possible..?
    Thanks!
     
  40. KaylMyers

    KaylMyers

    Joined:
    Mar 28, 2013
    Posts:
    33
    What I would probably do is leave your diffuse at 1. And use your emissive slot to drive the glow. If you create a fresnel color and really tighten it, you can throw that on your emissive and glow the edges.
     
  41. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,145
    Guess who's back with a rudimentary shader question?

    I'm creating a system to help me more easily identify in-focus areas when dealing with DoF shots.



    The green outlined area of the frustum is the space that'll be in focus, while the blue and the red will be out of focus. What I'd like to do is have my model (a simple modified cube) have different colours depending on a value I set for the near and far focus.



    I was able to get it so it's always shading in the right direction, but for the life of me I can not figure out how to plug in the values/masks to make this work. I just want to plug in some numbers (they'll be localspace in script) so I can resize it from an editor window. What's the easiest way to go about this?
     
  42. Ga2Z

    Ga2Z

    Joined:
    Feb 16, 2012
    Posts:
    68
    Hi Amnoon, I hope is not too late to answer your question, but in case you're still wondering:

    In 3D Max you could animate such a scene with a stack of modifiers, but this animation can't be saved as FBX because these modifiers affect the vertex offsets which are not saved in the FBX file (as far as I know). There are some solutions or at least, approaches to your problem.

    1) you could use morphers to store que vertex animation and Unity does read these as Blendshapes (like Maya) in the FBX import settings.

    2) you could use Point Cache, this is a modifier that stores the vertex offsets overtime, meaning it saves your modifiers animation data. Here's a tutorial about it:

    .

    Unity does not read these files but there are tools that could help, like Megafiers, an awesome and useful tool but pricey if you won't be using it a lot



    Or maybe this free Point Cache reader: http://forum.unity3d.com/threads/point-cache-reader.130564/

    I'm not sure if the Point Cache approach will work flawlessly but I think would be the best. Hope to hear (read) if it worked for your purposes, and pics or it didn't happen :)
     
  43. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    :eek::eek::eek: That's a great idea for cinematography! Does something like this help?

    SF_Murgilod_DistCols.jpg

    [EDIT::] Or do you want smooth transitions?
     
  44. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,145
    Nope! This is absolutely perfect AND it handles the coordinates in a way that I can pass them from code without having to do any math to check!

     
  45. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Should you swap around the red and blue node links to match the edge color? Will it be part of a paid asset?
    As for intersections (like you mentioned in another thread) you might take a look at using projectors. They're surprisingly versatile.
     
  46. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,145
    Whoops, yeah, I just swapped the blue and red frustum colours since all I really need is the green safe area"

    I'll probably toss it up for free once it's all done. It's part of an overall camera system I'm working on for my current project, which relies a lot on some pretty heavy cinematography. As for projectors, that's actually a really obvious idea I didn't consider, so I'll try tossing that on in a bit for a test.
     
  47. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Is there not a straightforward way to modify the vertices, without having to use offsets?
     
  48. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    There's not. I've asked for this one some time ago to get some procedural animation going. In the end I made it work with Offset instead of directly positioning the vertices.
    What you can do: create your shading graph and do the vertex positioning manually (as in: edit the final code) when you're done with your shading iterations in SF.
     
  49. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Gotcha, thanks Marco.
     
  50. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    So there is an anisotropic shader that uses the RGB channels for anisotropic direction, and it's a surprisingly simple shader. Seems like it ddoes something with the half dir and view dir. Is there any way to recreate this inside SF ?

    I'm posting the complete shader below :

    http://forum.unity3d.com/threads/anisotropic-highlight-surface-shader.94270/



    Shader "Bumped Anisotropic Specular" {
    Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Diffuse (RGB) Alpha (A)", 2D) = "white" {}
    _SpecularTex ("Specular (R) Gloss (G) Anisotropic Mask (B)", 2D) = "gray" {}
    _BumpMap ("Normal (Normal)", 2D) = "bump" {}
    _AnisoTex ("Anisotropic Direction (Normal)", 2D) = "bump" {}
    _AnisoOffset ("Anisotropic Highlight Offset", Range(-1,1)) = -0.2
    _Cutoff ("Alpha Cut-Off Threshold", Range(0,1)) = 0.5
    }

    SubShader{
    Tags { "RenderType" = "Opaque" }

    CGPROGRAM

    struct SurfaceOutputAniso {
    fixed3 Albedo;
    fixed3 Normal;
    fixed4 AnisoDir;
    fixed3 Emission;
    half Specular;
    fixed Gloss;
    fixed Alpha;
    };

    float _AnisoOffset, _Cutoff;
    inline fixed4 LightingAniso (SurfaceOutputAniso s, fixed3 lightDir, fixed3 viewDir, fixed atten)
    {
    fixed3 h = normalize(normalize(lightDir) + normalize(viewDir));
    float NdotL = saturate(dot(s.Normal, lightDir));

    fixed HdotA = dot(normalize(s.Normal + s.AnisoDir.rgb), h);
    float aniso = max(0, sin(radians((HdotA + _AnisoOffset) * 180)));

    float spec = saturate(dot(s.Normal, h));
    spec = saturate(pow(lerp(spec, aniso, s.AnisoDir.a), s.Gloss * 128) * s.Specular);

    fixed4 c;
    c.rgb = ((s.Albedo * _LightColor0.rgb * NdotL) + (_LightColor0.rgb * spec)) * (atten * 2);
    c.a = 1;
    clip(s.Alpha - _Cutoff);
    return c;
    }

    #pragma surface surf Aniso
    #pragma target 3.0

    struct Input
    {
    float2 uv_MainTex;
    float2 uv_AnisoTex;
    };

    sampler2D _MainTex, _SpecularTex, _BumpMap, _AnisoTex;

    void surf (Input IN, inout SurfaceOutputAniso o)
    {
    fixed4 albedo = tex2D(_MainTex, IN.uv_MainTex);
    o.Albedo = albedo.rgb;
    o.Alpha = albedo.a;
    o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
    fixed3 spec = tex2D(_SpecularTex, IN.uv_MainTex).rgb;
    o.Specular = spec.r;
    o.Gloss = spec.g;
    o.AnisoDir = fixed4(UnpackNormal(tex2D(_AnisoTex, IN.uv_AnisoTex)), spec.b);
    }
    ENDCG
    }
    FallBack "Transparent/Cutout/VertexLit"
    }