0
\$\begingroup\$

For a long time I was occuring issue with lights which use light volume to reduce fragment shaders run (point, spot).

First I use stencil pass to mark pixels which should be processed by fragment shader by drawing a sphere. Then in light pass I render the same sphere again.

Everything works ok until light volume cuts with far plane. Back faces of that volume aren't rendered so stencil buffer contain 0 value.

Because of that final image has big black circle instead of lightened area. I searched how to overcome that issue and I realized that one of the solution to this problem is to enable GL_DEPTH_CLAMP which ignores near and far plane. I enabled it for both passes. The problem dissapeared.

My question are:

  • Is that correct solution used by people and does it decrease performance?
  • Why all tutorials doesn't mention about that issue? I'm curious if I have something wrong in my implementation.

I am aware that there are other methods such as screen-aligned quads or tile based deferred rendering but I want to understand this method as well.

\$\endgroup\$
  • 2
    \$\begingroup\$ That is one correct way to solve the problem. Depth clipping can be disabled in other graphics APIs as well, this is a normal feature. \$\endgroup\$ – János Turánszki Jan 15 '18 at 21:12
  • \$\begingroup\$ Could you please briefly describe other possible methods? I had some other ideas but it seems to be the simplest one. \$\endgroup\$ – Harry Jan 15 '18 at 21:18
1
\$\begingroup\$

Depth clipping can be disabled in other graphics APIs as well, this is a normal feature, so this is one way to solve the problem.

You can draw front faces of light geometries when you are outside of the volume, this should resolve clipping issues because lights will be clipped when geometries are too. When you are inside, and still clip away the backfaces, you must extend the far plane I'm afraid or disable depth clipping.

An other way, is do not draw lights which would intersect the farplane or be completely behind it. Now this would result in light popping out as they get farther away from you. I would make a fog to hide them. If there is an area completely fogged between you and the farplane, that would be a safe area where lights can pop out unnoticed. The fog should occlude any lighting of the scene too to have lights pop out unnoticed.

\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.