Deferred decals normal problem

Started by
1 comment, last by Hodgman 11 years, 1 month ago

I've been working on a deferred decal system. So far I have finished the projection part, meaning I can click something in the scene and it will properly project a decal onto the surface of the object.

There are a couple other things I wish to add to this system: normal clipping and normal mapped decals. Normal clipping is when I discard fragments that are stretched across a sharp angle. Seen here. A way to solve this is to discard fragments that have a large difference between the normal in the G-Buffer and the decal's normal. This would require reading the G-buffer's normal texture.

In order to do decal normal mapping, I need to blend the decal's normal (from a normal map) with the G-buffer's normal. The requires writing to the G-buffer's normal texture.

I hope it's clear that in order to support these two features, I need to read and write to the normal texture in the same shader pass. Sadly, this is undefined behavior, so I'm wondering if there is some other way to implement these features.

Advertisement

For the normal clipping test, you could copy the normal rendertarget into another texture after the G-buffer geometry pass. It should not be a large performance hit.

As above, making a copy of the normal buffer to read from, before the decal pass is the most straightforward.

Some other ideas:

* you can read the depth buffer instead, and use ddx/ddy to calculate the change in depth, which can be converted into an approximation of the normal (just the per-triangle-face normal, not the normal-mapped normal).

* you can render your decals in two passes. In the first pass you read from the normal buffer and discard where invalid, but only output to a stencil mask. Then in the 2nd pass, draw your decal again only to pixels present in the stencil mask.

This topic is closed to new replies.

Advertisement