This commit is contained in:
m-schuetz 2017-10-20 17:32:06 +02:00
parent ac3c1883ac
commit 64c53184b6
3 changed files with 102 additions and 32 deletions

View File

@ -1324,7 +1324,9 @@ Potree.Renderer = class{
let shadowMaps = params.shadowMaps == null ? [] : params.shadowMaps;
let view = camera.matrixWorldInverse;
let viewInv = camera.matrixWorld;
let proj = camera.projectionMatrix;
let projInv = new THREE.Matrix4().getInverse(camera.projectionMatrix);
let worldView = new THREE.Matrix4();
let material = octree.material;
@ -1413,6 +1415,8 @@ Potree.Renderer = class{
{ // UPDATE UNIFORMS
shader.setUniformMatrix4("projectionMatrix", proj);
shader.setUniformMatrix4("viewMatrix", view);
shader.setUniformMatrix4("uViewInv", viewInv);
shader.setUniformMatrix4("uProjInv", projInv);
shader.setUniform1f("screenHeight", material.screenHeight);
shader.setUniform1f("screenWidth", material.screenWidth);
@ -1488,44 +1492,39 @@ Potree.Renderer = class{
if(material.snapEnabled === true){
//let snapTexture = this.textures.get(material.uniforms.snapshot.value);
//let texture = material.uniforms.snapshot.value;
//let snapTexture = this.threeRenderer.properties.get(texture).__webglTexture;
//shader.setUniform1i("snapshot", 2);
//gl.activeTexture(gl.TEXTURE2);
//for(let i = 0; i < 5; i++){
// let texture = material.uniforms[`uSnapshot_${i}`].value;
//
// if(!texture){
// break;
// }
//
// let snapTexture = this.threeRenderer.properties.get(texture).__webglTexture;
//
// shader.setUniform1i(`uSnapshot_${i}`, 2 + i);
// gl.activeTexture(gl[`TEXTURE${2+i}`]);
// gl.bindTexture(gl.TEXTURE_2D, snapTexture);
//
// //shader.setUniformMatrix4(`uSnapView_${i}`, material.uniforms[`uSnapView_${i}`].value);
// //shader.setUniformMatrix4(`uSnapProj_${i}`, material.uniforms[`uSnapProj_${i}`].value);
//}
{
const lSnapshot = shader.uniformLocations["uSnapshot[0]"];
gl.uniform1iv(lSnapshot, new Array(5).fill(0).map( (a, i) => (2 + i)));
const lSnapshotDepth = shader.uniformLocations["uSnapshotDepth[0]"];
let bindingStart = 2;
let lSnapshotBindingPoints = new Array(5).fill(bindingStart).map( (a, i) => (a + i));
let lSnapshotDepthBindingPoints = new Array(5)
.fill(1 + Math.max(...lSnapshotBindingPoints))
.map( (a, i) => (a + i));
gl.uniform1iv(lSnapshot, lSnapshotBindingPoints);
gl.uniform1iv(lSnapshotDepth, lSnapshotDepthBindingPoints);
for(let i = 0; i < 5; i++){
let texture = material.uniforms[`uSnapshot`].value[i];
let textureDepth = material.uniforms[`uSnapshotDepth`].value[i];
if(!texture){
break;
}
let snapTexture = this.threeRenderer.properties.get(texture).__webglTexture;
let snapTextureDepth = this.threeRenderer.properties.get(textureDepth).__webglTexture;
gl.activeTexture(gl[`TEXTURE${2+i}`]);
let bindingPoint = lSnapshotBindingPoints[i];
let depthBindingPoint = lSnapshotDepthBindingPoints[i];
gl.activeTexture(gl[`TEXTURE${bindingPoint}`]);
gl.bindTexture(gl.TEXTURE_2D, snapTexture);
gl.activeTexture(gl[`TEXTURE${depthBindingPoint}`]);
gl.bindTexture(gl.TEXTURE_2D, snapTextureDepth);
}
}

View File

@ -7,6 +7,8 @@ precision mediump int;
#endif
uniform mat4 viewMatrix;
uniform mat4 uViewInv;
uniform mat4 uProjInv;
uniform vec3 cameraPosition;
@ -42,6 +44,7 @@ uniform mat4 uSnapViewInv[max_snapshots];
varying vec4 vSP;
varying float vPointSize;
varying vec3 vPosition;
varying vec4 vSnapProjected[max_snapshots];
@ -56,6 +59,7 @@ void main() {
#if defined(snap_enabled)
//vec2 uv = 0.5 * (vSP.xy / vSP.w) + 0.5;
/*
vec2 pc = vec2(gl_PointCoord.x - 0.5, (1.0 - gl_PointCoord.y) - 0.5);
vec2 offset = (pc * vPointSize) / vec2(screenWidth, screenHeight);
@ -65,14 +69,76 @@ void main() {
for(int i = 0; i < max_snapshots; i++){
vec2 uv = 0.5 * (vSnapProjected[i].xy /vSnapProjected[i].w) + 0.5 + offset;
vec4 tc = texture2D(uSnapshot[i], uv);
vec4 td = texture2D(uSnapshotDepth[i], uv);
vec4 tmp = uSnapProjInv[i] * vec4(uv * 2.0 - 1.0, td.r, 1.0);
tmp = tmp / tmp.w;
tmp = viewMatrix * uSnapViewInv[i] * tmp;
if(tc.a > 0.0){
sRGB += tc.rgb;
//sRGB += tc.rgb;
//sRGB += vec3(1.0, 1.0, 1.0) * td.r;
sRGB += tmp.rgb;
sA += tc.a;
}
}
color = sRGB * 0.5;
*/
vec3 sRGB = vec3(0.0, 0.0, 0.0);
float sA = 0.0;
for(int i = 0; i < max_snapshots; i++){
//{
//const int i = 1;
float snapLinearDistance = 0.0;
float currentLinearDistance = 0.0;
vec4 col;
{
vec2 pc = vec2(gl_PointCoord.x - 0.5, (1.0 - gl_PointCoord.y) - 0.5);
vec2 offset = (pc * vPointSize) / vec2(screenWidth, screenHeight);
vec2 uv = 0.5 * (vSnapProjected[i].xy /vSnapProjected[i].w) + 0.5 + offset;
col = texture2D(uSnapshot[i], uv);
vec4 td = texture2D(uSnapshotDepth[i], uv);
float d = td.r;
vec4 snapViewPos = uSnapProjInv[i] * vec4(uv * 2.0 - 1.0, d * 2.0 - 1.0, 1.0);
snapViewPos = snapViewPos / snapViewPos.w;
snapLinearDistance = -snapViewPos.z;
}
{
vec4 currentViewPos = uSnapProjInv[i] * vSnapProjected[i];
currentLinearDistance = -currentViewPos.z;
}
//if(abs(currentLinearDistance - snapLinearDistance) > 0.2){
// color = vec3(1.0, 0.0, 0.0);
//}
if(abs(currentLinearDistance - snapLinearDistance) < vRadius * 2.0){
sRGB += col.rgb;
if(col.a != 0.0){
sA = sA + 1.0;
}
//sA += col.a;
}
}
color = sRGB / sA;
if(sA == 0.0){
discard;
}
//color = vec3(1.0, 1.0, 1.0) * sA * 0.5;
#endif

View File

@ -87,7 +87,6 @@ class RepRenderer {
// https://github.com/mrdoob/three.js/pull/6355
if (needsResize) {
this.rtColor.dispose();
this.snap.target.dispose();
}
viewer.scene.cameraP.aspect = aspect;
@ -106,7 +105,6 @@ class RepRenderer {
viewer.renderer.setSize(width, height);
this.rtColor.setSize(width, height);
this.snap.target.setSize(width, height);
}
makeSnapshot(){
@ -176,7 +174,10 @@ class RepRenderer {
//viewer.pRenderer.render(viewer.scene.scenePointCloud, viewer.shadowTestCam, this.rtShadow);
{ // NEW SNAPSHOT
//if(this.snapshotRequested){ // NEW SNAPSHOT
//if(performance.now() < 2000 || this.snapshotRequested){
{
this.snapshotRequested = false;
let snap;
if(this.history.snapshots.length < this.history.maxSnapshots){
@ -187,8 +188,8 @@ class RepRenderer {
format: THREE.RGBAFormat,
type: THREE.FloatType
});
//snap.target.depthTexture = new THREE.DepthTexture();
//snap.target.depthTexture.type = THREE.UnsignedIntType;
snap.target.depthTexture = new THREE.DepthTexture();
snap.target.depthTexture.type = THREE.UnsignedIntType;
}else{
snap = this.history.snapshots.pop();
}
@ -217,6 +218,10 @@ class RepRenderer {
let from = this.history.version * (octree.visibleNodes.length / this.history.maxSnapshots);
let to = (this.history.version + 1) * (octree.visibleNodes.length / this.history.maxSnapshots);
// DEBUG!!!
//let from = 0;
//let to = 20;
let nodes = octree.visibleNodes.slice(from, to);
viewer.pRenderer.renderOctree(octree, nodes, camera, snap.target, {vnTextureNodes: nodes});
@ -241,14 +246,14 @@ class RepRenderer {
let uniforms = octree.material.uniforms;
if(this.history.snapshots.length === this.history.maxSnapshots){
uniforms[`uSnapshot`].value = this.history.snapshots.map(s => s.target.texture);
uniforms[`uSnapshot`].value = this.history.snapshots.map(s => s.target.texture);
uniforms[`uSnapshotDepth`].value = this.history.snapshots.map(s => s.target.depthTexture);
uniforms[`uSnapView`].value = this.history.snapshots.map(s => s.camera.matrixWorldInverse);
uniforms[`uSnapProj`].value = this.history.snapshots.map(s => s.camera.projectionMatrix);
uniforms[`uSnapProjInv`].value = this.history.snapshots.map(s => new THREE.Matrix4().getInverse(s.camera.projectionMatrix));
uniforms[`uSnapViewInv`].value = this.history.snapshots.map(s => new THREE.Matrix4().getInverse(s.camera.matrixWorld));
}
let nodes = octree.visibleNodes.slice(0, 10);
let nodes = octree.visibleNodes.slice(0, 5);
//let nodes = octree.visibleNodes;
viewer.pRenderer.renderOctree(octree, nodes, camera, this.rtColor, {vnTextureNodes: nodes});
}