Skip to content

Commit

Permalink
fix(PointMaterial): force transparent to true and depthWrite to false
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Jan 17, 2025
1 parent 8716bd7 commit 2297d27
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
4 changes: 1 addition & 3 deletions src/Layer/PointCloudLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,12 @@ class PointCloudLayer extends GeometryLayer {
if (this.material) {
this.material.visible = this.visible;
this.material.opacity = this.opacity;
this.material.transparent = this.material.userData.needTransparency[this.material.mode] || this.opacity < 1 || this.material.userData.needTransparency.classTransparency;
this.material.depthWrite = !this.material.userData.needTransparency.classTransparency;
this.material.depthWrite = false;
this.material.size = this.pointSize;
this.material.scale = context.camera.preSSE;
if (this.material.updateUniforms) {
this.material.updateUniforms();
}
this.material.needsUpdate = true;
}

// lookup lowest common ancestor of changeSources
Expand Down
26 changes: 3 additions & 23 deletions src/Renderer/PointsMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ function generateGradientTexture(gradient) {
}

function recomputeTexture(scheme, texture, nbClass) {
let needTransparency;
const data = texture.image.data;
const width = texture.image.width;
if (!nbClass) { nbClass = Object.keys(scheme).length; }
Expand Down Expand Up @@ -141,11 +140,8 @@ function recomputeTexture(scheme, texture, nbClass) {
data[j + 1] = parseInt(255 * color.g, 10);
data[j + 2] = parseInt(255 * color.b, 10);
data[j + 3] = parseInt(255 * opacity, 10);

needTransparency = needTransparency || opacity < 1;
}
texture.needsUpdate = true;
return needTransparency;
}

class PointsMaterial extends THREE.ShaderMaterial {
Expand Down Expand Up @@ -206,6 +202,7 @@ class PointsMaterial extends THREE.ShaderMaterial {
super({
...materialOptions,
fog: true,
transparent: true,
precision: 'highp',
vertexColors: true,
});
Expand All @@ -217,7 +214,6 @@ class PointsMaterial extends THREE.ShaderMaterial {
this.vertexShader = PointsVS;
this.fragmentShader = PointsFS;

this.userData.needTransparency = {};
this.gradients = gradients;
this.gradientTexture = new THREE.CanvasTexture();

Expand Down Expand Up @@ -285,11 +281,6 @@ class PointsMaterial extends THREE.ShaderMaterial {
* @returns {this}
*/
copy(source) {
// Manually copy this needTransparency if source doesn't have one. Prevents losing it when copying a three
// PointsMaterial into this PointsMaterial
const needTransparency = source.userData.needTransparency !== undefined ? source.userData.needTransparency
: this.userData.needTransparency;

if (source.isShaderMaterial) {
super.copy(source);
} else {
Expand All @@ -304,8 +295,6 @@ class PointsMaterial extends THREE.ShaderMaterial {
this.sizeAttenuation = source.sizeAttenuation;
this.fog = source.fog;

this.userData.needTransparency = needTransparency;

return this;
}

Expand Down Expand Up @@ -376,28 +365,22 @@ class PointsMaterial extends THREE.ShaderMaterial {
}

recomputeClassification() {
const needTransparency = recomputeTexture(this.classificationScheme, this.classificationTexture, 256);
this.userData.needTransparency[PNTS_MODE.CLASSIFICATION] = needTransparency;
recomputeTexture(this.classificationScheme, this.classificationTexture, 256);
this.dispatchEvent({
type: 'material_property_changed',
target: this.uniforms,
});
}

recomputeDiscreteTexture() {
const needTransparency = recomputeTexture(this.discreteScheme, this.discreteTexture);
this.userData.needTransparency[PNTS_MODE.RETURN_NUMBER] = needTransparency;
this.userData.needTransparency[PNTS_MODE.RETURN_TYPE] = needTransparency;
this.userData.needTransparency[PNTS_MODE.RETURN_COUNT] = needTransparency;
this.userData.needTransparency[PNTS_MODE.POINT_SOURCE_ID] = needTransparency;
recomputeTexture(this.discreteScheme, this.discreteTexture);
this.dispatchEvent({
type: 'material_property_changed',
target: this.uniforms,
});
}

recomputeVisibleTexture() {
let needTransparency;
const texture = this.visiTexture;
const scheme = this.classificationScheme;

Expand All @@ -416,12 +399,9 @@ class PointsMaterial extends THREE.ShaderMaterial {
}

data[i] = visible ? 255 : 0;
needTransparency = needTransparency || visible === false;
}
texture.needsUpdate = true;

this.userData.needTransparency.classTransparency = needTransparency;

this.dispatchEvent({
type: 'material_property_changed',
target: this.uniforms,
Expand Down

0 comments on commit 2297d27

Please sign in to comment.