diff --git a/src/Renderer/PointsMaterial.js b/src/Renderer/PointsMaterial.js index df2e8ce0ab..2b8613c9cf 100644 --- a/src/Renderer/PointsMaterial.js +++ b/src/Renderer/PointsMaterial.js @@ -136,11 +136,11 @@ class PointsMaterial extends THREE.RawShaderMaterial { CommonMaterial.setUniformProperty(this, 'maxAttenuatedSize', maxAttenuatedSize); // add classification texture to apply classification lut. - const data = new Uint8Array(256 * 4); - const texture = new THREE.DataTexture(data, 256, 1, THREE.RGBAFormat); - texture.needsUpdate = true; - texture.magFilter = THREE.NearestFilter; - CommonMaterial.setUniformProperty(this, 'classificationLUT', texture); + const classData = new Uint8Array(256 * 4); + const classTexture = new THREE.DataTexture(classData, 256, 1, THREE.RGBAFormat); + classTexture.needsUpdate = true; + classTexture.magFilter = THREE.NearestFilter; + CommonMaterial.setUniformProperty(this, 'classificationLUT', classTexture); // Classification scheme this.classification = classification; @@ -148,6 +148,15 @@ class PointsMaterial extends THREE.RawShaderMaterial { // Update classification this.recomputeClassification(); + // TODO + const gradientCanvas = document.createElement('canvas'); + gradientCanvas.width = 256; + gradientCanvas.height = 1; + const gradientTexture = new THREE.CanvasTexture(gradientCanvas); + CommonMaterial.setUniformProperty(this, 'gradient', gradientTexture); + + this.recomputeGradient(); + if (oiMaterial) { this.uniforms.projectiveTextureAlphaBorder = oiMaterial.uniforms.projectiveTextureAlphaBorder; this.uniforms.projectiveTextureDistortion = oiMaterial.uniforms.projectiveTextureDistortion; @@ -217,6 +226,25 @@ class PointsMaterial extends THREE.RawShaderMaterial { }); } + recomputeGradient() { + const width = this.gradient.source.data.width; + const context = this.gradient.source.data.getContext('2d'); + + context.rect(0, 0, width, 1); + const gradient = context.createLinearGradient(0, 0, width, 1); + gradient.addColorStop(0, '#000000'); + gradient.addColorStop(1, '#ffffff'); + context.fillStyle = gradient; + context.fill(); + + this.gradient.needsUpdate = true; + + this.dispatchEvent({ + type: 'material_property_changed', + target: this, + }); + } + onBeforeCompile(shader, renderer) { if (renderer.capabilities.isWebGL2) { diff --git a/src/Renderer/Shader/PointsVS.glsl b/src/Renderer/Shader/PointsVS.glsl index a18416ebbf..1bdc9c3d2a 100644 --- a/src/Renderer/Shader/PointsVS.glsl +++ b/src/Renderer/Shader/PointsVS.glsl @@ -25,6 +25,9 @@ uniform mat4 modelMatrix; uniform vec2 intensityRange; uniform vec2 elevationRange; +uniform sampler2D classificationLUT; +uniform sampler2D gradient; + uniform float size; uniform float preSSE; @@ -34,7 +37,6 @@ uniform float opacity; uniform vec4 overlayColor; uniform bool applyOpacityClassication; attribute vec4 unique_id; -uniform sampler2D classificationLUT; uniform int sizeMode; uniform float minAttenuatedSize; uniform float maxAttenuatedSize; @@ -104,9 +106,9 @@ void main() { } if (mode == PNTS_MODE_INTENSITY) { - // adapt the grayscale knowing the range + // adapt the gradient knowing the range float i = (intensity - intensityRange.x) / (intensityRange.y - intensityRange.x); - vColor.rgb = vec3(i, i, i); + vColor.rgb = texture2D(gradient, vec2(i, 0.5)).rgb; } else if (mode == PNTS_MODE_NORMAL) { vColor.rgb = abs(normal); } else if (mode == PNTS_MODE_COLOR) { @@ -114,20 +116,20 @@ void main() { vColor.rgb = mix(color, overlayColor.rgb, overlayColor.a); } else if (mode == PNTS_MODE_RETURN_NUMBER) { float n = returnNumber / RETURN_NUMBER_MAX; - vColor.rgb = vec3(n, n, n); + vColor.rgb = texture2D(gradient, vec2(n, 0.5)).rgb; } else if (mode == PNTS_MODE_NUMBER_OF_RETURNS) { float n = numberOfReturns / RETURN_NUMBER_MAX; - vColor.rgb = vec3(n, n, n); + vColor.rgb = texture2D(gradient, vec2(n, 0.5)).rgb; } else if (mode == PNTS_MODE_POINT_SOURCE_ID) { // group ids by their 4 least significant bits float i = mod(pointSourceID, 16.) / 16.; - vColor.rgb = vec3(i, i, i); + vColor.rgb = texture2D(gradient, vec2(i, 0.5)).rgb; } else if (mode == PNTS_MODE_ELEVATION) { // apply scale and offset transform vec4 model = modelMatrix * vec4(position, 1.0); float z = (model.z - elevationRange.x) / (elevationRange.y - elevationRange.x); // adapt the grayscale knowing the range - vColor.rgb = vec3(z, z, z); + vColor.rgb = texture2D(gradient, vec2(z, 0.5)).rgb; } }