Browse Source

Unrolled shadow filtering loops to work on ATI OpenGL.

ATI OpenGL shader compiler doesn't seem to like texture access with UV coordinates generated in a loop.
alteredq 13 years ago
parent
commit
ab0ce36091
3 changed files with 44 additions and 2 deletions
  1. 0 1
      build/Three.js
  2. 0 1
      build/custom/ThreeWebGL.js
  3. 44 0
      src/renderers/WebGLShaders.js

File diff suppressed because it is too large
+ 0 - 1
build/Three.js


File diff suppressed because it is too large
+ 0 - 1
build/custom/ThreeWebGL.js


+ 44 - 0
src/renderers/WebGLShaders.js

@@ -769,12 +769,16 @@ THREE.ShaderChunk = {
 			"#endif",
 
 			"vec3 shadowColor = vec3( 1.0 );",
+			"float fDepth;",
 
 			"for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
 
 				"vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;",
 				"shadowCoord.z += shadowBias;",
 
+				// using "if ( all )" for ATI OpenGL shader compiler
+				// "if ( something && something )" breaks it
+
 				"bvec4 shadowTest = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );",
 
 				"if ( all( shadowTest ) ) {",
@@ -787,6 +791,10 @@ THREE.ShaderChunk = {
 
 						"float shadow = 0.0;",
 
+						/*
+						// this breaks shader compiler / validator on some ATI cards when using OpenGL
+						// must enroll loop manually
+
 						"for ( float y = -1.25; y <= 1.25; y += 1.25 )",
 							"for ( float x = -1.25; x <= 1.25; x += 1.25 ) {",
 
@@ -803,6 +811,42 @@ THREE.ShaderChunk = {
 						"}",
 
 						"shadow /= 9.0;",
+
+						*/
+
+						"const float shadowDelta = 1.0 / 9.0;",
+						"const float dx0 = -1.25 * xPixelOffset;",
+						"const float dy0 = -1.25 * yPixelOffset;",
+						"const float dx1 = 1.25 * xPixelOffset;",
+						"const float dy1 = 1.25 * yPixelOffset;",
+
+						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );",
+						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
+
+						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );",
+						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
+
+						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );",
+						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
+
+						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );",
+						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
+
+						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );",
+						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
+
+						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );",
+						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
+
+						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );",
+						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
+
+						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );",
+						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
+
+						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );",
+						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
+
 						"shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness * shadow ) );",
 
 					"#else",

Some files were not shown because too many files changed in this diff