Conflict of the glPolygonOffset() with "Shadow Map Silhouette Revectorization" technique

Hello there. :slight_smile:
Hope you have a good day!

To solve “peter panning” problem I try to perform glPolygonOffset().
That gives so good results that I became almost happy.
But one frustrating problem appears: it conflicts with “Shadow Map Silhouette Revectorization” technique I implemented before.

The point is I need to determine the center of shadow texel in view space.
Before I calculated it easily by reprojecting point from shadow map to view space.
But now depth map loose exact dept because of details of glPolygonOffset:
The offset is added before the depth test is performed and before the value is written into the depth buffer.
Thus I can not calculate offsets in view space for shadow texels.

Is there a way to calculate the center of the shadow texel in view space without dept map values?
May be I can have origin and modified depth at the same rendering pass?
May be exists the third way to do that?

Thank for any answer!

It is possible to store a diff generated by glPolygonOffet to separate buffer and keep real data in depth buffer at the same pass?

May be I want to strange stuff, but separate pass to get offset is very expensive, also a custom offset generation is to expensive too even if using early depth test.

Found and implemented solution.

Build composite frame buffer with depth and color textures.
While rendering depth map:

  1. Render adapted depth data directly in depth buffer.
  2. Calculate real depth value in attached fragment shader.

The most difficult was correct calculation of depth:

#version 430

out vec4 fragColor;

in VBlock {
  vec4 position;
} vIn;

void main() {
  float far = gl_DepthRange.far;
  float near = gl_DepthRange.near;
  vec4 pos = vIn.position;
  float val = pos.z / pos.w;
  float depth = (((far - near) * val) + near + far) / 2.0;
  fragColor = vec4(depth, 0, 0, 1.0);

That little bit slower than default depth mapping (without fragment shader) +6 ms.
But much much faster that 2 different passes.

The glPolygonOffet let me dramatically improve shadow quality avoiding any “peter panning”

The very good result for me.