• Advertisement
Sign in to follow this  

Deferred decals normal problem

This topic is 1788 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Edited by Petwoip

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement