Added ner and far camera planes controls to see how they're values change depth encoding precision

This commit is contained in:
AlexandruPopovici
2022-10-18 22:12:02 +03:00
parent 931190f738
commit e778637b94
4 changed files with 59 additions and 54 deletions
+24
View File
@@ -335,6 +335,30 @@ export default class Sandbox {
this.viewer.requestRender()
})
postFolder
.addInput({ near: 0.01 }, 'near', {
min: 0,
max: 2,
step: 0.001
})
.on('change', (ev) => {
this.viewer.cameraHandler.activeCam.camera.near = ev.value
this.viewer.cameraHandler.activeCam.camera.updateProjectionMatrix()
this.viewer.requestRender()
})
postFolder
.addInput({ far: 10 }, 'far', {
min: 0,
max: 10000,
step: 1
})
.on('change', (ev) => {
this.viewer.cameraHandler.activeCam.camera.far = ev.value
this.viewer.cameraHandler.activeCam.camera.updateProjectionMatrix()
this.viewer.requestRender()
})
postFolder
.addInput(Sandbox.sceneParams, 'tonemapping', {
options: {
+26 -26
View File
@@ -264,32 +264,32 @@ export default class SpeckleRenderer {
}
}
const v = new Vector3()
const box = this.sceneBox
const camPos = new Vector3().copy(
this.viewer.cameraHandler.activeCam.camera.position
)
let d = 0
v.set(box.min.x, box.min.y, box.min.z) // 000
d = Math.max(camPos.distanceTo(v), d)
v.set(box.min.x, box.min.y, box.max.z) // 001
d = Math.max(camPos.distanceTo(v), d)
v.set(box.min.x, box.max.y, box.min.z) // 010
d = Math.max(camPos.distanceTo(v), d)
v.set(box.min.x, box.max.y, box.max.z) // 011
d = Math.max(camPos.distanceTo(v), d)
v.set(box.max.x, box.min.y, box.min.z) // 100
d = Math.max(camPos.distanceTo(v), d)
v.set(box.max.x, box.min.y, box.max.z) // 101
d = Math.max(camPos.distanceTo(v), d)
v.set(box.max.x, box.max.y, box.min.z) // 110
d = Math.max(camPos.distanceTo(v), d)
v.set(box.max.x, box.max.y, box.max.z) // 111
d = Math.max(camPos.distanceTo(v), d)
this.viewer.cameraHandler.camera.far = d
this.viewer.cameraHandler.activeCam.camera.far = d
this.viewer.cameraHandler.activeCam.camera.updateProjectionMatrix()
this.viewer.cameraHandler.camera.updateProjectionMatrix()
// const v = new Vector3()
// const box = this.sceneBox
// const camPos = new Vector3().copy(
// this.viewer.cameraHandler.activeCam.camera.position
// )
// let d = 0
// v.set(box.min.x, box.min.y, box.min.z) // 000
// d = Math.max(camPos.distanceTo(v), d)
// v.set(box.min.x, box.min.y, box.max.z) // 001
// d = Math.max(camPos.distanceTo(v), d)
// v.set(box.min.x, box.max.y, box.min.z) // 010
// d = Math.max(camPos.distanceTo(v), d)
// v.set(box.min.x, box.max.y, box.max.z) // 011
// d = Math.max(camPos.distanceTo(v), d)
// v.set(box.max.x, box.min.y, box.min.z) // 100
// d = Math.max(camPos.distanceTo(v), d)
// v.set(box.max.x, box.min.y, box.max.z) // 101
// d = Math.max(camPos.distanceTo(v), d)
// v.set(box.max.x, box.max.y, box.min.z) // 110
// d = Math.max(camPos.distanceTo(v), d)
// v.set(box.max.x, box.max.y, box.max.z) // 111
// d = Math.max(camPos.distanceTo(v), d)
// this.viewer.cameraHandler.camera.far = d
// this.viewer.cameraHandler.activeCam.camera.far = d
// this.viewer.cameraHandler.activeCam.camera.updateProjectionMatrix()
// this.viewer.cameraHandler.camera.updateProjectionMatrix()
const currentAzimuth = this.viewer.cameraHandler.controls.azimuthAngle
const currentPolar = this.viewer.cameraHandler.controls.polarAngle
@@ -11,23 +11,6 @@ export const speckleDepthFrag = /* glsl */ `
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
varying vec2 vHighPrecisionZW;
highp vec4 encode32(highp float f) {
highp float e =5.0;
highp float F = abs(f);
highp float Sign = step(0.0,-f);
highp float Exponent = floor(log2(F));
highp float Mantissa = (exp2(- Exponent) * F);
Exponent = floor(log2(F) + 127.0) + floor(log2(Mantissa));
highp vec4 rgba;
rgba[0] = 128.0 * Sign + floor(Exponent*exp2(-1.0));
rgba[1] = 128.0 * mod(Exponent,2.0) + mod(floor(Mantissa*128.0),128.0);
rgba[2] = floor(mod(floor(Mantissa*exp2(23.0 -8.0)),exp2(8.0)));
rgba[3] = floor(exp2(23.0)*mod(Mantissa,exp2(-15.0)));
return rgba / 255.;
}
void main() {
#include <clipping_planes_fragment>
vec4 diffuseColor = vec4( 1.0 );
@@ -50,7 +33,7 @@ void main() {
#if DEPTH_PACKING == 3200
gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
#elif DEPTH_PACKING == 3201
gl_FragColor = encode32( fragCoordZ );
gl_FragColor = packDepthToRGBA( fragCoordZ );
#endif
}
`
@@ -38,18 +38,9 @@ export const speckleStaticAoGenerateFrag = /* glsl */ `
vec4 getDefaultColor( const in vec2 screenPosition ) {
return vec4( 1.0 );
}
highp float decode32(highp vec4 rgba) {
highp float Sign = 1.0 - step(128.0,rgba[0])*2.0;
highp float Exponent = 2.0 * mod(rgba[0],128.0) + step(128.0,rgba[1]) - 127.0;
highp float Mantissa = mod(rgba[1],128.0)*65536.0 + rgba[2]*256.0 +rgba[3] + float(0x800000);
highp float Result = Sign * exp2(Exponent) * (Mantissa * exp2(-23.0 ));
return Result;
}
float getDepth( const in vec2 screenPosition ) {
vec4 plm = texture2D( tDepth, screenPosition ) * 255.;
return decode32( plm.rgba );
return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );
}
float getLinearDepth( const in vec2 screenPosition ) {
@@ -192,6 +183,13 @@ export const speckleStaticAoGenerateFrag = /* glsl */ `
#endif
}
highp float decode32(highp vec4 rgba) {
highp float Sign = 1.0 - step(128.0,rgba[0])*2.0;
highp float Exponent = 2.0 * mod(rgba[0],128.0) + step(128.0,rgba[1]) - 127.0;
highp float Mantissa = mod(rgba[1],128.0)*65536.0 + rgba[2]*256.0 +rgba[3] + float(0x800000);
highp float Result = Sign * exp2(Exponent) * (Mantissa * exp2(-23.0 ));
return Result;
}
float scaleDividedByCameraFar;