瀏覽代碼

add lightScale parameter which varies the intensity of the lightMap.

Ben Houston 10 年之前
父節點
當前提交
b593b45f9d

+ 6 - 1
examples/webgl_materials_lightmap.html

@@ -100,7 +100,7 @@
 
 				// LIGHTS
 
-				var hemiLight = new THREE.HemisphereLight( 0xaabbff, 0x040404, 0.5 );
+				var hemiLight = new THREE.HemisphereLight( 0xaabbff, 0x040404, 0.3 );
 
 				hemiLight.position.y = 500;
 				scene.add( hemiLight );
@@ -152,7 +152,12 @@
 				var loader = new THREE.JSONLoader();
 				loader.load( "obj/lightmap/lightmap.js", function ( geometry, materials ) {
 
+					for( var i = 0; i < materials.length; i ++ ) {
+						materials[i].lightScale = 0.75;
+					}
+
 					var mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
+
 					mesh.scale.multiplyScalar( 100 );
 					scene.add( mesh );
 

+ 7 - 0
src/materials/MeshPhongMaterial.js

@@ -12,7 +12,10 @@
  *  map: new THREE.Texture( <Image> ),
  *
  *  lightMap: new THREE.Texture( <Image> ),
+ *  lightScale: <float>
+ *
  *  aoMap: new THREE.Texture( <Image> ),
+ *  aoScale: <float>
  *
  *  bumpMap: new THREE.Texture( <Image> ),
  *  bumpScale: <float>,
@@ -66,6 +69,8 @@ THREE.MeshPhongMaterial = function ( parameters ) {
 	this.map = null;
 
 	this.lightMap = null;
+	this.lightScale = null;
+
 	this.aoMap = null;
 	this.aoScale = 1.0;
 
@@ -125,6 +130,8 @@ THREE.MeshPhongMaterial.prototype.clone = function () {
 	material.map = this.map;
 
 	material.lightMap = this.lightMap;
+	material.lightScale = this.lightScale;
+
 	material.aoMap = this.aoMap;
 	material.aoScale = this.aoScale;
 

+ 1 - 0
src/renderers/WebGLRenderer.js

@@ -4596,6 +4596,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		uniforms.map.value = material.map;
 		uniforms.lightMap.value = material.lightMap;
+		uniforms.lightScale.value = material.lightScale;
 		uniforms.aoMap.value = material.aoMap;
 		uniforms.aoScale.value = material.aoScale;
 		uniforms.specularMap.value = material.specularMap;

+ 1 - 1
src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl

@@ -1,5 +1,5 @@
 #ifdef USE_LIGHTMAP
 
-	outgoingLight += diffuseColor.xyz * texture2D( lightMap, vUv2 ).xyz;
+	outgoingLight += diffuseColor.xyz * texture2D( lightMap, vUv2 ).xyz * lightScale;
 
 #endif

+ 1 - 0
src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl

@@ -1,5 +1,6 @@
 #ifdef USE_LIGHTMAP
 
 	uniform sampler2D lightMap;
+	uniform float lightScale;
 
 #endif

+ 1 - 0
src/renderers/shaders/UniformsLib.js

@@ -13,6 +13,7 @@ THREE.UniformsLib = {
 		"offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
 
 		"lightMap" : { type: "t", value: null },
+		"lightScale" : { type: "f", value: 1 },
 
 		"aoMap" : { type: "t", value: null },
 		"aoScale" : { type: "f", value: 1 },