Skip to main content
GameDev.net gamedev.net
🔒 Locked

Deferred decals normal problem

Started by Petwoip Feb 26, 2013 at 11:39 PM 1 replies 4.1k views
Original Post
Petwoip
Petwoip

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.

Hodgman
Hodgman

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.