1
\$\begingroup\$

Basically I'm already drawing decals on top of various flat surfaces and that works great.

As soon as the decal approaches the edge of a surface, naturally it doesn't get clipped.

Is there a way to add simple clipping by comparing the value in stored depth buffer, with the depth value (Z) of the decal pixel to be written?

If the depth value about to be written is ~about the same (is within a range), the decal pixel gets drawn, otherwise discarded. Decals don't write to depth-buffer themselves.

Example scene: enter image description here

\$\endgroup\$
  • 1
    \$\begingroup\$ Note that, under the "about the same" criterion, if a character walks through that doorway they'll briefly have a splash of blood ripple across them, as they cross this threshold depth range. So, depending on your setup, you might need a more selective method than comparing depths alone. \$\endgroup\$ – DMGregory Dec 30 '16 at 20:20
  • \$\begingroup\$ @DMGregory do that in addition to stencil test perhaps? Stencil test if the pixel represents THE SURFACE, plus the depth buffer comparison? \$\endgroup\$ – JBeurer Dec 30 '16 at 20:22
  • \$\begingroup\$ have you tried glDepthFunc(GL_EQUAL)? \$\endgroup\$ – Ali1S232 Dec 30 '16 at 21:15
  • \$\begingroup\$ @Ali.S GL_EQUAL doesn't seem to work, (seems like due to precision problems) \$\endgroup\$ – JBeurer Dec 30 '16 at 21:59
  • \$\begingroup\$ @DMGregory actually, this is only an issue if character gets drawn before decals. If decals are drawn first, this doesn't become a problem. \$\endgroup\$ – JBeurer Dec 31 '16 at 4:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.