- Home /
Vertex/Fragment shaders - transparency ignoring Render Queue
So, I've been writing my own fur shader (because I have only seen one half-decent one around, and I don't have the money to buy it), and it's been going pretty well so far. Lighting is a bit dodgy, but only because I don't have Unity Pro (I could fix it with that, I think). I'm happy to use it as it is at the moment, except for one thing. This shader works by rendering a solid base layer, then gradually stepping out the vertices, and rendering 10 fur layers, stacking on top of each other to produce the hairs. The first layer is rendered with ZWrite On, as well as being tagged as Opaque. The fur layers, however, are rendered with ZWrite Off, and are tagged as Transparent (with the appropriate render queue). However, this is producing problems, as for some reason they seem to always render behind my trees' leaves. No matter what I do to the render queue, I can't seem to get this to work - instead, the only thing I can do is to turn on ZWrite, and this just culls out the leaves, which is almost as bad. I'm fairly new to fragment shaders (I've mostly worked with surface shaders before now), so if anyone could help me out here, I'd really appreciate it. Here's a screenshot of the effect:
I hope that someone can help me out!
Have you tried "Transparent+1000" etc? Try to bring it forward? If you make it work, it will of course render infront of the trees even when it's behind them...
I have tried, that's the odd thing, and it changes nothing.
Actually that's not right I guess, if they are using a cutout shader for leaves.
The leaves are a cutout shader, but it also seems to render behind my custom water shader, which is not.
I think I should clarify that no matter how much I fiddle with the render queue, it seems to change literally nothing - It will not render behind the geometry, no matter what I change, and nor will it do what I want and render in front of leaves and grass.
Answer by Hoeloe · Sep 28, 2013 at 11:33 AM
Aha! I fixed it! It turns out I needed the tags in the Subshader, rather than inside the Pass. The first pass (the base pass) now overwrites the tags from the Subshader, but the rest of the passes, the fur layers, use the default, and now it works perfectly.
Answer by highpockets · Sep 28, 2013 at 05:34 AM
I'm no shader expert and I can't see your code, but I think "Transparent" should be fine. Another thing to consider is the Blend options, which are typically right below the tags.
Try:
Tags{ "Queue", "Transparent" }
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
This is Alpha blending.
There are the tags on my first, base pass:
Tags {"Light$$anonymous$$ode" = "ForwardBase" "RenderType"="Opaque"}
ZWrite On
And these are the tags on my other passes:
Tags { "RenderType"="Transparent" "IgnoreProjector"="True" "Queue"="Transparent"}
Blend SrcAlpha One$$anonymous$$inusSrcAlpha
ZWrite Off
Cull Off
Answer by Steviebops · Apr 14, 2014 at 07:46 PM
Would you be willing to share that shader? I've been looking at fur, and the existing free shaders don't seem to work with my texture's alpha. I get a black outline, as seen here.