Browse Source

Refactored bump mapping handling so that it's possible to have bump map without color map.

alteredq 13 năm trước cách đây
mục cha
commit
ae7e147f4e

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 88 - 88
build/Three.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 59 - 58
build/custom/ThreeWebGL.js


+ 3 - 5
examples/webgl_materials_bumpmap.html

@@ -150,15 +150,13 @@
 
 
 				var mapHeight = THREE.ImageUtils.loadTexture( "obj/leeperrysmith/Infinite-Level_02_Disp_NoSmoothUV-4096.jpg" );
-				var mapDummy = THREE.ImageUtils.generateDataTexture( 1, 1, new THREE.Color( 0xffffff ) );
 
 				mapHeight.anisotropy = 16;
-
-				mapDummy.repeat.set( 0.998, 0.998 );
-				mapDummy.offset.set( 0.001, 0.001 )
+				mapHeight.repeat.set( 0.998, 0.998 );
+				mapHeight.offset.set( 0.001, 0.001 )
 				mapHeight.wrapS = mapHeight.wrapT = THREE.RepeatWrapping;
 
-				var material = new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0x333333, shininess: 25, perPixel: true, map: mapDummy, bumpMap: mapHeight, bumpScale: 19, metal: false } );
+				var material = new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0x333333, shininess: 25, perPixel: true, bumpMap: mapHeight, bumpScale: 19, metal: false } );
 
 				loader = new THREE.JSONLoader( true );
 				document.body.appendChild( loader.statusDomElement );

+ 26 - 1
src/renderers/WebGLRenderer.js

@@ -5000,6 +5000,12 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			uniforms.bumpScale.value = material.bumpScale;
 
+			if ( ! material.map ) {
+
+				uniforms.offsetRepeat.value.set( material.bumpMap.offset.x, material.bumpMap.offset.y, material.bumpMap.repeat.x, material.bumpMap.repeat.y );
+
+			}
+
 		}
 
 		uniforms.envMap.texture = material.envMap;
@@ -5926,6 +5932,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			"precision " + _precision + " float;",
 
+			parameters.bumpMap ? "#extension GL_OES_standard_derivatives : enable" : "",
+
 			"#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
 			"#define MAX_POINT_LIGHTS " + parameters.maxPointLights,
 			"#define MAX_SPOT_LIGHTS " + parameters.maxSpotLights,
@@ -6084,6 +6092,23 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	};
 
+	function addLineNumbers ( string ) {
+
+		var chunks = string.split( "\n" );
+
+		for ( var i = 0, il = chunks.length; i < il; i ++ ) {
+
+			// Chrome reports shader errors on lines
+			// starting counting from 1
+
+			chunks[ i ] = ( i + 1 ) + ": " + chunks[ i ];
+
+		}
+
+		return chunks.join( "\n" );
+
+	};
+
 	function getShader ( type, string ) {
 
 		var shader;
@@ -6104,7 +6129,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 		if ( !_gl.getShaderParameter( shader, _gl.COMPILE_STATUS ) ) {
 
 			console.error( _gl.getShaderInfoLog( shader ) );
-			console.error( string );
+			console.error( addLineNumbers( string ) );
 			return null;
 
 		}

+ 9 - 6
src/renderers/WebGLShaders.js

@@ -166,7 +166,7 @@ THREE.ShaderChunk = {
 
 	map_pars_vertex: [
 
-		"#ifdef USE_MAP",
+		"#if defined( USE_MAP ) || defined( USE_BUMPMAP )",
 
 			"varying vec2 vUv;",
 			"uniform vec4 offsetRepeat;",
@@ -177,18 +177,23 @@ THREE.ShaderChunk = {
 
 	map_pars_fragment: [
 
-		"#ifdef USE_MAP",
+		"#if defined( USE_MAP ) || defined( USE_BUMPMAP )",
 
 			"varying vec2 vUv;",
+
+		"#endif",
+
+		"#ifdef USE_MAP",
+
 			"uniform sampler2D map;",
 
-		"#endif"
+		"#endif",
 
 	].join("\n"),
 
 	map_vertex: [
 
-		"#ifdef USE_MAP",
+		"#if defined( USE_MAP ) || defined( USE_BUMPMAP )",
 
 			"vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
 
@@ -266,8 +271,6 @@ THREE.ShaderChunk = {
 
 		"#ifdef USE_BUMPMAP",
 
-			"#extension GL_OES_standard_derivatives : enable",
-
 			"uniform sampler2D bumpMap;",
 			"uniform float bumpScale;",
 

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác