Trying 24 bit encoding

This commit is contained in:
AlexandruPopovici
2022-10-20 15:07:13 +03:00
parent 60b2f260f9
commit f33faf8475
2 changed files with 16 additions and 7 deletions
@@ -25,6 +25,14 @@ vec3 packLinearDepth(const in float depth) {
return pack;
}
vec3 encode24(const in float x) {
const vec3 code = vec3(1.0, 255.0, 65025.0);
vec3 pack = vec3(code * x);
pack.gb = fract(pack.gb);
pack.rg -= pack.gb * (1.0 / 256.0);
return pack;
}
void main() {
#include <clipping_planes_fragment>
vec4 diffuseColor = vec4( 1.0 );
@@ -45,7 +53,7 @@ void main() {
// Higher precision equivalent of gl_FragCoord.z. This assumes depthRange has been left to its default values.
#ifdef LINEAR_DEPTH
/** View z is negative moving away from the camera */
gl_FragColor = packDepthToRGBA((vViewPosition.z + near) / (near - far));
gl_FragColor = vec4(encode24((vViewPosition.z + near) / (near - far)), 1.);
#else
float fragCoordZ = (0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5);
#if DEPTH_PACKING == 3200
@@ -39,10 +39,6 @@ export const speckleStaticAoGenerateFrag = /* glsl */ `
return vec4( 1.0 );
}
float decode24(const in vec3 x) {
const vec3 decode = 1.0 / vec3(1.0, 255.0, 65025.0);
return dot(x, decode);
}
float getDepth( const in vec2 screenPosition ) {
return texture2D( tDepth, screenPosition ).y;//unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );
@@ -207,6 +203,11 @@ export const speckleStaticAoGenerateFrag = /* glsl */ `
return Result;
}
float decode24(const in vec3 x) {
const vec3 decode = 1.0 / vec3(1.0, 255.0, 65025.0);
return dot(x, decode);
}
float scaleDividedByCameraFar;
float minResolutionMultipliedByCameraFar;
@@ -273,7 +274,7 @@ export const speckleStaticAoGenerateFrag = /* glsl */ `
vec4 samplePointNDC = cameraProjectionMatrix * vec4( samplePoint, 1.0 ); // project point and calculate NDC
samplePointNDC /= samplePointNDC.w;
vec2 samplePointUv = samplePointNDC.xy * 0.5 + 0.5; // compute uv coordinates
float realDepth = unpackRGBAToDepth( texture2D( tDepth, samplePointUv ) );//getLinearDepth( samplePointUv ); // get linear depth from depth texture
float realDepth = decode24( texture2D( tDepth, samplePointUv ).rgb );//getLinearDepth( samplePointUv ); // get linear depth from depth texture
// float realDepth = getLinearDepth( samplePointUv ); // get linear depth from depth texture
float sampleDepth = viewZToOrthographicDepth( samplePoint.z, cameraNear, cameraFar ); // compute linear depth of the sample view Z value
float delta = sampleDepth - realDepth;
@@ -285,7 +286,7 @@ export const speckleStaticAoGenerateFrag = /* glsl */ `
#endif
}
void main() {
float linearDepth = unpackRGBAToDepth( texture2D( tDepth, vUv ) );
float linearDepth = decode24( texture2D( tDepth, vUv ).rgb );
// float convertedViewZ = orthographicDepthToViewZ(linearDepth, cameraNear, cameraFar);
// float centerDepth = viewZToPerspectiveDepth(convertedViewZ, cameraNear, cameraFar);
float centerDepth = getPerspectiveDepth(vUv);