Browse Source

Added .ior property

WestLangley 4 years ago
parent
commit
751dfaff88
1 changed files with 15 additions and 0 deletions
  1. 15 0
      src/materials/MeshPhysicalMaterial.js

+ 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;