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-09 16:26:33 +01:00 committed by Paul
parent 21f95eb977
commit d5b3970e01
35 changed files with 60 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

View File

@ -502,7 +502,7 @@ class WebGLTexture {
gl.texImage2D(this.target, level, internalFormat,
width, height, border, srcFormat, srcType,
data);
} else if (texture instanceof THREE.CanvasTexture) {
} else if ((texture instanceof THREE.CanvasTexture) || (texture instanceof THREE.Texture)) {
data = texture.image;
gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, paramThreeToGL(gl, texture.wrapS));
@ -513,6 +513,8 @@ class WebGLTexture {
gl.texImage2D(this.target, level, internalFormat,
internalFormat, srcType, data);
if (texture instanceof THREE.Texture) {gl.generateMipmap(gl.TEXTURE_2D);}
}
gl.bindTexture(this.target, null);
@ -1210,6 +1212,12 @@ export class Renderer {
gl.bindTexture(classificationTexture.target, classificationTexture.id);
currentTextureBindingPoint++;
let matcapTexture = this.textures.get(material.matcapTexture);
shader.setUniform1i("matcapTextureUniform", currentTextureBindingPoint);
gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
gl.bindTexture(matcapTexture.target, matcapTexture.id);
currentTextureBindingPoint++;
if (material.snapEnabled === true) {

View File

@ -55,6 +55,7 @@ export const PointColorType = {
PHONG: 12,
RGB_HEIGHT: 13,
GPS_TIME: 14,
MATCAP: 15,
COMPOSITE: 50
};

View File

@ -46,6 +46,8 @@ export class PointCloudMaterial extends THREE.RawShaderMaterial {
this._weighted = false;
this._gradient = Gradients.SPECTRAL;
this.gradientTexture = PointCloudMaterial.generateGradientTexture(this._gradient);
this._matcap = "matcap.jpg";
this.matcapTexture = Potree.PointCloudMaterial.generateMatcapTexture(this._matcap);
this.lights = false;
this.fog = false;
this._treeType = treeType;
@ -133,6 +135,8 @@ 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 },
};
this.classification = ClassificationScheme.DEFAULT;
@ -280,6 +284,8 @@ export class PointCloudMaterial extends THREE.RawShaderMaterial {
defines.push('#define color_type_gpstime');
} else if (this._pointColorType === PointColorType.COMPOSITE) {
defines.push('#define color_type_composite');
} else if (this._pointColorType === PointColorType.MATCAP) {
defines.push('#define color_type_matcap');
}
if(this._treeType === TreeType.OCTREE){
@ -382,7 +388,19 @@ export class PointCloudMaterial extends THREE.RawShaderMaterial {
this.uniforms.gradient.value = this.gradientTexture;
}
}
get matcap(){
return this._matcap;
}
set matcap (value) {
if (this._matcap !== value) {
this._matcap = value;
this.matcapTexture = Potree.PointCloudMaterial.generateMatcapTexture(this._matcap);
this.uniforms.matcapTextureUniform.value = this.matcapTexture;
}
}
get useOrthographicCamera() {
return this.uniforms.useOrthographicCamera.value;
}
@ -967,6 +985,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 generateClassificationTexture (classification) {
let width = 256;
let height = 256;

View File

@ -15,6 +15,7 @@ attribute float pointSourceID;
attribute vec4 indices;
attribute float spacing;
attribute float gpsTime;
attribute vec3 normal;
uniform mat4 modelMatrix;
uniform mat4 modelViewMatrix;
@ -104,6 +105,7 @@ uniform vec3 uShadowColor;
uniform sampler2D visibleNodes;
uniform sampler2D gradient;
uniform sampler2D classificationLUT;
uniform sampler2D matcapTextureUniform;
#if defined(num_shadowmaps) && num_shadowmaps > 0
uniform sampler2D uShadowMap[num_shadowmaps];
@ -479,6 +481,21 @@ vec3 getCompositeColor(){
}
// 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;
}
//
// ###### ## #### ######## ######## #### ## ## ######
// ## ## ## ## ## ## ## ## ## ### ## ## ##
@ -535,6 +552,8 @@ vec3 getColor(){
color = color;
#elif defined color_type_composite
color = getCompositeColor();
#elif defined color_type_matcap
color = getMatcap();
#endif
return color;

View File

@ -188,6 +188,7 @@ export class HQSplatRenderer{
attributeMaterial.elevationRange = material.elevationRange;
attributeMaterial.gradient = material.gradient;
attributeMaterial.matcap = material.matcap;
attributeMaterial.intensityRange = material.intensityRange;
attributeMaterial.intensityGamma = material.intensityGamma;