fixed adaptive point size with orthographic cameras

This commit is contained in:
Lukas Gersthofer 2017-05-23 11:45:24 +02:00
parent 4df3c4c86f
commit 48f9247e68
3 changed files with 20 additions and 7 deletions

View File

@ -169,7 +169,8 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
wClassification: { type: "f", value: 0 },
wReturnNumber: { type: "f", value: 0 },
wSourceID: { type: "f", value: 0 },
useOrthographicCamera: { type: "b", value: false }
useOrthographicCamera: { type: "b", value: false },
orthoRange: { type: "f", value: 10.0 }
};
this.defaultAttributeValues.normal = [0,0,0];
@ -463,6 +464,17 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
}
get orthoRange(){
return this.uniforms.orthoRange.value;
}
set orthoRange(value){
if(this.uniforms.orthoRange.value !== value){
this.uniforms.orthoRange.value = value;
}
}
get opacity(){
return this.uniforms.opacity.value;
}

View File

@ -31,6 +31,7 @@ uniform float fov;
uniform float spacing;
uniform float near;
uniform float far;
uniform float orthoRange;
#if defined use_clip_box
uniform mat4 clipBoxes[max_clip_boxes];
@ -390,12 +391,7 @@ void main() {
pointSize = pointSize * projFactor;
#elif defined adaptive_point_size
if(useOrthographicCamera) {
/*vec3 p1 = (projectionMatrix * vec4(0, 0, 0, 1)).xyz;
vec3 p2 = (projectionMatrix * vec4(r, 0, 0, 1)).xyz;
float projSpacing = length(p2 - p1);
projSpacing = (projSpacing + 1.0) * 0.5 * screenWidth;*/
// TODO ortho
pointSize = size * r / pow(2.0, getLOD());
pointSize = size * r / (orthoRange * pow(2.0, getLOD())) * screenWidth;
} else {
float worldSpaceSize = size * r / getPointSizeAttenuation();
pointSize = worldSpaceSize * projFactor;

View File

@ -1597,6 +1597,11 @@ class PotreeRenderer{
viewer.scene.cameraO.top = frustumScale * 1/aspect;
viewer.scene.cameraO.bottom = -frustumScale * 1/aspect;
viewer.scene.cameraO.updateProjectionMatrix();
// update frustum size for adaptive point size with ortho cameras
for(let pointcloud of viewer.scene.pointclouds){
pointcloud.material.orthoRange = 2.0 * frustumScale;
}
viewer.renderer.setSize(width, height);
}