We’re trying to do an adjustable per surface glow on surfaces with transparent shaders.
Right now we’re using a modified particle shader (with colormask removed) and fudging it with global glow settings compromised between all surfaces. Is there a better way to do this?
I found mentions of multipass rendering in other threads but am unsure of how to pursue that.
I think the multipass is the only sane way to go. Basically one pass for colors, and one for glow. Something like this (pseudocode, not the actual shader):
...
Pass { // this will do colors
ColorMask RGB // color channel only
Blend SrcAlpha OneMinusSrcAlpha // blend
ZWrite Off
SetTexture [_MainTex] { combine primary }
}
Pass { // this will do alpha (glow)
ColorMask A // alpha channel only
Blend Off // hm... not sure what you'd want here
ZWrite Off
// use separate alpha texture for the glow!
SetTexture [_GlowTex] { combine primary }
}
So, I’ve been using this method of getting per-object-glow, but I’ve run into a problem I can’t figure out:
I have some billboard trees, where I don’t wan’t glow. First I did the Colormask RBG, but then the glow from objects behind it would shine through. So I added the extra pass (I’m using a modified “vegetation - two pass - unlit”). Problem with that is that now SOME of my trees mask the glow behind them with the entire polygon, while some trees mask the glow with the shape created from the alpha channel. weird…
Attached image: In the left image the polygon is masking the glow (red lines) and in the right one the glow is masked by the alpha-shape of the texture. Only thing I can think of that’s different between the two is what way the polygon is facing. Could that cause the problem? (Haven’t been able to solve the probkem by rotating my trees though…)
My third pass is almost identical to your suggestion Aras, except for “SetTexture [_GlowTex] { combine texture }”
Pass { // this will do alpha (glow)
ColorMask A // alpha channel only
Blend Off // hm... not sure what you'd want here
//Cull Off
ZWrite Off
// use separate alpha texture for the glow!
SetTexture [_GlowTex] { combine texture }
}
Sorry about the weird indentation, but hope it is of some help. In the screenshot you can see the results of it. The Character doesn’t have any glow, but is properly interacting with the glowing sun behind him.
I can’t get your shader to cover my glow at all, but at least it’s consistent. I’m using a lot of custom shaders, doing fogs and what not so there’s enough things that can go wrong.
I’m leaving the topic for now, need to finish a lot of other stuff for tomorrow. I’ll do some simple test scenes this weekend and try to locate the source of the problem.
Found one thing that contributes to the equation → Combining my mesh into on big object.
I’ve been using the meshcombiner to create one object out of all my trees and removing that helps fix the problem. It doesn’t remove it completely though (my shader is probably also doing something wacky…). I’m guessing that the big combined mesh, with vertices all around my glowing object doesn’t perform well with z-sorting.