diff --git a/resources/textures/matcap/matcap29.jpg b/resources/textures/matcap/matcap29.jpg new file mode 100644 index 00000000..2f1d94bd Binary files /dev/null and b/resources/textures/matcap/matcap29.jpg differ diff --git a/src/materials/PointCloudMaterial.js b/src/materials/PointCloudMaterial.js index 63a778f1..1ba4949b 100644 --- a/src/materials/PointCloudMaterial.js +++ b/src/materials/PointCloudMaterial.js @@ -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; diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs index cbdb090f..bfc9db71 100644 --- a/src/materials/shaders/pointcloud.vs +++ b/src/materials/shaders/pointcloud.vs @@ -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(){