Browse Source

WebGLRenderer: “Native” ShadowMaterial support.

Mr.doob 8 years ago
parent
commit
ca76e45053

+ 10 - 38
src/materials/ShadowMaterial.js

@@ -1,8 +1,3 @@
-import { ShaderMaterial } from './ShaderMaterial';
-import { ShaderChunk } from '../renderers/shaders/ShaderChunk';
-import { UniformsLib } from '../renderers/shaders/UniformsLib';
-import { UniformsUtils } from '../renderers/shaders/UniformsUtils';
-
 /**
  * @author mrdoob / http://mrdoob.com/
  *
@@ -12,49 +7,26 @@ import { UniformsUtils } from '../renderers/shaders/UniformsUtils';
  * }
  */
 
+import { Material } from './Material';
+import { Color } from '../math/Color';
+
 function ShadowMaterial( parameters ) {
 
-	ShaderMaterial.call( this, {
-		uniforms: UniformsUtils.merge( [
-			UniformsLib.lights,
-			{
-				color: { value: new THREE.Color( 0, 0, 0 ) },
-				opacity: { value: 1.0 }
-			}
-		] ),
-		vertexShader: ShaderChunk[ 'shadow_vert' ],
-		fragmentShader: ShaderChunk[ 'shadow_frag' ]
-	} );
+	Material.call( this );
+
+	this.type = 'ShadowMaterial';
+
+	this.color = new Color( 0x000000 );
+	this.opacity = 1.0;
 
 	this.lights = true;
 	this.transparent = true;
 
-	Object.defineProperties( this, {
-		color: {
-			enumerable: true,
-			get: function () {
-				return this.uniforms.color.value;
-			},
-			set: function ( value ) {
-				this.uniforms.color.value = value;
-			}
-		},
-		opacity: {
-			enumerable: true,
-			get: function () {
-				return this.uniforms.opacity.value;
-			},
-			set: function ( value ) {
-				this.uniforms.opacity.value = value;
-			}
-		}
-	} );
-
 	this.setValues( parameters );
 
 }
 
-ShadowMaterial.prototype = Object.create( ShaderMaterial.prototype );
+ShadowMaterial.prototype = Object.create( Material.prototype );
 ShadowMaterial.prototype.constructor = ShadowMaterial;
 
 ShadowMaterial.prototype.isShadowMaterial = true;

+ 5 - 0
src/renderers/WebGLRenderer.js

@@ -1816,6 +1816,11 @@ function WebGLRenderer( parameters ) {
 
 				refreshUniformsNormal( m_uniforms, material );
 
+			} else if ( material.isShadowMaterial ) {
+
+				m_uniforms.color.value = material.color;
+				m_uniforms.opacity.value = material.opacity;
+
 			}
 
 			// RectAreaLight Texture

+ 15 - 0
src/renderers/shaders/ShaderLib.js

@@ -205,6 +205,21 @@ var ShaderLib = {
 		vertexShader: ShaderChunk.distanceRGBA_vert,
 		fragmentShader: ShaderChunk.distanceRGBA_frag
 
+	},
+
+	shadow: {
+
+		uniforms: UniformsUtils.merge( [
+			UniformsLib.lights,
+			{
+				color: { value: new Color( 0x00000 ) },
+				opacity: { value: 1.0 }
+			},
+		] ),
+
+		vertexShader: ShaderChunk.shadow_vert,
+		fragmentShader: ShaderChunk.shadow_frag
+
 	}
 
 };

+ 2 - 1
src/renderers/webgl/WebGLPrograms.js

@@ -21,7 +21,8 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
 		MeshPhysicalMaterial: 'physical',
 		LineBasicMaterial: 'basic',
 		LineDashedMaterial: 'dashed',
-		PointsMaterial: 'points'
+		PointsMaterial: 'points',
+		ShadowMaterial: 'shadow'
 	};
 
 	var parameterNames = [