From 2a2a3287de0fc72eb181a6633c868b9b5c3ce347 Mon Sep 17 00:00:00 2001 From: Kevin ETOURNEAU Date: Wed, 23 Aug 2023 09:20:08 +0200 Subject: [PATCH] feat(points): Allow custom adaptive points parameters --- CONTRIBUTORS.md | 4 ++++ src/Renderer/PointsMaterial.js | 14 +++++++++++++- src/Renderer/Shader/PointsVS.glsl | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 835d010b51..48747ddf04 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -45,6 +45,10 @@ The following people have contributed to iTowns. * [Diginove](http://diginove.com/index.php/fr/diginove-lexpertise-en-traitement-dimages/): * [Michel Benet](https://github.com/mbenevole) +* [Sogelink](https://www.sogelink.com/) + * [Kévin ETOURNEAU](https://github.com/ketourneau) + * [Alexis DELFORGES](https://github.com/pourfex) + The following organizations are the current maintainers of iTowns: * IGN (http://www.ign.fr) * Ciril Group (https://www.cirilgroup.com/) diff --git a/src/Renderer/PointsMaterial.js b/src/Renderer/PointsMaterial.js index 2d9e5f5866..574c4c4e25 100644 --- a/src/Renderer/PointsMaterial.js +++ b/src/Renderer/PointsMaterial.js @@ -53,12 +53,15 @@ class PointsMaterial extends THREE.RawShaderMaterial { /** * @class PointsMaterial * @param {object} [options={}] The options - * @param {number} [options.size=0] size point + * @param {number} [options.size=0] size point (adaptive size mode when size is 0) * @param {number} [options.mode=PNTS_MODE.COLOR] display mode. * @param {THREE.Vector4} [options.overlayColor=new THREE.Vector4(0, 0, 0, 0)] overlay color. * @param {THREE.Vector2} [options.intensityRange=new THREE.Vector2(0, 1)] intensity range. * @param {boolean} [options.applyOpacityClassication=false] apply opacity classification on all display mode. * @param {Classification} [options.classification] - define points classification. + * @param {number} [options.minAdaptiveSize=3] min adaptive size point (used only when size is 0) + * @param {number} [options.maxAdaptiveSize=10] max adaptive size point (used only when size is 0) + * @param {number} [options.adaptiveScale=1] adaptive scale factor (used only when size is 0) * @property {Classification} classification - points classification. * * @example @@ -74,6 +77,9 @@ class PointsMaterial extends THREE.RawShaderMaterial { const applyOpacityClassication = options.applyOpacityClassication == undefined ? false : options.applyOpacityClassication; const size = options.size || 0; const mode = options.mode || PNTS_MODE.COLOR; + const minAdaptiveSize = options.minAdaptiveSize || 3; + const maxAdaptiveSize = options.maxAdaptiveSize || 10; + const adaptiveScale = options.adaptiveScale || 1; delete options.orientedImageMaterial; delete options.intensityRange; @@ -81,6 +87,9 @@ class PointsMaterial extends THREE.RawShaderMaterial { delete options.applyOpacityClassication; delete options.size; delete options.mode; + delete options.minAdaptiveSize; + delete options.maxAdaptiveSize; + delete options.adaptiveScale; super(options); @@ -97,6 +106,9 @@ class PointsMaterial extends THREE.RawShaderMaterial { CommonMaterial.setUniformProperty(this, 'overlayColor', options.overlayColor || new THREE.Vector4(0, 0, 0, 0)); CommonMaterial.setUniformProperty(this, 'intensityRange', intensityRange); CommonMaterial.setUniformProperty(this, 'applyOpacityClassication', applyOpacityClassication); + CommonMaterial.setUniformProperty(this, 'minAdaptiveSize', minAdaptiveSize); + CommonMaterial.setUniformProperty(this, 'maxAdaptiveSize', maxAdaptiveSize); + CommonMaterial.setUniformProperty(this, 'adaptiveScale', adaptiveScale); // add classification texture to apply classification lut. const data = new Uint8Array(256 * 4); diff --git a/src/Renderer/Shader/PointsVS.glsl b/src/Renderer/Shader/PointsVS.glsl index c36b57ee1d..a70a489023 100644 --- a/src/Renderer/Shader/PointsVS.glsl +++ b/src/Renderer/Shader/PointsVS.glsl @@ -20,6 +20,9 @@ attribute vec4 unique_id; attribute float intensity; attribute float classification; uniform sampler2D classificationLUT; +uniform float minAdaptiveSize; +uniform float maxAdaptiveSize; +uniform float adaptiveScale; #if defined(NORMAL_OCT16) attribute vec2 oct16Normal; @@ -102,7 +105,7 @@ void main() { if (size > 0.) { gl_PointSize = size; } else { - gl_PointSize = clamp(-size / gl_Position.w, 3.0, 10.0); + gl_PointSize = clamp(-size / gl_Position.w, minAdaptiveSize, maxAdaptiveSize) * adaptiveScale; } #if defined(USE_TEXTURES_PROJECTIVE)