Browse Source

make disabling mipmap the default in the cube_uv shader for performance reasons.

Ben Houston 9 years ago
parent
commit
936c2ad329
1 changed files with 28 additions and 6 deletions
  1. 28 6
      src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl

+ 28 - 6
src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl

@@ -1,5 +1,8 @@
+#define DISABLE_CUBE_UV_MIPMAP_INTERPOLATION
+
 #ifdef ENVMAP_TYPE_CUBE_UV
 #ifdef ENVMAP_TYPE_CUBE_UV
 
 
+
 int getFaceFromDirection(vec3 direction) {
 int getFaceFromDirection(vec3 direction) {
     vec3 absDirection = abs(direction);
     vec3 absDirection = abs(direction);
     int face = -1;
     int face = -1;
@@ -103,19 +106,38 @@ vec4 textureCubeUV(vec3 reflectedDirection, float roughness, float textureSize)
     float level0 = mipInfo.x;
     float level0 = mipInfo.x;
     float level1 = level0 + 1.0;
     float level1 = level0 + 1.0;
     level1 = level1 > 5.0 ? 5.0 : level1;
     level1 = level1 > 5.0 ? 5.0 : level1;
+
+#if defined( DISABLE_CUBE_UV_MIPMAP_INTERPOLATION )
+    level0 += min( floor( s + 1.0 ), 5.0 );
+#endif
+
     // Tri linear interpolation.
     // Tri linear interpolation.
     vec2 uv_10 = getCubeUV(reflectedDirection, r1, level0, textureSize);
     vec2 uv_10 = getCubeUV(reflectedDirection, r1, level0, textureSize);
-    vec2 uv_11 = getCubeUV(reflectedDirection, r1, level1, textureSize);
-    vec2 uv_20 = getCubeUV(reflectedDirection, r2, level0, textureSize);
-    vec2 uv_21 = getCubeUV(reflectedDirection, r2, level1, textureSize);
     vec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));
     vec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));
-    vec4 color11 = envMapTexelToLinear(texture2D(envMap, uv_11));
+
+    vec2 uv_20 = getCubeUV(reflectedDirection, r2, level0, textureSize);
     vec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));
     vec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));
+
+    vec4 result = mix(color10 , color20,  t);
+
+#if ! defined( DISABLE_CUBE_UV_MIPMAP_INTERPOLATION )
+
+    vec2 uv_11 = getCubeUV(reflectedDirection, r1, level1, textureSize);
+    vec4 color11 = envMapTexelToLinear(texture2D(envMap, uv_11));
+
+    vec2 uv_21 = getCubeUV(reflectedDirection, r2, level1, textureSize);
     vec4 color21 = envMapTexelToLinear(texture2D(envMap, uv_21));
     vec4 color21 = envMapTexelToLinear(texture2D(envMap, uv_21));
+
+    vec4 c2 = mix(color11 , color21,  t);
+    result = mix(result , c2,  s);
+    
+#endif
+/*
     vec4 c1 = mix(color10 , color11,  s);
     vec4 c1 = mix(color10 , color11,  s);
     vec4 c2 = mix(color20 , color21,  s);
     vec4 c2 = mix(color20 , color21,  s);
-    vec4 c3 = mix(c1 , c2,  t);
-    return vec4(c3.rgb, 1.0);
+    vec4 c3 = mix(c1 , c2,  t);*/
+
+    return vec4(result.rgb, 1.0);
 }
 }
 
 
 #endif
 #endif