瀏覽代碼

Refactored environment mapping to use bump mapped normals (if available).

alteredq 13 年之前
父節點
當前提交
a5a38ae323
共有 3 個文件被更改,包括 50 次插入12 次删除
  1. 2 2
      build/Three.js
  2. 3 3
      build/custom/ThreeWebGL.js
  3. 45 7
      src/renderers/WebGLShaders.js

文件差異過大導致無法顯示
+ 2 - 2
build/Three.js


文件差異過大導致無法顯示
+ 3 - 3
build/custom/ThreeWebGL.js


+ 45 - 7
src/renderers/WebGLShaders.js

@@ -59,13 +59,22 @@ THREE.ShaderChunk = {
 
 		"#ifdef USE_ENVMAP",
 
-			"varying vec3 vReflect;",
-
 			"uniform float reflectivity;",
 			"uniform samplerCube envMap;",
 			"uniform float flipEnvMap;",
 			"uniform int combine;",
 
+			"#ifdef USE_BUMPMAP",
+
+				"uniform bool useRefract;",
+				"uniform float refractionRatio;",
+
+			"#else",
+
+				"varying vec3 vReflect;",
+
+			"#endif",
+
 		"#endif"
 
 	].join("\n"),
@@ -74,14 +83,34 @@ THREE.ShaderChunk = {
 
 		"#ifdef USE_ENVMAP",
 
+			"vec3 reflectVec;",
+
+			"#ifdef USE_BUMPMAP",
+
+				"if ( useRefract ) {",
+
+					"reflectVec = refract( normalize( vWorldPosition - cameraPosition ), normal, refractionRatio );",
+
+				"} else { ",
+
+					"reflectVec = reflect( normalize( vWorldPosition - cameraPosition ), normal );",
+
+				"}",
+
+			"#else",
+
+				"reflectVec = vReflect;",
+
+			"#endif",
+
 			"#ifdef DOUBLE_SIDED",
 
 				"float flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );",
-				"vec4 cubeColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * vReflect.x, vReflect.yz ) );",
+				"vec4 cubeColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );",
 
 			"#else",
 
-				"vec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * vReflect.x, vReflect.yz ) );",
+				"vec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );",
 
 			"#endif",
 
@@ -107,7 +136,7 @@ THREE.ShaderChunk = {
 
 	envmap_pars_vertex: [
 
-		"#ifdef USE_ENVMAP",
+		"#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP )",
 
 			"varying vec3 vReflect;",
 
@@ -123,6 +152,11 @@ THREE.ShaderChunk = {
 		"#ifdef USE_ENVMAP",
 
 			"vec4 mPosition = modelMatrix * vec4( position, 1.0 );",
+
+		"#endif",
+
+		"#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP )",
+
 			"vec3 nWorld = mat3( modelMatrix[ 0 ].xyz, modelMatrix[ 1 ].xyz, modelMatrix[ 2 ].xyz ) * normal;",
 
 			"if ( useRefract ) {",
@@ -565,7 +599,7 @@ THREE.ShaderChunk = {
 
 		"#endif",
 
-		"#if MAX_SPOT_LIGHTS > 0",
+		"#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP )",
 
 			"varying vec3 vWorldPosition;",
 
@@ -614,7 +648,7 @@ THREE.ShaderChunk = {
 
 		"#endif",
 
-		"#if MAX_SPOT_LIGHTS > 0",
+		"#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP )",
 
 			"vWorldPosition = mPosition.xyz;",
 
@@ -668,6 +702,10 @@ THREE.ShaderChunk = {
 
 			"#endif",
 
+		"#endif",
+
+		"#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP )",
+
 			"varying vec3 vWorldPosition;",
 
 		"#endif",

部分文件因文件數量過多而無法顯示