Hey all.
I am working on a project that uses a post-processing effect on the camera to outline environment objects - things like castle walls, wooden boxes. The problem is that we use mostly transparent diffuse textures for our character, because he is a ghost, and the black lines from the outlines show through his body (and some other things that use transparent diffuse as well).
You can see an example here:
http://oldjawbone.com/matt/theReturn.png
Notice towards the middle of the screen cap the main character has the lines of the castle turret behind him clipping through.
Does anyone have a suggestion on a shader or combination of shaders that would accomplish a similar outlining effect so that we could use that instead of the post-processing?
You want the outlines to be seen through your ghost man or not?
Not sure which shader you’re using but I’m guessing it doesn’t write to the ZBuffer (thus the edge-detection algorithm can’t see it as it’s likely based on depth testing).
I guess there’s two ways around it - either ZPrime your character so he writes to the ZBuffer (but that’ll stop transparent stuff from rendering behind him) or edit the edge-detection shader to mask the effect from your character - probably by passing in an extra rendertexture that only has him in it in mask format (i.e. either pure black or white - opposite colour to the background).
To ZPrime your character, you want a pass with this before the rest of your shader. This will render him to the depth buffer but nowhere else.
Pass {
ColorMask 0
}
And ensure that the pass that renders him has ZWrite Off and ColorMask RGB. This will render him to the screen but not to the depth buffer - it’ll also stop you seeing him through himself.
Pass {
ZWrite Off
ColorMask RGB
...
}
I don’t want the outlines to show through the ghost man.
Great, thanks for the ideas Farfarer! I will look into the implementation.
Actually, I have an update to this issue.
It’s not just the character that the black lines show through. The game has some environment objects that reside very close to the camera with transparent diffuse textures, and the black lines show through those as well.
The effect that I am using is the Edge Detect Effect Normals, a script that we attached to the camera.
I could attempt to ZPrime all objects (character and environment) that the black lines show through, but do you think that would slow down processing significantly?
I think the better option - if you’re wanting multiple objects to now show the effect through them - would be to use some kind of mask in the shader itself.
I haven’t played extensively with either method - I’ve only had one or two objects per scene ZPrimed before to achieve a ghost-like look. I’m not sure how it interacts with screen shaders.
OK, so I would use a mask in the shader of the objects that I don’t want the effect to show through?