Support Matcap for Potree

When normals are available per point, can support matcap by computing reflected eye vector at each location, and infering color from a matcap texture. 30 matcap textures included, from the web.
This commit is contained in:
Jonathan Chemla 2018-11-12 10:18:17 +01:00 committed by Paul
parent d5b3970e01
commit a68d640e46
3 changed files with 27 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@ -135,8 +135,7 @@ export class PointCloudMaterial extends THREE.RawShaderMaterial {
uFilterReturnNumberRange: { type: "fv", value: [0, 7]},
uFilterNumberOfReturnsRange: { type: "fv", value: [0, 7]},
uFilterGPSTimeClipRange: { type: "fv", value: [0, 7]},
matcapTextureUniform: { type: "t", value: this.matcapTexture },
matcapTextureUniform: { type: "t", value: this.matcapTexture },
};
this.classification = ClassificationScheme.DEFAULT;
@ -400,7 +399,6 @@ export class PointCloudMaterial extends THREE.RawShaderMaterial {
this.uniforms.matcapTextureUniform.value = this.matcapTexture;
}
}
get useOrthographicCamera() {
return this.uniforms.useOrthographicCamera.value;
}
@ -984,6 +982,17 @@ export class PointCloudMaterial extends THREE.RawShaderMaterial {
return texture;
}
static generateMatcapTexture (matcap) {
var url = new URL(Potree.resourcePath + "/textures/matcap/" + matcap).href;
let texture = new THREE.TextureLoader().load( url );
texture.magFilter = texture.minFilter = THREE.LinearFilter;
texture.needsUpdate = true;
// PotreeConverter_1.6_2018_07_29_windows_x64\PotreeConverter.exe autzen_xyzrgbXYZ_ascii.xyz -f xyzrgbXYZ -a RGB NORMAL -o autzen_xyzrgbXYZ_ascii_a -p index --overwrite
// Switch matcap texture on the fly : viewer.scene.pointclouds[0].material.matcap = 'matcap1.jpg';
// For non power of 2, use LinearFilter and dont generate mipmaps, For power of 2, use NearestFilter and generate mipmaps : matcap2.jpg 1 2 8 11 12 13
return texture;
}
static generateMatcapTexture (matcap) {
var url = new URL(Potree.resourcePath + "/textures/matcap/" + matcap).href;

View File

@ -480,6 +480,21 @@ vec3 getCompositeColor(){
return c;
}
// Matcap Material
vec3 getNormal(){
//vec3 n_hsv = vec3( modelMatrix * vec4( normal, 0.0 )) * 0.5 + 0.5; // (n_world.xyz + vec3(1.,1.,1.)) / 2.;
vec3 n_view = normalize( vec3( modelViewMatrix * vec4( normal, 0.0 ) ) );
return n_view;
}
vec3 getMatcap(){
vec3 eye = normalize( vec3( modelViewMatrix * vec4( position, 1. ) ) );
vec3 r_en = reflect( eye, getNormal() ); // or r_en = e - 2. * dot( n, e ) * n;
float m = 2. * sqrt(pow( r_en.x, 2. ) + pow( r_en.y, 2. ) + pow( r_en.z + 1., 2. ));
vec2 vN = r_en.xy / m + .5;
return texture2D(matcapTextureUniform, vN).rgb;
}
// Matcap Material
vec3 getNormal(){