Skip to content

Commit c08bcce

Browse files
authored
MeshPhysicalMaterial: Match behavior of attenuationDistance to KHR_materials_volume (#24622)
* Change default attenuation distance to Infinity * Update GLTFLoader to new default for attenuationDistance
1 parent b835414 commit c08bcce

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

docs/api/en/materials/MeshPhysicalMaterial.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ <h3>[property:Color attenuationColor]</h3>
8686

8787
<h3>[property:Float attenuationDistance]</h3>
8888
<p>
89-
Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. Default is `0`.
89+
Density of the medium given as the average distance that light travels in the medium before interacting with a particle. The value is given in world space. Default is `Infinity`.
9090
</p>
9191

9292
<h3>[property:Float clearcoat]</h3>

examples/jsm/loaders/GLTFLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ class GLTFMaterialsVolumeExtension {
10441044

10451045
}
10461046

1047-
materialParams.attenuationDistance = extension.attenuationDistance || 0;
1047+
materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
10481048

10491049
const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
10501050
materialParams.attenuationColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );

src/materials/MeshPhysicalMaterial.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class MeshPhysicalMaterial extends MeshStandardMaterial {
5555

5656
this.thickness = 0;
5757
this.thicknessMap = null;
58-
this.attenuationDistance = 0.0;
58+
this.attenuationDistance = Infinity;
5959
this.attenuationColor = new Color( 1, 1, 1 );
6060

6161
this.specularIntensity = 1.0;

src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ export default /* glsl */`
7171
7272
vec3 applyVolumeAttenuation( const in vec3 radiance, const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
7373
74-
if ( attenuationDistance == 0.0 ) {
74+
if ( isinf( attenuationDistance ) ) {
7575
76-
// Attenuation distance is +∞ (which we indicate by zero), i.e. the transmitted color is not attenuated at all.
76+
// Attenuation distance is +∞, i.e. the transmitted color is not attenuated at all.
7777
return radiance;
7878
7979
} else {

0 commit comments

Comments
 (0)