Merge pull request #60 from potree/high_quality
added high quality interpolation material
This commit is contained in:
commit
895db20405
@ -52,6 +52,7 @@
|
||||
<script src="../libs/proj4/proj4.js"></script>
|
||||
|
||||
<script src="../build/js/potree.js"></script>
|
||||
<script src="../src/materials/PointCloudRGBInterpolationMaterial.js"></script>
|
||||
|
||||
<title>Georeferencing Example</title>
|
||||
</head>
|
||||
@ -79,7 +80,7 @@
|
||||
<script type="text/javascript">
|
||||
|
||||
var pointcloudPath = "../resources/pointclouds/vol_total/cloud.js";
|
||||
var defaultPointSize = 3;
|
||||
var defaultPointSize = 4;
|
||||
var defaultLOD = 17;
|
||||
|
||||
// add EPSG:21781 to the proj4 projection database
|
||||
@ -228,6 +229,8 @@
|
||||
controls.moveSpeed *= 10;
|
||||
|
||||
materials.rgb = new Potree.PointCloudRGBMaterial({ size: defaultPointSize});
|
||||
materials.rgbInterpolated = new Potree.PointCloudRGBInterpolationMaterial({ size: defaultPointSize});
|
||||
materials.height = new Potree.PointCloudHeightMaterial({size: defaultPointSize, min: 0, max: 60});
|
||||
|
||||
// load pointcloud
|
||||
var pco = POCLoader.load(pointcloudPath, {toOrigin: true});
|
||||
@ -275,7 +278,8 @@
|
||||
var params = {
|
||||
PointSize: defaultPointSize,
|
||||
LOD: defaultLOD,
|
||||
"bounding box" : false
|
||||
"show octree" : false,
|
||||
"Materials" : materials.rgb
|
||||
};
|
||||
|
||||
var pLOD = gui.add(params, 'LOD', 0.5,20);
|
||||
@ -283,16 +287,40 @@
|
||||
pointcloud.LOD = value;
|
||||
});
|
||||
|
||||
var pPointSize = gui.add(params, 'PointSize', 0.01, 4.0);
|
||||
var pPointSize = gui.add(params, 'PointSize', 0.01, 6.0);
|
||||
pPointSize.onChange(function(value){
|
||||
pointcloud.material.size = value;
|
||||
});
|
||||
|
||||
var pMaterial = gui.add(params, 'Materials', [ "RGB", "RGB High Quality", "Height" ]);
|
||||
pMaterial.onChange(function(value){
|
||||
var size = pointcloud.material.size;
|
||||
if(value === "RGB"){
|
||||
pointcloud.material = materials.rgb;
|
||||
}else if(value === "RGB High Quality"){
|
||||
var frag_depth_ext = renderer.context.getExtension('EXT_frag_depth');
|
||||
if(!frag_depth_ext){
|
||||
var message = "failed to load EXT_frag_depth. This extension is required for the high quality shader.\n";
|
||||
message += "using standard RGB material instead";
|
||||
alert(message);
|
||||
pointcloud.material = materials.rgb;
|
||||
}else{
|
||||
pointcloud.material = materials.rgbInterpolated;
|
||||
}
|
||||
|
||||
}else if(value === "Height"){
|
||||
pointcloud.material = materials.height;
|
||||
}
|
||||
|
||||
pointcloud.material.size = size;
|
||||
|
||||
var pBoundingBox = gui.add(params, 'bounding box');
|
||||
console.log(value);
|
||||
});
|
||||
|
||||
var pBoundingBox = gui.add(params, 'show octree');
|
||||
pBoundingBox.onChange(function(value){
|
||||
pointcloud.showBoundingBox = value;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function update(){
|
||||
|
||||
@ -31,16 +31,22 @@
|
||||
<script src="../libs/other/dat.gui.min.js"></script>
|
||||
|
||||
<script src="../build/js/potree.min.js"></script>
|
||||
<script src="../src/materials/PointCloudRGBInterpolationMaterial.js"></script>
|
||||
<script src="../src/materials/PointCloudRGBMaterial.js"></script>
|
||||
|
||||
<div id="lblNumVisibleNodes" class="info" style="position: absolute; left: 10px; top: 80px; width: 400px; color:white"></div>
|
||||
<div id="lblNumVisiblePoints" class="info" style="position: absolute; left: 10px; top: 100px; width: 400px; color:white"></div>
|
||||
|
||||
<div class="info" style="position: absolute; left: 300px; right: 300px; top: 10px; text-align: center;">
|
||||
<a href="http://potree.org" target="_blank">potree.org</a><br>
|
||||
<br>
|
||||
The RGB High Quality shader interpolates between points, rather than rendering the nearest one.
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var defaultPointSize = 0.04;
|
||||
var defaultPointSize = 0.07;
|
||||
var defaultBlendDepth = 0.01;
|
||||
var defaultLOD = 15;
|
||||
var pointcloudPath = "../resources/pointclouds/lion_takanawa/cloud_bin.js";
|
||||
|
||||
@ -62,8 +68,9 @@
|
||||
|
||||
var params = {
|
||||
PointSize: defaultPointSize,
|
||||
BlendDepth: defaultBlendDepth,
|
||||
LOD: defaultLOD,
|
||||
"show aabb" : false,
|
||||
"show octree" : false,
|
||||
"Materials" : materials.rgb
|
||||
};
|
||||
|
||||
@ -72,16 +79,27 @@
|
||||
pointcloud.LOD = value;
|
||||
});
|
||||
|
||||
var pPointSize = gui.add(params, 'PointSize', 0.01, 0.1);
|
||||
var pPointSize = gui.add(params, 'PointSize', 0.01, 0.2);
|
||||
pPointSize.onChange(function(value){
|
||||
pointcloud.material.size = value;
|
||||
});
|
||||
|
||||
var pMaterial = gui.add(params, 'Materials', [ "RGB", "Color", "Height" ]);
|
||||
var pMaterial = gui.add(params, 'Materials', [ "RGB", "RGB High Quality", "Color", "Height" ]);
|
||||
pMaterial.onChange(function(value){
|
||||
var size = pointcloud.material.size;
|
||||
if(value === "RGB"){
|
||||
pointcloud.material = materials.rgb;
|
||||
}else if(value === "RGB High Quality"){
|
||||
var frag_depth_ext = renderer.context.getExtension('EXT_frag_depth');
|
||||
if(!frag_depth_ext){
|
||||
var message = "failed to load EXT_frag_depth. This extension is required for the high quality shader.\n";
|
||||
message += "using standard RGB material instead";
|
||||
alert(message);
|
||||
pointcloud.material = materials.rgb;
|
||||
}else{
|
||||
pointcloud.material = materials.rgbInterpolated;
|
||||
}
|
||||
|
||||
}else if(value === "Color"){
|
||||
pointcloud.material = materials.color;
|
||||
}else if(value === "Height"){
|
||||
@ -93,7 +111,7 @@
|
||||
console.log(value);
|
||||
});
|
||||
|
||||
var pBoundingBox = gui.add(params, 'show aabb');
|
||||
var pBoundingBox = gui.add(params, 'show octree');
|
||||
pBoundingBox.onChange(function(value){
|
||||
pointcloud.showBoundingBox = value;
|
||||
});
|
||||
@ -118,16 +136,16 @@
|
||||
skybox = Potree.utils.loadSkybox("../resources/textures/skybox/");
|
||||
|
||||
// camera and controls
|
||||
camera.position.set(5, 10, 15);
|
||||
camera.position.set(3, 7, 6);
|
||||
controls = new THREE.OrbitControls(camera, renderer.domElement);
|
||||
controls.target.set( 0, 4, 0 );
|
||||
controls.target.set( 0, 5, 0 );
|
||||
camera.lookAt(controls.target);
|
||||
|
||||
// materials
|
||||
materials.rgb = new Potree.PointCloudRGBMaterial({ size: defaultPointSize});
|
||||
materials.rgbInterpolated = new Potree.PointCloudRGBInterpolationMaterial({ size: defaultPointSize});
|
||||
materials.color = new Potree.PointCloudColorMaterial({size: defaultPointSize});
|
||||
materials.height = new Potree.PointCloudHeightMaterial({size: defaultPointSize, min: 0, max: 10});
|
||||
materials.height = new Potree.PointCloudHeightMaterial({size: defaultPointSize, min: 0, max: 10});
|
||||
materials.height = new Potree.PointCloudHeightMaterial({size: defaultPointSize, min: 2, max: 8});
|
||||
|
||||
// load pointcloud
|
||||
var pco = POCLoader.load(pointcloudPath, {toOrigin: true});
|
||||
|
||||
104
src/materials/PointCloudRGBInterpolationMaterial.js
Normal file
104
src/materials/PointCloudRGBInterpolationMaterial.js
Normal file
@ -0,0 +1,104 @@
|
||||
|
||||
Potree.PointCloudRGBInterpolationMaterial = function(parameters){
|
||||
parameters = parameters || {};
|
||||
|
||||
var attributes = {};
|
||||
var uniforms = {
|
||||
color: { type: "c", value: new THREE.Color( 0xffffff ) },
|
||||
size: { type: "f", value: 10 },
|
||||
blendDepth: { type: "f", value: 0.01 }
|
||||
};
|
||||
|
||||
var pointSize = parameters.size || 1.0;
|
||||
|
||||
var vs;
|
||||
var fs;
|
||||
var frag_depth_ext = renderer.context.getExtension('EXT_frag_depth');
|
||||
if(!frag_depth_ext){
|
||||
vs = Potree.PointCloudRGBMaterial.vs_points.join("\n");
|
||||
fs = Potree.PointCloudRGBMaterial.fs_points_rgb.join("\n");
|
||||
}else{
|
||||
vs = Potree.PointCloudRGBInterpolationMaterial.vs_points.join("\n");
|
||||
fs = Potree.PointCloudRGBInterpolationMaterial.fs_points_rgb.join("\n");
|
||||
}
|
||||
|
||||
this.setValues({
|
||||
uniforms: uniforms,
|
||||
attributes: attributes,
|
||||
vertexShader: vs,
|
||||
fragmentShader: fs,
|
||||
vertexColors: THREE.VertexColors,
|
||||
size: pointSize,
|
||||
alphaTest: 0.9,
|
||||
});
|
||||
};
|
||||
|
||||
Potree.PointCloudRGBInterpolationMaterial.prototype = new THREE.ShaderMaterial();
|
||||
|
||||
Object.defineProperty(Potree.PointCloudRGBInterpolationMaterial.prototype, "size", {
|
||||
get: function(){
|
||||
return this.uniforms.size.value;
|
||||
},
|
||||
set: function(value){
|
||||
this.uniforms.size.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Potree.PointCloudRGBInterpolationMaterial.prototype, "blendDepth", {
|
||||
get: function(){
|
||||
return this.uniforms.blendDepth.value;
|
||||
},
|
||||
set: function(value){
|
||||
this.uniforms.blendDepth.value = value;
|
||||
}
|
||||
});
|
||||
|
||||
Potree.PointCloudRGBInterpolationMaterial.vs_points = [
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
"uniform float size; ",
|
||||
"varying vec3 vColor; ",
|
||||
" ",
|
||||
"void main() { ",
|
||||
" vColor = color; ",
|
||||
" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); ",
|
||||
" ",
|
||||
" gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); ",
|
||||
" gl_PointSize = max(2.0, gl_PointSize); ",
|
||||
" gl_Position = projectionMatrix * mvPosition; ",
|
||||
"} "];
|
||||
|
||||
Potree.PointCloudRGBInterpolationMaterial.fs_points_rgb = [
|
||||
"#extension GL_EXT_frag_depth : enable ",
|
||||
"varying vec3 vColor; ",
|
||||
"uniform float blendDepth; ",
|
||||
" ",
|
||||
" ",
|
||||
"void main() { ",
|
||||
" ",
|
||||
" float a = pow(2.0*(gl_PointCoord.x - 0.5), 2.0); ",
|
||||
" float b = pow(2.0*(gl_PointCoord.y - 0.5), 2.0); ",
|
||||
" float c = 1.0 - (a + b); ",
|
||||
" ",
|
||||
" if(c < 0.0){ ",
|
||||
" discard; ",
|
||||
" } ",
|
||||
" ",
|
||||
" gl_FragColor = vec4(vColor, 1.0); ",
|
||||
" gl_FragDepthEXT = gl_FragCoord.z + blendDepth*(1.0-pow(c, 1.0)) * gl_FragCoord.w ; ",
|
||||
"} "];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user