c++ - Reconstructed position from depth - How to handle precision issues? -
in deferred renderer, i've managed reconstruct fragment position depth buffer.... mostly. comparing results position stored in buffer, i've noticed i'm getting lot of popping far away screen. here's screenshot of i'm seeing:
the green , yellow parts @ top skybox, position buffer contains (0, 0, 0) reconstruction algorithm interprets normal fragment depth = 0.0 (or 1.0?).
the scene rendered using fragcolor = vec4(0.5 + (reconstpos - bufferpos.xyz), 1.0);
, anywhere resulting fragment (0.5, 0.5, 0.5) reconstruction , buffer have exact same value. imprecision towards of depth buffer expected, magenta , blue seems bit strange.
this how reconstruct position depth buffer:
vec3 reconstructpositionwithmat(vec2 texcoord) { float depth = texture2d(depthbuffer, texcoord).x; depth = (depth * 2.0) - 1.0; vec2 ndc = (texcoord * 2.0) - 1.0; vec4 pos = vec4(ndc, depth, 1.0); pos = matinvproj * pos; return vec3(pos.xyz / pos.w); }
where texcoord = gl_fragcoord.xy / texturesize(colorbuffer, 0);
, , matinvproj
inverse of projection matrix used render gbuffer.
right position buffer gl_rgba32f
(since it's testing accuracy, don't care bandwith , memory waste), , depth buffer gl_depth24_stencil8
(i got similar results gl_depth_component32
, , yes need stencil buffer).
my znear 0.01f, , zfar 1000.0f. i'm rendering single quad ground 2000.0f x 2000.0f large (i wanted big enough clip far plane).
is level of imprecision considered acceptable? ways people have gotten around problem? there wrong how reconstruct view/eye-space position?
Comments
Post a Comment