浏览代码

Restored aoMap to MeshBasicMaterial

WestLangley 10 年之前
父节点
当前提交
6475b29ab8

+ 10 - 6
docs/api/materials/MeshBasicMaterial.html

@@ -24,7 +24,8 @@
 		<div>parameters is an object with one or more properties defining the material's appearance.</div>
 		<div>
 		color — geometry color in hexadecimal. Default is 0xffffff.<br />
-		map — Sets the texture map. Default is null <br />
+		map — Set texture map. Default is null <br />
+		aoMap — Set ambient occlusion map. Default is null <br />
 		specularMap — Set specular map. Default is null.<br />
 		alphaMap — Set alpha map. Default is null.<br />
 		envMap — Set env map. Default is null.<br />
@@ -44,6 +45,14 @@
 		<h3>[property:Integer color]</h3>
 		<div>Sets the color of the geometry. Default is 0xffffff.</div>
 		
+		<h3>[property:Texture map]</h3>
+		<div>
+		Set texture map. Default is  null.
+		</div>
+
+		<h3>[property:Texture aoMap]</h3>
+		<div>Set ambient occlusion map. Default is null.</div>
+
 		<h3>[property:Texture specularMap]</h3>
 		<div>Set specular map. Default is null.</div>
 
@@ -86,11 +95,6 @@
 		<h3>[property:Boolean morphTargets]</h3>
 		<div>Define whether the material uses morphTargets. Default is false.</div>	
 		
-		<h3>[property:Texture map]</h3>
-		<div>
-		Sets the texture map. Default is  null.
-		</div> 
-
 		<h3>[property:number combine]</h3>
 		<div>
 		How to combine the result of the surface's color with the environment map, if any.

+ 5 - 1
docs/api/materials/MeshPhongMaterial.html

@@ -24,8 +24,9 @@
 		</div>
 		<div>
 		color — geometry color in hexadecimal. Default is 0xffffff.<br />
-		map — Sets the texture map. Default is null <br />
+		map — Set texture map. Default is null <br />
 		lightMap — Set light map. Default is null.<br />
+		aoMap — Set ao map. Default is null.<br />
 		specularMap — Set specular map. Default is null.<br />
 		alphaMap — Set alpha map. Default is null.<br />
 		envMap — Set env map. Default is null.<br />
@@ -80,6 +81,9 @@
 		<h3>[property:Texture lightMap]</h3>
 		<div>Set light map. Default is null.</div>
 
+		<h3>[property:Texture aoMap]</h3>
+		<div>Set ambient occlusion map. Default is null.</div>
+
 		<h3>[property:Texture bumpMap]</h3>
 		<div>
 			The texture to create a bump map. The black and white values map to the perceived depth in relation to the lights.

+ 9 - 0
src/materials/MeshBasicMaterial.js

@@ -7,6 +7,9 @@
  *  opacity: <float>,
  *  map: new THREE.Texture( <Image> ),
  *
+ *  aoMap: new THREE.Texture( <Image> ),
+ *  aoMapIntensity: <float>
+ *
  *  specularMap: new THREE.Texture( <Image> ),
  *
  *  alphaMap: new THREE.Texture( <Image> ),
@@ -43,6 +46,9 @@ THREE.MeshBasicMaterial = function ( parameters ) {
 
 	this.map = null;
 
+	this.aoMap = null;
+	this.aoMapIntensity = 1.0;
+
 	this.specularMap = null;
 
 	this.alphaMap = null;
@@ -83,6 +89,9 @@ THREE.MeshBasicMaterial.prototype.clone = function () {
 
 	material.map = this.map;
 
+	material.aoMap = this.aoMap;
+	material.aoMapIntensity = this.aoMapIntensity;
+
 	material.specularMap = this.specularMap;
 
 	material.alphaMap = this.alphaMap;

+ 11 - 0
src/renderers/WebGLRenderer.js

@@ -2255,6 +2255,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				refreshUniformsLambert( m_uniforms, material );
 
+			} else if ( material instanceof THREE.MeshBasicMaterial ) {
+
+				refreshUniformsBasic( m_uniforms, material );
+
 			} else if ( material instanceof THREE.MeshDepthMaterial ) {
 
 				m_uniforms.mNear.value = camera.near;
@@ -2438,6 +2442,13 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	}
 
+	function refreshUniformsBasic ( uniforms, material ) {
+
+		uniforms.aoMap.value = material.aoMap;
+		uniforms.aoMapIntensity.value = material.aoMapIntensity;
+
+	}
+
 	function refreshUniformsLights ( uniforms, lights ) {
 
 		uniforms.ambientLightColor.value = lights.ambient;

+ 6 - 2
src/renderers/shaders/ShaderLib.js

@@ -14,6 +14,7 @@ THREE.ShaderLib = {
 		uniforms: THREE.UniformsUtils.merge( [
 
 			THREE.UniformsLib[ "common" ],
+			THREE.UniformsLib[ "aomap" ],
 			THREE.UniformsLib[ "fog" ],
 			THREE.UniformsLib[ "shadowmap" ]
 
@@ -70,6 +71,7 @@ THREE.ShaderLib = {
 			THREE.ShaderChunk[ "uv2_pars_fragment" ],
 			THREE.ShaderChunk[ "map_pars_fragment" ],
 			THREE.ShaderChunk[ "alphamap_pars_fragment" ],
+			THREE.ShaderChunk[ "aomap_pars_fragment" ],
 			THREE.ShaderChunk[ "envmap_pars_fragment" ],
 			THREE.ShaderChunk[ "fog_pars_fragment" ],
 			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
@@ -78,8 +80,9 @@ THREE.ShaderLib = {
 
 			"void main() {",
 
-			"	vec3 outgoingLight = vec3( 0.0 );",	// outgoing light does not have an alpha, the surface does
+			"	vec3 outgoingLight = vec3( 0.0 );",
 			"	vec4 diffuseColor = vec4( diffuse, opacity );",
+			"	vec3 totalAmbientLight = vec3( 1.0 );", // hardwired
 
 				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
 				THREE.ShaderChunk[ "map_fragment" ],
@@ -87,8 +90,9 @@ THREE.ShaderLib = {
 				THREE.ShaderChunk[ "alphamap_fragment" ],
 				THREE.ShaderChunk[ "alphatest_fragment" ],
 				THREE.ShaderChunk[ "specularmap_fragment" ],
+				THREE.ShaderChunk[ "aomap_fragment" ],
 
-			"	outgoingLight = diffuseColor.rgb;", // simple shader
+			"	outgoingLight = diffuseColor.rgb * totalAmbientLight;", // simple shader
 
 				THREE.ShaderChunk[ "envmap_fragment" ],
 				THREE.ShaderChunk[ "shadowmap_fragment" ],		// TODO: Shadows on an otherwise unlit surface doesn't make sense.