de-unrolling
This commit is contained in:
parent
7226636d12
commit
ea973bd8d5
@ -1353,7 +1353,9 @@ Potree.Renderer = class{
|
||||
if (material.pointSizeType >= 0) {
|
||||
if (material.pointSizeType === Potree.PointSizeType.ADAPTIVE ||
|
||||
material.pointColorType === Potree.PointColorType.LOD) {
|
||||
visibilityTextureData = octree.computeVisibilityTextureData(nodes);
|
||||
|
||||
let vnNodes = (params.vnTextureNodes != null) ? params.vnTextureNodes : nodes;
|
||||
visibilityTextureData = octree.computeVisibilityTextureData(vnNodes);
|
||||
|
||||
const vnt = material.visibleNodesTexture;
|
||||
const data = vnt.image.data;
|
||||
@ -1487,19 +1489,57 @@ 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);
|
||||
//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);
|
||||
//}
|
||||
|
||||
//let gradientTexture = this.textures.get(material.gradientTexture);
|
||||
gl.bindTexture(gl.TEXTURE_2D, snapTexture);
|
||||
{
|
||||
const lSnapshot = shader.uniformLocations["uSnapshot[0]"];
|
||||
gl.uniform1iv(lSnapshot, new Array(5).fill(0).map( (a, i) => (2 + i)));
|
||||
|
||||
for(let i = 0; i < 5; i++){
|
||||
let texture = material.uniforms[`uSnapshot`].value[i];
|
||||
|
||||
if(!texture){
|
||||
break;
|
||||
}
|
||||
|
||||
let snapTexture = this.threeRenderer.properties.get(texture).__webglTexture;
|
||||
|
||||
gl.activeTexture(gl[`TEXTURE${2+i}`]);
|
||||
gl.bindTexture(gl.TEXTURE_2D, snapTexture);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let flattenedMatrices = [].concat(...material.uniforms.uSnapView.value.map(c => c.elements));
|
||||
const lSnapView = shader.uniformLocations["uSnapView[0]"];
|
||||
gl.uniformMatrix4fv(lSnapView, false, flattenedMatrices);
|
||||
}
|
||||
{
|
||||
let flattenedMatrices = [].concat(...material.uniforms.uSnapProj.value.map(c => c.elements));
|
||||
const lSnapProj = shader.uniformLocations["uSnapProj[0]"];
|
||||
gl.uniformMatrix4fv(lSnapProj, false, flattenedMatrices);
|
||||
}
|
||||
|
||||
shader.setUniformMatrix4("snapView", material.uniforms.snapView.value);
|
||||
shader.setUniformMatrix4("snapProj", material.uniforms.snapProj.value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -267,9 +267,9 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
|
||||
useOrthographicCamera: { type: "b", value: false },
|
||||
orthoRange: { type: "f", value: 10.0 },
|
||||
clipMode: { type: "i", value: 1},
|
||||
snapshot: { type: "t", value: null},
|
||||
snapView: { type: "Matrix4f", value: []},
|
||||
snapProj: { type: "Matrix4f", value: []},
|
||||
uSnapshot: { type: "tv", value: []},
|
||||
uSnapView: { type: "Matrix4fv", value: []},
|
||||
uSnapProj: { type: "Matrix4fv", value: []},
|
||||
};
|
||||
|
||||
this.defaultAttributeValues.normal = [0, 0, 0];
|
||||
|
||||
@ -30,15 +30,18 @@ varying float vLogDepth;
|
||||
varying vec3 vViewPosition;
|
||||
varying float vRadius;
|
||||
|
||||
#define max_snapshots 5
|
||||
#if defined(snap_enabled)
|
||||
uniform sampler2D snapshot;
|
||||
uniform mat4 snapView;
|
||||
uniform mat4 snapProj;
|
||||
uniform sampler2D uSnapshot[max_snapshots];
|
||||
uniform mat4 uSnapView[max_snapshots];
|
||||
uniform mat4 uSnapProj[max_snapshots];
|
||||
#endif
|
||||
|
||||
varying vec4 vSP;
|
||||
varying float vPointSize;
|
||||
|
||||
varying vec4 vSnapProjected[max_snapshots];
|
||||
|
||||
float specularStrength = 1.0;
|
||||
|
||||
void main() {
|
||||
@ -48,7 +51,7 @@ void main() {
|
||||
|
||||
|
||||
#if defined(snap_enabled)
|
||||
vec2 uv = 0.5 * (vSP.xy / vSP.w) + 0.5;
|
||||
//vec2 uv = 0.5 * (vSP.xy / vSP.w) + 0.5;
|
||||
|
||||
vec2 pc = vec2(
|
||||
gl_PointCoord.x - 0.5,
|
||||
@ -56,15 +59,56 @@ void main() {
|
||||
);
|
||||
vec2 offset = (pc * vPointSize) / vec2(screenWidth, screenHeight);
|
||||
|
||||
uv = uv + offset;
|
||||
vec2 uv0 = 0.5 * (vSnapProjected[0].xy /vSnapProjected[0].w) + 0.5 + offset;
|
||||
vec2 uv1 = 0.5 * (vSnapProjected[1].xy /vSnapProjected[1].w) + 0.5 + offset;
|
||||
vec2 uv2 = 0.5 * (vSnapProjected[2].xy /vSnapProjected[2].w) + 0.5 + offset;
|
||||
vec2 uv3 = 0.5 * (vSnapProjected[3].xy /vSnapProjected[3].w) + 0.5 + offset;
|
||||
vec2 uv4 = 0.5 * (vSnapProjected[4].xy /vSnapProjected[4].w) + 0.5 + offset;
|
||||
|
||||
vec4 tc = texture2D(snapshot, uv);
|
||||
color = tc.rgb;
|
||||
vec4 tc_0 = texture2D(uSnapshot[0], uv0);
|
||||
vec4 tc_1 = texture2D(uSnapshot[1], uv1);
|
||||
vec4 tc_2 = texture2D(uSnapshot[2], uv2);
|
||||
vec4 tc_3 = texture2D(uSnapshot[3], uv3);
|
||||
vec4 tc_4 = texture2D(uSnapshot[4], uv4);
|
||||
|
||||
if(tc.a == 0.0){
|
||||
discard;
|
||||
return;
|
||||
//color = ((tc_0 + tc_1 + tc_2 + tc_3 + tc_4) / 5.0).rgb;
|
||||
//color = ((tc_0 + tc_1 + tc_2 + tc_3) / 4.0).rgb;
|
||||
//color = (tc_0.rgb + tc_1.rgb + tc_2.rgb + tc_3.rgb + tc_4.rgb) / 5.0;
|
||||
|
||||
vec3 sRGB = vec3(0.0, 0.0, 0.0);
|
||||
float sA = 0.0;
|
||||
|
||||
if(tc_0.a > 0.0){
|
||||
sRGB += tc_0.rgb;
|
||||
sA += tc_0.a;
|
||||
}
|
||||
if(tc_1.a > 0.0){
|
||||
sRGB += tc_1.rgb;
|
||||
sA += tc_1.a;
|
||||
}
|
||||
if(tc_2.a > 0.0){
|
||||
sRGB += tc_2.rgb;
|
||||
sA += tc_2.a;
|
||||
}
|
||||
if(tc_3.a > 0.0){
|
||||
sRGB += tc_3.rgb;
|
||||
sA += tc_3.a;
|
||||
}
|
||||
if(tc_4.a > 0.0){
|
||||
sRGB += tc_4.rgb;
|
||||
sA += tc_4.a;
|
||||
}
|
||||
|
||||
//color = sRGB / sA;
|
||||
color = sRGB * 0.5;
|
||||
|
||||
|
||||
//color = tc.rgb;
|
||||
|
||||
//if(tc.a == 0.0){
|
||||
// discard;
|
||||
// return;
|
||||
//}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@ -79,10 +79,16 @@ uniform sampler2D classificationLUT;
|
||||
uniform bool useShadowMap;
|
||||
uniform mat4 smWorldViewProj;
|
||||
|
||||
#define max_snapshots 5
|
||||
#if defined(snap_enabled)
|
||||
uniform sampler2D snapshot;
|
||||
uniform mat4 snapView;
|
||||
uniform mat4 snapProj;
|
||||
uniform sampler2D uSnapshot_0;
|
||||
uniform sampler2D uSnapshot_1;
|
||||
uniform sampler2D uSnapshot_2;
|
||||
uniform sampler2D uSnapshot_3;
|
||||
uniform sampler2D uSnapshot_4;
|
||||
|
||||
uniform mat4 uSnapView[max_snapshots];
|
||||
uniform mat4 uSnapProj[max_snapshots];
|
||||
#endif
|
||||
|
||||
varying float vOpacity;
|
||||
@ -95,6 +101,7 @@ varying vec3 vWorldPosition;
|
||||
varying vec4 vSP;
|
||||
varying float vPointSize;
|
||||
|
||||
varying vec4 vSnapProjected[max_snapshots];
|
||||
|
||||
// ---------------------
|
||||
// OCTREE
|
||||
@ -529,20 +536,15 @@ void main() {
|
||||
|
||||
|
||||
#if defined(snap_enabled)
|
||||
//vColor = vec3(1.0, 0.0, 0.0);
|
||||
//vec4 snapPos = snapProj * snapView * modelMatrix * vec4( position, 1.0 );
|
||||
//vec2 uv = (snapPos.xy / snapPos.w) * 0.5 + 0.5;
|
||||
//vec4 c = texture2D(snapshot, uv);
|
||||
//vColor = vec3(c.rgb);
|
||||
|
||||
|
||||
vec4 sp = snapProj * snapView * modelMatrix * vec4(position, 1.0);
|
||||
vec2 uv = 0.5 * (sp.xy / sp.w) + 0.5;
|
||||
vec4 col = texture2D(snapshot, uv);
|
||||
vColor = col.rgb;
|
||||
|
||||
vSP = sp;
|
||||
//vColor = vec3(uv, 0.0);
|
||||
for(int i = 0; i < 5; i++){
|
||||
vSnapProjected[i] = uSnapProj[i] * uSnapView[i] * modelMatrix * vec4(position, 1.0);
|
||||
}
|
||||
//vSnapProjected[0] = uSnapProj[0] * uSnapView[0] * modelMatrix * vec4(position, 1.0);
|
||||
//vSnapProjected[1] = uSnapProj[1] * uSnapView[1] * modelMatrix * vec4(position, 1.0);
|
||||
//vSnapProjected[2] = uSnapProj[2] * uSnapView[2] * modelMatrix * vec4(position, 1.0);
|
||||
//vSnapProjected[3] = uSnapProj[3] * uSnapView[3] * modelMatrix * vec4(position, 1.0);
|
||||
//vSnapProjected[4] = uSnapProj[4] * uSnapView[4] * modelMatrix * vec4(position, 1.0);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1,4 +1,12 @@
|
||||
|
||||
class RepSnapshot{
|
||||
|
||||
constructor(){
|
||||
this.target = null;
|
||||
this.camera = null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class RepRenderer {
|
||||
constructor (viewer) {
|
||||
@ -21,8 +29,10 @@ class RepRenderer {
|
||||
matrix: null
|
||||
};
|
||||
|
||||
this.aug = {
|
||||
|
||||
this.history = {
|
||||
maxSnapshots: 5,
|
||||
snapshots: [],
|
||||
version: 0
|
||||
};
|
||||
|
||||
}
|
||||
@ -64,14 +74,15 @@ class RepRenderer {
|
||||
this.snap.target.generateMipMaps = false;
|
||||
|
||||
|
||||
//{
|
||||
// let geometry = new THREE.PlaneBufferGeometry( 10, 7, 32 );
|
||||
// let material = new THREE.MeshBasicMaterial( {side: THREE.DoubleSide, map: this.snap.target.texture} );
|
||||
// let plane = new THREE.Mesh( geometry, material );
|
||||
// plane.position.z = 0.2;
|
||||
// plane.position.y = -1;
|
||||
// this.viewer.scene.scene.add( plane );
|
||||
//}
|
||||
{
|
||||
let geometry = new THREE.PlaneBufferGeometry( 20, 20, 32 );
|
||||
let material = new THREE.MeshBasicMaterial( {side: THREE.DoubleSide, map: this.snap.target.texture} );
|
||||
let plane = new THREE.Mesh( geometry, material );
|
||||
plane.position.z = 0.2;
|
||||
plane.position.y = -1;
|
||||
this.viewer.scene.scene.add( plane );
|
||||
this.debugPlane = plane;
|
||||
}
|
||||
};
|
||||
|
||||
resize () {
|
||||
@ -175,17 +186,71 @@ class RepRenderer {
|
||||
//viewer.pRenderer.render(viewer.scene.scenePointCloud, viewer.shadowTestCam, this.rtShadow);
|
||||
|
||||
|
||||
if(this.snapshotRequested || !this.snap.camera){
|
||||
viewer.renderer.clearTarget(this.snap.target, true, true, true);
|
||||
viewer.renderer.setRenderTarget(this.snap.target);
|
||||
camera.updateProjectionMatrix();
|
||||
this.snap.camera = camera.clone();
|
||||
//if(this.snapshotRequested || !this.snap.camera){
|
||||
// viewer.renderer.clearTarget(this.snap.target, true, true, true);
|
||||
// viewer.renderer.setRenderTarget(this.snap.target);
|
||||
// camera.updateProjectionMatrix();
|
||||
// this.snap.camera = camera.clone();
|
||||
// for(const octree of viewer.scene.pointclouds){
|
||||
// octree.material.snapEnabled = false;
|
||||
// octree.material.needsUpdate = true;
|
||||
// viewer.pRenderer.renderOctree(octree, octree.visibleNodes, camera, this.snap.target, {});
|
||||
// }
|
||||
// this.snapshotRequested = false;
|
||||
//}
|
||||
|
||||
{ // NEW SNAPSHOT
|
||||
|
||||
let snap;
|
||||
if(this.history.snapshots.length < this.history.maxSnapshots){
|
||||
snap = new RepSnapshot();
|
||||
snap.target = new THREE.WebGLRenderTarget(1024, 1024, {
|
||||
minFilter: THREE.NearestFilter,
|
||||
magFilter: THREE.NearestFilter,
|
||||
format: THREE.RGBAFormat,
|
||||
type: THREE.FloatType
|
||||
});
|
||||
}else{
|
||||
snap = this.history.snapshots.pop();
|
||||
}
|
||||
|
||||
{ // resize
|
||||
let width = viewer.scaleFactor * viewer.renderArea.clientWidth;
|
||||
let height = viewer.scaleFactor * viewer.renderArea.clientHeight;
|
||||
let aspect = width / height;
|
||||
|
||||
let needsResize = (snap.target.width !== width || snap.target.height !== height);
|
||||
|
||||
if (needsResize) {
|
||||
snap.target.dispose();
|
||||
}
|
||||
|
||||
snap.target.setSize(width, height);
|
||||
}
|
||||
|
||||
viewer.renderer.clearTarget(snap.target, true, true, true);
|
||||
viewer.renderer.setRenderTarget(snap.target);
|
||||
|
||||
for(const octree of viewer.scene.pointclouds){
|
||||
|
||||
octree.material.snapEnabled = false;
|
||||
octree.material.needsUpdate = true;
|
||||
viewer.pRenderer.renderOctree(octree, octree.visibleNodes, camera, this.snap.target, {});
|
||||
|
||||
let from = this.history.version * (octree.visibleNodes.length / this.history.maxSnapshots);
|
||||
let to = (this.history.version + 1) * (octree.visibleNodes.length / this.history.maxSnapshots);
|
||||
let nodes = octree.visibleNodes.slice(from, to);
|
||||
|
||||
viewer.pRenderer.renderOctree(octree, nodes, camera, snap.target, {vnTextureNodes: nodes});
|
||||
}
|
||||
this.snapshotRequested = false;
|
||||
|
||||
snap.camera = camera.clone();
|
||||
this.history.version = (this.history.version + 1) % this.history.maxSnapshots;
|
||||
|
||||
if(this.debugPlane){
|
||||
this.debugPlane.material.map = snap.target.texture;
|
||||
}
|
||||
|
||||
this.history.snapshots.unshift(snap);
|
||||
}
|
||||
|
||||
viewer.renderer.clearTarget(this.rtColor, true, true, true);
|
||||
@ -193,13 +258,25 @@ class RepRenderer {
|
||||
for(const octree of viewer.scene.pointclouds){
|
||||
octree.material.snapEnabled = true;
|
||||
octree.material.needsUpdate = true;
|
||||
octree.material.uniforms.snapshot.value = this.snap.target.texture;
|
||||
octree.material.uniforms.snapView.value = this.snap.camera.matrixWorldInverse;
|
||||
octree.material.uniforms.snapProj.value = this.snap.camera.projectionMatrix;
|
||||
//octree.material.uniforms.snapshot.value = this.history.snapshots[0].target.texture;
|
||||
//octree.material.uniforms.snapView.value = this.history.snapshots[0].camera.matrixWorldInverse;
|
||||
//octree.material.uniforms.snapProj.value = this.history.snapshots[0].camera.projectionMatrix;
|
||||
|
||||
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[`uSnapView`].value = this.history.snapshots.map(s => s.camera.matrixWorldInverse);
|
||||
uniforms[`uSnapProj`].value = this.history.snapshots.map(s => s.camera.projectionMatrix);
|
||||
|
||||
//for(let i = 0; i < 5; i++){
|
||||
// let snap = this.history.snapshots[i];
|
||||
// uniforms[`uSnapshot_${i}`].value = snap.target.texture;
|
||||
//}
|
||||
}
|
||||
|
||||
//let nodes = octree.visibleNodes.slice(0, 10);
|
||||
let nodes = octree.visibleNodes;
|
||||
viewer.pRenderer.renderOctree(octree, nodes, camera, this.rtColor, {});
|
||||
let nodes = octree.visibleNodes.slice(0, 10);
|
||||
//let nodes = octree.visibleNodes;
|
||||
viewer.pRenderer.renderOctree(octree, nodes, camera, this.rtColor, {vnTextureNodes: nodes});
|
||||
}
|
||||
|
||||
//viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.rtColor, {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user