Skip to content

Commit d2f506e

Browse files
authored
Merge pull request #273 from gkjohnson/transparent-fix
Transparent fix
2 parents 6fd71f8 + 828024d commit d2f506e

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

example/materialBall.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ function animate() {
589589
m1.iridescenceThicknessRange = [ 0, params.material1.iridescenceThickness ];
590590
m1.specularColor.set( params.material1.specularColor ).convertSRGBToLinear();
591591
m1.specularIntensity = params.material1.specularIntensity;
592+
m1.transparent = m1.opacity < 1;
592593

593594
const m2 = materials[ 1 ];
594595
m2.color.set( params.material2.color ).convertSRGBToLinear();
@@ -610,11 +611,13 @@ function animate() {
610611
m2.iridescenceThicknessRange = [ 0, params.material2.iridescenceThickness ];
611612
m2.specularColor.set( params.material2.specularColor ).convertSRGBToLinear();
612613
m2.specularIntensity = params.material2.specularIntensity;
614+
m2.transparent = m2.opacity < 1;
613615

614616
const m3 = materials[ 2 ];
615617
m3.color.set( params.material3.color ).convertSRGBToLinear();
616618
m3.metalness = params.material3.metalness;
617619
m3.roughness = params.material3.roughness;
620+
m3.transparent = m3.opacity < 1;
618621

619622
ptRenderer.material.materials.updateFrom( sceneInfo.materials, sceneInfo.textures );
620623
ptRenderer.material.materials.setMatte( 0, params.material1.matte );

example/viewerTest.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,6 @@ async function updateModel() {
439439

440440
generator.dispose();
441441

442-
envMap.mapping = EquirectangularReflectionMapping;
443-
scene.environment = envMap;
444-
scene.background = envMap;
445-
446442
loadingEl.style.visibility = 'hidden';
447443

448444
creditEl.innerHTML = modelInfo.credit || '';
@@ -467,7 +463,20 @@ async function updateModel() {
467463
controls.update();
468464
camera.updateMatrixWorld();
469465

470-
ptRenderer.material.backgroundAlpha = renderSkybox ? 1 : 0;
466+
envMap.mapping = EquirectangularReflectionMapping;
467+
scene.environment = envMap;
468+
if ( renderSkybox ) {
469+
470+
scene.background = envMap;
471+
ptRenderer.material.backgroundAlpha = 1;
472+
473+
} else {
474+
475+
renderer.setClearAlpha( 0 );
476+
scene.background = null;
477+
ptRenderer.material.backgroundAlpha = 0;
478+
479+
}
471480

472481
ptRenderer.reset();
473482

src/materials/PhysicalPathTracingMaterial.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
273273
|| useAlphaTest && albedo.a < alphaTest
274274
275275
// opacity
276-
|| ! useAlphaTest && albedo.a < rand()
276+
|| material.transparent && ! useAlphaTest && albedo.a < rand()
277277
)
278278
) {
279279
@@ -580,7 +580,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
580580
|| useAlphaTest && albedo.a < alphaTest
581581
582582
// opacity
583-
|| ! useAlphaTest && albedo.a < rand()
583+
|| material.transparent && ! useAlphaTest && albedo.a < rand()
584584
) {
585585
586586
vec3 point = rayOrigin + rayDirection * dist;

src/shader/shaderStructs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const shaderMaterialStructs = /* glsl */ `
8181
int sheenRoughnessMap;
8282
8383
bool vertexColors;
84+
bool transparent;
8485
8586
mat3 mapTransform;
8687
mat3 metalnessMapTransform;
@@ -192,6 +193,7 @@ export const shaderMaterialStructs = /* glsl */ `
192193
m.matte = bool( s14.r );
193194
m.castShadow = ! bool( s14.g );
194195
m.vertexColors = bool( s14.b );
196+
m.transparent = bool( s14.a );
195197
196198
uint firstTextureTransformIdx = i + 15u;
197199

src/uniforms/MaterialsTexture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export class MaterialsTexture extends DataTexture {
368368
index ++; // matte
369369
index ++; // shadow
370370
floatArray[ index ++ ] = Number( m.vertexColors ); // vertexColors
371-
index ++;
371+
floatArray[ index ++ ] = Number( m.transparent ); // transparent
372372

373373
// map transform 15
374374
index += writeTextureMatrixToArray( m, 'map', floatArray, index );

src/utils/GeometryPreparationUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function setCommonAttributes( geometry, options ) {
104104
if ( ! geometry.attributes.color && ( attributes && attributes.includes( 'color' ) ) ) {
105105

106106
const vertCount = geometry.attributes.position.count;
107-
geometry.setAttribute( 'color', new BufferAttribute( new Float32Array( vertCount * 4 ), 4, true ) );
107+
geometry.setAttribute( 'color', new BufferAttribute( new Float32Array( vertCount * 4 ), 4 ) );
108108

109109
}
110110

0 commit comments

Comments
 (0)