Ver Fonte

MeshPhysicalMaterial: Match behavior of attenuationDistance to KHR_materials_volume (#24622)

* Change default attenuation distance to Infinity

* Update GLTFLoader to new default for attenuationDistance
Zachary Capalbo há 2 anos atrás
pai
commit
c08bcce99a

+ 1 - 1
docs/api/en/materials/MeshPhysicalMaterial.html

@@ -86,7 +86,7 @@
 
 		<h3>[property:Float attenuationDistance]</h3>
 		<p>
-		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`.
+		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`.
 		</p>
 
 		<h3>[property:Float clearcoat]</h3>

+ 1 - 1
examples/jsm/loaders/GLTFLoader.js

@@ -1044,7 +1044,7 @@ class GLTFMaterialsVolumeExtension {
 
 		}
 
-		materialParams.attenuationDistance = extension.attenuationDistance || 0;
+		materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
 
 		const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
 		materialParams.attenuationColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );

+ 1 - 1
src/materials/MeshPhysicalMaterial.js

@@ -55,7 +55,7 @@ class MeshPhysicalMaterial extends MeshStandardMaterial {
 
 		this.thickness = 0;
 		this.thicknessMap = null;
-		this.attenuationDistance = 0.0;
+		this.attenuationDistance = Infinity;
 		this.attenuationColor = new Color( 1, 1, 1 );
 
 		this.specularIntensity = 1.0;

+ 2 - 2
src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js

@@ -71,9 +71,9 @@ export default /* glsl */`
 
 	vec3 applyVolumeAttenuation( const in vec3 radiance, const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
 
-		if ( attenuationDistance == 0.0 ) {
+		if ( isinf( attenuationDistance ) ) {
 
-			// Attenuation distance is +∞ (which we indicate by zero), i.e. the transmitted color is not attenuated at all.
+			// Attenuation distance is +∞, i.e. the transmitted color is not attenuated at all.
 			return radiance;
 
 		} else {