Browse Source

Merge pull request #20322 from WestLangley/dev_ior

MeshPhysicalMaterial: Added .ior property
Mr.doob 4 years ago
parent
commit
538533d068

+ 7 - 2
docs/api/en/materials/MeshPhysicalMaterial.html

@@ -121,11 +121,16 @@
 			This is used by the [page:WebGLRenderer] for selecting shaders.
 		</p>
 
+		<h3>[property:Float ior]</h3>
+		<p>
+			Index-of-refraction for non-metallic materials, from *1.0* to *2.333*. Default is *1.5*.<br />
+		</p>
+
 		<h3>[property:Float reflectivity]</h3>
 		<p>
-		Degree of reflectivity, from *0.0* to *1.0*. Default is *0.5*.<br />
+			Degree of reflectivity, from *0.0* to *1.0*. Default is *0.5*, which corresponds to an index-of-refraction of 1.5.<br />
 
-		This models the reflectivity of non-metallic materials. It has no effect when [page:MeshStandardMaterial.metalness metalness] is *1.0*
+			This models the reflectivity of non-metallic materials. It has no effect when [page:MeshStandardMaterial.metalness metalness] is *1.0*
 		</p>
 
 		<h3>[property:Float transmission]</h3>

+ 8 - 1
docs/api/zh/materials/MeshPhysicalMaterial.html

@@ -118,8 +118,15 @@
 			[page:WebGLRenderer]使用它来选择shaders。
 		</p>
 
+		<h3>[property:Float ior]</h3>
+		<p>
+			Index-of-refraction for non-metallic materials, from *1.0* to *2.333*. Default is *1.5*.<br />
+		</p>
+
 		<h3>[property:Float reflectivity]</h3>
-		<p> 反射度,从*0.0*到*1.0*。默认值为*0.5*。<br />
+		<p>
+			Degree of reflectivity, from *0.0* to *1.0*. Default is *0.5*, which corresponds to an index-of-refraction of 1.5.<br />
+
 			这模拟了非金属材质的反射率。当[page:MeshStandardMaterial]为*1.0*时,此属性无效。
 		</p>
 

+ 6 - 0
src/materials/MeshPhysicalMaterial.d.ts

@@ -17,6 +17,7 @@ export interface MeshPhysicalMaterialParameters
 	clearcoatNormalMap?: Texture | null;
 
 	reflectivity?: number;
+	ior?: number;
 
 	sheen?: Color;
 
@@ -74,6 +75,11 @@ export class MeshPhysicalMaterial extends MeshStandardMaterial {
 	 */
 	reflectivity: number;
 
+	/**
+	 * @default 1.5
+	 */
+	ior: number;
+
 	/**
 	 * @default null
 	 */

+ 15 - 0
src/materials/MeshPhysicalMaterial.js

@@ -1,6 +1,7 @@
 import { Vector2 } from '../math/Vector2.js';
 import { MeshStandardMaterial } from './MeshStandardMaterial.js';
 import { Color } from '../math/Color.js';
+import { MathUtils } from '../math/MathUtils.js';
 
 /**
  * parameters = {
@@ -12,6 +13,7 @@ import { Color } from '../math/Color.js';
  *  clearcoatNormalMap: new THREE.Texture( <Image> ),
  *
  *  reflectivity: <float>,
+ *  ior: <float>,
  *
  *  sheen: <Color>,
  *
@@ -42,6 +44,19 @@ function MeshPhysicalMaterial( parameters ) {
 
 	this.reflectivity = 0.5; // maps to F0 = 0.04
 
+	Object.defineProperty( this, 'ior', {
+		get: function () {
+
+			return ( 1 + 0.4 * this.reflectivity ) / ( 1 - 0.4 * this.reflectivity );
+
+		},
+		set: function ( ior ) {
+
+			this.reflectivity = MathUtils.clamp( 2.5 * ( ior - 1 ) / ( ior + 1 ), 0, 1 );
+
+		}
+	} );
+
 	this.sheen = null; // null will disable sheen bsdf
 
 	this.transmission = 0.0;