using WEBGL_DEPTH_TEXTURE extension to remove the depth pass. causes precision problems for EDL
This commit is contained in:
parent
22ddccc5c2
commit
963bc76d99
@ -280,6 +280,8 @@ Potree.Shaders["pointcloud.vs"] = [
|
||||
" vOpacity = opacity;",
|
||||
" vLinearDepth = -mvPosition.z;",
|
||||
" vNormal = normalize(normalMatrix * normal);",
|
||||
" ",
|
||||
" //gl_Position.z = ((vLinearDepth - near) / (far - near)) * 2.0 - 1.0;",
|
||||
"",
|
||||
"",
|
||||
" // ---------------------",
|
||||
@ -294,7 +296,7 @@ Potree.Shaders["pointcloud.vs"] = [
|
||||
" vColor = texture2D(gradient, vec2(w,1.0-w)).rgb;",
|
||||
" #elif defined color_type_depth",
|
||||
" float linearDepth = -mvPosition.z ;",
|
||||
" float expDepth = gl_Position.z / gl_Position.w;",
|
||||
" float expDepth = (gl_Position.z / gl_Position.w) * 0.5 + 0.5;",
|
||||
" vColor = vec3(linearDepth, expDepth, 0.0);",
|
||||
" #elif defined color_type_intensity",
|
||||
" float w = (intensity - intensityMin) / (intensityMax - intensityMin);",
|
||||
@ -739,6 +741,13 @@ Potree.Shaders["edl.fs"] = [
|
||||
" return 1.0 - (linearDepth - near) / (far - near);",
|
||||
"}",
|
||||
"",
|
||||
"float expToLinear(float z){",
|
||||
" z = 2.0 * z - 1.0;",
|
||||
" float linear = (2.0 * near * far) / (far + near - z * (far - near));",
|
||||
"",
|
||||
" return linear;",
|
||||
"}",
|
||||
"",
|
||||
"float obscurance(float z, float dist){",
|
||||
" return max(0.0, z) / dist;",
|
||||
"}",
|
||||
@ -753,9 +762,10 @@ Potree.Shaders["edl.fs"] = [
|
||||
" vec2 N_abs_pos = vUv + N_rel_pos;",
|
||||
" ",
|
||||
" vec4 neighbourDepth = texture2D(depthMap, N_abs_pos);",
|
||||
" float linearNeighbourDepth = expToLinear(neighbourDepth.r);",
|
||||
" ",
|
||||
" if(neighbourDepth.w > 0.0){",
|
||||
" float Zn = ztransform(neighbourDepth.r);",
|
||||
" float Zn = ztransform(linearNeighbourDepth);",
|
||||
" float Znp = dot( vec4( N_rel_pos, Zn, 1.0), P );",
|
||||
" ",
|
||||
" sum += obscurance( Znp, 0.1 * linearDepth );",
|
||||
@ -766,12 +776,14 @@ Potree.Shaders["edl.fs"] = [
|
||||
"}",
|
||||
"",
|
||||
"void main(){",
|
||||
" vec4 color = texture2D(colorMap, vUv);",
|
||||
"",
|
||||
" float linearDepth = texture2D(depthMap, vUv).r;",
|
||||
" float expDepth = texture2D(depthMap, vUv).r;",
|
||||
" float linearDepth = expToLinear(expDepth);",
|
||||
" ",
|
||||
" float f = computeObscurance(linearDepth, pixScale);",
|
||||
" f = exp(-expScale * f);",
|
||||
" ",
|
||||
" vec4 color = texture2D(colorMap, vUv);",
|
||||
" if(color.a == 0.0 && f >= 1.0){",
|
||||
" discard;",
|
||||
" }",
|
||||
@ -2378,6 +2390,7 @@ Potree.EyeDomeLightingMaterial = function(parameters){
|
||||
lightDir: { type: "v3", value: lightDir },
|
||||
neighbours: { type: "2fv", value: neighbours },
|
||||
depthMap: { type: "t", value: null },
|
||||
depthPassMap: { type: "t", value: null },
|
||||
colorMap: { type: "t", value: null }
|
||||
};
|
||||
|
||||
|
||||
4
build/js/potree.min.js
vendored
4
build/js/potree.min.js
vendored
File diff suppressed because one or more lines are too long
@ -218,6 +218,8 @@ Potree.Shaders["pointcloud.vs"] = [
|
||||
" vOpacity = opacity;",
|
||||
" vLinearDepth = -mvPosition.z;",
|
||||
" vNormal = normalize(normalMatrix * normal);",
|
||||
" ",
|
||||
" //gl_Position.z = ((vLinearDepth - near) / (far - near)) * 2.0 - 1.0;",
|
||||
"",
|
||||
"",
|
||||
" // ---------------------",
|
||||
@ -232,7 +234,7 @@ Potree.Shaders["pointcloud.vs"] = [
|
||||
" vColor = texture2D(gradient, vec2(w,1.0-w)).rgb;",
|
||||
" #elif defined color_type_depth",
|
||||
" float linearDepth = -mvPosition.z ;",
|
||||
" float expDepth = gl_Position.z / gl_Position.w;",
|
||||
" float expDepth = (gl_Position.z / gl_Position.w) * 0.5 + 0.5;",
|
||||
" vColor = vec3(linearDepth, expDepth, 0.0);",
|
||||
" #elif defined color_type_intensity",
|
||||
" float w = (intensity - intensityMin) / (intensityMax - intensityMin);",
|
||||
@ -677,6 +679,13 @@ Potree.Shaders["edl.fs"] = [
|
||||
" return 1.0 - (linearDepth - near) / (far - near);",
|
||||
"}",
|
||||
"",
|
||||
"float expToLinear(float z){",
|
||||
" z = 2.0 * z - 1.0;",
|
||||
" float linear = (2.0 * near * far) / (far + near - z * (far - near));",
|
||||
"",
|
||||
" return linear;",
|
||||
"}",
|
||||
"",
|
||||
"float obscurance(float z, float dist){",
|
||||
" return max(0.0, z) / dist;",
|
||||
"}",
|
||||
@ -691,9 +700,10 @@ Potree.Shaders["edl.fs"] = [
|
||||
" vec2 N_abs_pos = vUv + N_rel_pos;",
|
||||
" ",
|
||||
" vec4 neighbourDepth = texture2D(depthMap, N_abs_pos);",
|
||||
" float linearNeighbourDepth = expToLinear(neighbourDepth.r);",
|
||||
" ",
|
||||
" if(neighbourDepth.w > 0.0){",
|
||||
" float Zn = ztransform(neighbourDepth.r);",
|
||||
" float Zn = ztransform(linearNeighbourDepth);",
|
||||
" float Znp = dot( vec4( N_rel_pos, Zn, 1.0), P );",
|
||||
" ",
|
||||
" sum += obscurance( Znp, 0.1 * linearDepth );",
|
||||
@ -704,12 +714,14 @@ Potree.Shaders["edl.fs"] = [
|
||||
"}",
|
||||
"",
|
||||
"void main(){",
|
||||
" vec4 color = texture2D(colorMap, vUv);",
|
||||
"",
|
||||
" float linearDepth = texture2D(depthMap, vUv).r;",
|
||||
" float expDepth = texture2D(depthMap, vUv).r;",
|
||||
" float linearDepth = expToLinear(expDepth);",
|
||||
" ",
|
||||
" float f = computeObscurance(linearDepth, pixScale);",
|
||||
" f = exp(-expScale * f);",
|
||||
" ",
|
||||
" vec4 color = texture2D(colorMap, vUv);",
|
||||
" if(color.a == 0.0 && f >= 1.0){",
|
||||
" discard;",
|
||||
" }",
|
||||
|
||||
@ -285,7 +285,7 @@ function initThree(){
|
||||
var height = elRenderArea.clientHeight;
|
||||
var aspect = width / height;
|
||||
var near = 0.1;
|
||||
var far = 1000000;
|
||||
var far = 100*1000;
|
||||
|
||||
scene = new THREE.Scene();
|
||||
scenePointCloud = new THREE.Scene();
|
||||
@ -1030,16 +1030,21 @@ var EDLRenderer = function(){
|
||||
var depthMaterial = null;
|
||||
var attributeMaterial = null;
|
||||
|
||||
var depthTexture = null;
|
||||
|
||||
var rtDepth = null;
|
||||
var rtOcclusion = null;
|
||||
var rtNormalize = null;
|
||||
var rtColor = null;
|
||||
var hqCompositionMaterial = null;
|
||||
var gl = renderer.context;
|
||||
|
||||
var initEDL = function(){
|
||||
if(edlMaterial != null){
|
||||
return;
|
||||
}
|
||||
|
||||
var depthTextureExt = gl.getExtension("WEBGL_depth_texture");
|
||||
|
||||
edlMaterial = new Potree.EyeDomeLightingMaterial();
|
||||
depthMaterial = new Potree.PointCloudMaterial();
|
||||
attributeMaterial = new Potree.PointCloudMaterial();
|
||||
@ -1069,11 +1074,13 @@ var EDLRenderer = function(){
|
||||
type: THREE.FloatType
|
||||
} );
|
||||
|
||||
rtNormalize = new THREE.WebGLRenderTarget( 1024, 1024, {
|
||||
rtColor = new THREE.WebGLRenderTarget( 1024, 1024, {
|
||||
minFilter: THREE.LinearFilter,
|
||||
magFilter: THREE.NearestFilter,
|
||||
format: THREE.RGBAFormat,
|
||||
type: THREE.FloatType
|
||||
type: THREE.FloatType,
|
||||
depthBuffer: false,
|
||||
stencilBuffer: false
|
||||
} );
|
||||
|
||||
var vsNormalize = Potree.Shaders["normalize.vs"];
|
||||
@ -1082,7 +1089,7 @@ var EDLRenderer = function(){
|
||||
var uniformsNormalize = {
|
||||
depthMap: { type: "t", value: rtDepth },
|
||||
occlusionMap: { type: "t", value: rtOcclusion },
|
||||
texture: { type: "t", value: rtNormalize }
|
||||
texture: { type: "t", value: rtColor }
|
||||
};
|
||||
|
||||
var hqCompositionMaterial = new THREE.ShaderMaterial({
|
||||
@ -1090,18 +1097,36 @@ var EDLRenderer = function(){
|
||||
vertexShader: vsNormalize,
|
||||
fragmentShader: fsNormalize
|
||||
});
|
||||
|
||||
|
||||
|
||||
depthTexture = new THREE.Texture();
|
||||
depthTexture.__webglInit = true;
|
||||
depthTexture.__webglTexture = gl.createTexture();;
|
||||
gl.bindTexture(gl.TEXTURE_2D, depthTexture.__webglTexture);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT, 1024, 1024, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_SHORT, null);
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
var resize = function(){
|
||||
var width = elRenderArea.clientWidth;
|
||||
var height = elRenderArea.clientHeight;
|
||||
var aspect = width / height;
|
||||
|
||||
var needsResize = (rtDepth.width != width || rtDepth.height != height);
|
||||
|
||||
// disposal will be unnecessary once this fix made it into three.js master:
|
||||
// https://github.com/mrdoob/three.js/pull/6355
|
||||
if(rtDepth.width != width || rtDepth.height != height){
|
||||
if(needsResize){
|
||||
rtDepth.dispose();
|
||||
rtNormalize.dispose();
|
||||
rtColor.dispose();
|
||||
rtOcclusion.dispose();
|
||||
}
|
||||
|
||||
@ -1110,11 +1135,37 @@ var EDLRenderer = function(){
|
||||
|
||||
renderer.setSize(width, height);
|
||||
rtDepth.setSize(width, height);
|
||||
rtNormalize.setSize(width, height);
|
||||
rtColor.setSize(width, height);
|
||||
rtOcclusion.setSize(width, height);
|
||||
|
||||
if(needsResize){
|
||||
renderer.setRenderTarget(rtColor);
|
||||
var framebuffer = rtColor.__webglFramebuffer;
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
||||
|
||||
|
||||
gl.bindRenderbuffer( gl.RENDERBUFFER, rtColor.__webglRenderbuffer );
|
||||
gl.renderbufferStorage( gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, rtColor.width, rtColor.height );
|
||||
gl.framebufferRenderbuffer( gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, null );
|
||||
|
||||
gl.bindTexture(gl.TEXTURE_2D, depthTexture.__webglTexture);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
//gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
//gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
//gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
//gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT, width, height, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_INT, null);
|
||||
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTexture.__webglTexture, 0);
|
||||
|
||||
renderer.setRenderTarget(null);
|
||||
}
|
||||
}
|
||||
|
||||
this.render = function(renderer){
|
||||
this.render = function(){
|
||||
|
||||
initEDL();
|
||||
|
||||
@ -1144,26 +1195,26 @@ var EDLRenderer = function(){
|
||||
vn.push(pointcloud.visibleNodes[i].node);
|
||||
}
|
||||
|
||||
{// DEPTH PASS
|
||||
depthMaterial.size = pointSize;
|
||||
depthMaterial.pointSizeType = pointSizeType;
|
||||
depthMaterial.screenWidth = width;
|
||||
depthMaterial.screenHeight = height;
|
||||
depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.size().x;
|
||||
depthMaterial.fov = camera.fov * (Math.PI / 180);
|
||||
depthMaterial.spacing = pointcloud.pcoGeometry.spacing;
|
||||
depthMaterial.near = camera.near;
|
||||
depthMaterial.far = camera.far;
|
||||
depthMaterial.heightMin = heightMin;
|
||||
depthMaterial.heightMax = heightMax;
|
||||
depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.size().x;
|
||||
pointcloud.updateVisibilityTexture(depthMaterial, vn);
|
||||
|
||||
scenePointCloud.overrideMaterial = depthMaterial;
|
||||
renderer.clearTarget( rtDepth, true, true, true );
|
||||
renderer.render(scenePointCloud, camera, rtDepth);
|
||||
scenePointCloud.overrideMaterial = null;
|
||||
}
|
||||
//{// DEPTH PASS
|
||||
// depthMaterial.size = pointSize;
|
||||
// depthMaterial.pointSizeType = pointSizeType;
|
||||
// depthMaterial.screenWidth = width;
|
||||
// depthMaterial.screenHeight = height;
|
||||
// depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.size().x;
|
||||
// depthMaterial.fov = camera.fov * (Math.PI / 180);
|
||||
// depthMaterial.spacing = pointcloud.pcoGeometry.spacing;
|
||||
// depthMaterial.near = camera.near;
|
||||
// depthMaterial.far = camera.far;
|
||||
// depthMaterial.heightMin = heightMin;
|
||||
// depthMaterial.heightMax = heightMax;
|
||||
// depthMaterial.uniforms.octreeSize.value = pointcloud.pcoGeometry.boundingBox.size().x;
|
||||
// pointcloud.updateVisibilityTexture(depthMaterial, vn);
|
||||
//
|
||||
// scenePointCloud.overrideMaterial = depthMaterial;
|
||||
// renderer.clearTarget( rtDepth, true, true, true );
|
||||
// renderer.render(scenePointCloud, camera, rtDepth);
|
||||
// scenePointCloud.overrideMaterial = null;
|
||||
//}
|
||||
|
||||
{// ATTRIBUTE PASS
|
||||
attributeMaterial.size = pointSize;
|
||||
@ -1182,8 +1233,8 @@ var EDLRenderer = function(){
|
||||
pointcloud.updateVisibilityTexture(attributeMaterial, vn);
|
||||
|
||||
scenePointCloud.overrideMaterial = attributeMaterial;
|
||||
renderer.clearTarget( rtNormalize, true, true, true );
|
||||
renderer.render(scenePointCloud, camera, rtNormalize);
|
||||
renderer.clearTarget( rtColor, true, true, true );
|
||||
renderer.render(scenePointCloud, camera, rtColor);
|
||||
scenePointCloud.overrideMaterial = null;
|
||||
}
|
||||
|
||||
@ -1192,9 +1243,17 @@ var EDLRenderer = function(){
|
||||
edlMaterial.uniforms.screenHeight.value = height;
|
||||
edlMaterial.uniforms.near.value = camera.near;
|
||||
edlMaterial.uniforms.far.value = camera.far;
|
||||
edlMaterial.uniforms.depthMap.value = rtDepth;
|
||||
edlMaterial.uniforms.colorMap.value = rtNormalize;
|
||||
edlMaterial.uniforms.colorMap.value = rtColor;
|
||||
edlMaterial.uniforms.expScale.value = camera.far;
|
||||
|
||||
//edlMaterial.uniforms.depthMap.value = rtDepth;
|
||||
//edlMaterial.uniforms.depthPassMap.value = rtDepth;
|
||||
edlMaterial.uniforms.depthMap.value = depthTexture;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
renderer.clearTarget( rtOcclusion, true, true, true );
|
||||
Potree.utils.screenPass.render(renderer, edlMaterial);
|
||||
|
||||
@ -84,11 +84,11 @@
|
||||
path: "http://localhost/dev/pointclouds/pix4d/lausanne_converted/cloud.js",
|
||||
path: "http://localhost/dev/pointclouds/3dlasermapping/Whitby_sample_GeoM.las_converted/cloud.js",
|
||||
path: "http://localhost/dev/pointclouds/bruno_friedmann/vol_total/vol_total/cloud.js",
|
||||
path: "../resources/pointclouds/lion_takanawa/cloud.js",
|
||||
path: "http://localhost/dev/pointclouds/g4d/04_centrum_high_vyber5m_ijk.ply_converted/cloud.js",
|
||||
path: "http://5.9.65.151/mschuetz/potree/users/archpro/heidentor/resources/pointclouds/heidentor.laz/cloud.js",
|
||||
path: "http://5.9.65.151/mschuetz/potree/resources/pointclouds/pix4d/matterhorn/resources/pointclouds/matterhorn.laz/cloud.js",
|
||||
path: "http://ahn2.pointclouds.nl/potree_data/tile_all/cloud.js",
|
||||
path: "../resources/pointclouds/lion_takanawa/cloud.js",
|
||||
path: "http://5.9.65.151/mschuetz/potree/test/cloud.js",
|
||||
cameraPosition: null, // options: cameraPosition: [10,10,10],
|
||||
cameraTarget: null, // options: cameraTarget: [0,0,0],
|
||||
|
||||
@ -32,6 +32,13 @@ float ztransform(float linearDepth){
|
||||
return 1.0 - (linearDepth - near) / (far - near);
|
||||
}
|
||||
|
||||
float expToLinear(float z){
|
||||
z = 2.0 * z - 1.0;
|
||||
float linear = (2.0 * near * far) / (far + near - z * (far - near));
|
||||
|
||||
return linear;
|
||||
}
|
||||
|
||||
float obscurance(float z, float dist){
|
||||
return max(0.0, z) / dist;
|
||||
}
|
||||
@ -46,9 +53,10 @@ float computeObscurance(float linearDepth, float scale){
|
||||
vec2 N_abs_pos = vUv + N_rel_pos;
|
||||
|
||||
vec4 neighbourDepth = texture2D(depthMap, N_abs_pos);
|
||||
float linearNeighbourDepth = expToLinear(neighbourDepth.r);
|
||||
|
||||
if(neighbourDepth.w > 0.0){
|
||||
float Zn = ztransform(neighbourDepth.r);
|
||||
float Zn = ztransform(linearNeighbourDepth);
|
||||
float Znp = dot( vec4( N_rel_pos, Zn, 1.0), P );
|
||||
|
||||
sum += obscurance( Znp, 0.1 * linearDepth );
|
||||
@ -59,12 +67,14 @@ float computeObscurance(float linearDepth, float scale){
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec4 color = texture2D(colorMap, vUv);
|
||||
|
||||
float linearDepth = texture2D(depthMap, vUv).r;
|
||||
float expDepth = texture2D(depthMap, vUv).r;
|
||||
float linearDepth = expToLinear(expDepth);
|
||||
|
||||
float f = computeObscurance(linearDepth, pixScale);
|
||||
f = exp(-expScale * f);
|
||||
|
||||
vec4 color = texture2D(colorMap, vUv);
|
||||
if(color.a == 0.0 && f >= 1.0){
|
||||
discard;
|
||||
}
|
||||
|
||||
@ -217,6 +217,8 @@ void main() {
|
||||
vOpacity = opacity;
|
||||
vLinearDepth = -mvPosition.z;
|
||||
vNormal = normalize(normalMatrix * normal);
|
||||
|
||||
//gl_Position.z = ((vLinearDepth - near) / (far - near)) * 2.0 - 1.0;
|
||||
|
||||
|
||||
// ---------------------
|
||||
@ -231,7 +233,7 @@ void main() {
|
||||
vColor = texture2D(gradient, vec2(w,1.0-w)).rgb;
|
||||
#elif defined color_type_depth
|
||||
float linearDepth = -mvPosition.z ;
|
||||
float expDepth = gl_Position.z / gl_Position.w;
|
||||
float expDepth = (gl_Position.z / gl_Position.w) * 0.5 + 0.5;
|
||||
vColor = vec3(linearDepth, expDepth, 0.0);
|
||||
#elif defined color_type_intensity
|
||||
float w = (intensity - intensityMin) / (intensityMax - intensityMin);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user