Parcourir la source

MMDLoader: Handle shininess properly (#23889)

MMDToonMaterial is derived from MeshToon/Phong/MatcapMaterial.
Similar to MeshPhongMaterial, shininess should have lower limit
to prevent pow(0.0, 0.0) in the shader code.
Takahiro il y a 3 ans
Parent
commit
1ec52458eb
1 fichiers modifiés avec 19 ajouts et 1 suppressions
  1. 19 1
      examples/jsm/loaders/MMDLoader.js

+ 19 - 1
examples/jsm/loaders/MMDLoader.js

@@ -2133,7 +2133,6 @@ class MMDToonMaterial extends ShaderMaterial {
 		// merged from MeshToon/Phong/MatcapMaterial
 		const exposePropertyNames = [
 			'specular',
-			'shininess',
 			'opacity',
 			'diffuse',
 
@@ -2188,6 +2187,25 @@ class MMDToonMaterial extends ShaderMaterial {
 
 		}
 
+		// Special path for shininess to handle zero shininess properly
+		this._shininess = 30;
+		Object.defineProperty( this, 'shininess', {
+
+			get: function () {
+
+				return this._shininess;
+
+			},
+
+			set: function ( value ) {
+
+				this._shininess = value;
+				this.uniforms.shininess.value = Math.max( this._shininess, 1e-4 ); // To prevent pow( 0.0, 0.0 )
+
+			},
+
+		} );
+
 		Object.defineProperty(
 			this,
 			'color',