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.
BIN
resources/textures/matcap/matcap.jpg
Normal file
|
After Width: | Height: | Size: 7.8 KiB |
BIN
resources/textures/matcap/matcap0.jpg
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
resources/textures/matcap/matcap1.jpg
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
resources/textures/matcap/matcap10.jpg
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
BIN
resources/textures/matcap/matcap11.jpg
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
resources/textures/matcap/matcap12.jpg
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
resources/textures/matcap/matcap13.jpg
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
resources/textures/matcap/matcap14.jpg
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
BIN
resources/textures/matcap/matcap15.jpg
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
resources/textures/matcap/matcap16.jpg
Normal file
|
After Width: | Height: | Size: 6.6 KiB |
BIN
resources/textures/matcap/matcap17.jpg
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
BIN
resources/textures/matcap/matcap18.jpg
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
resources/textures/matcap/matcap19.jpg
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
resources/textures/matcap/matcap2.jpg
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
BIN
resources/textures/matcap/matcap20.jpg
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
resources/textures/matcap/matcap21.jpg
Normal file
|
After Width: | Height: | Size: 71 KiB |
BIN
resources/textures/matcap/matcap22.jpg
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
resources/textures/matcap/matcap23.jpg
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
resources/textures/matcap/matcap24.jpg
Normal file
|
After Width: | Height: | Size: 6.7 KiB |
BIN
resources/textures/matcap/matcap25.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
resources/textures/matcap/matcap26.jpg
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
resources/textures/matcap/matcap27.jpg
Normal file
|
After Width: | Height: | Size: 68 KiB |
BIN
resources/textures/matcap/matcap28.jpg
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
resources/textures/matcap/matcap3.jpg
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
resources/textures/matcap/matcap4.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
resources/textures/matcap/matcap5.jpg
Normal file
|
After Width: | Height: | Size: 65 KiB |
BIN
resources/textures/matcap/matcap6.jpg
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
resources/textures/matcap/matcap7.jpg
Normal file
|
After Width: | Height: | Size: 135 KiB |
BIN
resources/textures/matcap/matcap8.jpg
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
resources/textures/matcap/matcap9.jpg
Normal file
|
After Width: | Height: | Size: 59 KiB |
@ -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) {
|
||||
|
||||
|
||||
@ -55,6 +55,7 @@ export const PointColorType = {
|
||||
PHONG: 12,
|
||||
RGB_HEIGHT: 13,
|
||||
GPS_TIME: 14,
|
||||
MATCAP: 15,
|
||||
COMPOSITE: 50
|
||||
};
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||