Skip to content

Commit

Permalink
feature(points): apply opacity classification on others MODE.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Jan 11, 2021
1 parent 9666822 commit e411425
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
8 changes: 7 additions & 1 deletion src/Renderer/PointsMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PointsMaterial extends THREE.RawShaderMaterial {
* @param {number} [options.mode=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.
* @property {Classification} classification - points classification.
*
Expand All @@ -69,8 +70,12 @@ class PointsMaterial extends THREE.RawShaderMaterial {
constructor(options = {}) {
const intensityRange = options.intensityRange || new THREE.Vector2(0, 1);
const oiMaterial = options.orientedImageMaterial;
const classification = options.classification || ClassificationScheme.DEFAULT;
const applyOpacityClassication = options.applyOpacityClassication == undefined ? false : options.applyOpacityClassication;
delete options.orientedImageMaterial;
delete options.intensityRange;
delete options.classification;
delete options.applyOpacityClassication;
super(options);

this.vertexShader = PointsVS;
Expand All @@ -85,6 +90,7 @@ class PointsMaterial extends THREE.RawShaderMaterial {
CommonMaterial.setUniformProperty(this, 'opacity', this.opacity);
CommonMaterial.setUniformProperty(this, 'overlayColor', options.overlayColor || new THREE.Vector4(0, 0, 0, 0));
CommonMaterial.setUniformProperty(this, 'intensityRange', intensityRange);
CommonMaterial.setUniformProperty(this, 'applyOpacityClassication', applyOpacityClassication);

// add classification texture to apply classification lut.
const data = new Uint8Array(256 * 4);
Expand All @@ -93,7 +99,7 @@ class PointsMaterial extends THREE.RawShaderMaterial {
CommonMaterial.setUniformProperty(this, 'classificationLUT', texture);

// Classification scheme
this.classification = options.classification || ClassificationScheme.DEFAULT;
this.classification = classification;

// Update classification
this.recomputeClassification();
Expand Down
3 changes: 1 addition & 2 deletions src/Renderer/Shader/PointsFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ uniform bool picking;
void main() {
#include <logdepthbuf_fragment>
// circular point rendering
if(length(gl_PointCoord - 0.5) > 0.5){
if((length(gl_PointCoord - 0.5) > 0.5) || (vColor.a == 0.0)) {
discard;
}

#if defined(USE_TEXTURES_PROJECTIVE)
vec4 color = vColor;
if (!picking) {
Expand Down
29 changes: 18 additions & 11 deletions src/Renderer/Shader/PointsVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ uniform int mode;
uniform float opacity;
uniform vec4 overlayColor;
uniform vec2 intensityRange;
uniform bool applyOpacityClassication;
attribute vec3 color;
attribute vec4 unique_id;
attribute float intensity;
Expand Down Expand Up @@ -75,18 +76,24 @@ void main() {

if (picking) {
vColor = unique_id;
} else if (mode == MODE_INTENSITY) {
// adapt the grayscale knowing the range
float i = (intensity - intensityRange.x) / (intensityRange.y - intensityRange.x);
vColor = vec4(i, i, i, opacity);
} else if (mode == MODE_NORMAL) {
vColor = vec4(abs(normal), opacity);
} else if (mode == MODE_CLASSIFICATION) {
vec2 uv = vec2(classification, 0.5);
vColor = texture2D(classificationLUT, uv);
} else {
// default to color mode
vColor = vec4(mix(color, overlayColor.rgb, overlayColor.a), opacity);
vColor.a = opacity;
if (applyOpacityClassication || mode == MODE_CLASSIFICATION) {
vec2 uv = vec2(classification, 0.5);
vColor = texture2D(classificationLUT, uv);
vColor.a *= opacity;
}

if (mode == MODE_INTENSITY) {
// adapt the grayscale knowing the range
float i = (intensity - intensityRange.x) / (intensityRange.y - intensityRange.x);
vColor.rgb = vec3(i, i, i);
} else if (mode == MODE_NORMAL) {
vColor.rgb = abs(normal);
} else if (mode == MODE_COLOR) {
// default to color mode
vColor.rgb = mix(color, overlayColor.rgb, overlayColor.a);
}
}

#include <begin_vertex>
Expand Down

0 comments on commit e411425

Please sign in to comment.