]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - client/shaders/nodes_shader/opengl_fragment.glsl
Remove "generate normal maps" feature (#10313)
[dragonfireclient.git] / client / shaders / nodes_shader / opengl_fragment.glsl
index 149aa2bc5b72be7df39b767000fd85f4a47d6208..437b325d3f831e35afe9b7190edcc909ca91b5fa 100644 (file)
@@ -6,7 +6,16 @@ uniform vec4 skyBgColor;
 uniform float fogDistance;
 uniform vec3 eyePosition;
 
+// The cameraOffset is the current center of the visible world.
+uniform vec3 cameraOffset;
+uniform float animationTimer;
+
 varying vec3 vPosition;
+// World position in the visible world (i.e. relative to the cameraOffset.)
+// This can be used for many shader effects without loss of precision.
+// If the absolute position is required it can be calculated with
+// cameraOffset + worldPosition (for large coordinates the limits of float
+// precision must be considered).
 varying vec3 worldPosition;
 varying float area_enable_parallax;
 
@@ -19,7 +28,7 @@ bool normalTexturePresent = false;
 
 const float e = 2.718281828459;
 const float BS = 10.0;
-const float fogStart = 0.4;
+const float fogStart = FOG_START;
 const float fogShadingParameter = 1 / ( 1 - fogStart);
 
 #ifdef ENABLE_TONE_MAPPING
@@ -37,7 +46,7 @@ const float fogShadingParameter = 1 / ( 1 - fogStart);
 
 vec3 uncharted2Tonemap(vec3 x)
 {
-       return ((x * (0.22 * x + 0.03) + 0.002) / (x * (0.22 * x + 0.3) + 0.06)) - 0.03334;
+       return ((x * (0.22 * x + 0.03) + 0.002) / (x * (0.22 * x + 0.3) + 0.06)) - 0.03333;
 }
 
 vec4 applyToneMapping(vec4 color)
@@ -62,16 +71,6 @@ void get_texture_flags()
        }
 }
 
-float intensity(vec3 color)
-{
-       return (color.r + color.g + color.b) / 3.0;
-}
-
-float get_rgb_height(vec2 uv)
-{
-       return intensity(texture2D(baseTexture, uv).rgb);
-}
-
 vec4 get_normal_map(vec2 uv)
 {
        vec4 bump = texture2D(normalTexture, uv).rgba;
@@ -106,19 +105,6 @@ float find_intersection(vec2 dp, vec2 ds)
        return best_depth;
 }
 
-float find_intersectionRGB(vec2 dp, vec2 ds)
-{
-       const float depth_step = 1.0 / 24.0;
-       float depth = 1.0;
-       for (int i = 0 ; i < 24 ; i++) {
-               float h = get_rgb_height(dp + ds * depth);
-               if (h >= depth)
-                       break;
-               depth -= depth_step;
-       }
-       return depth;
-}
-
 void main(void)
 {
        vec3 color;
@@ -140,21 +126,17 @@ void main(void)
                        float h = normal.a * scale - bias;
                        uv += h * normal.z * eyeRay;
                }
+       }
 #endif
-
 #if PARALLAX_OCCLUSION_MODE == 1
        // Relief mapping
        if (normalTexturePresent && area_enable_parallax > 0.0) {
                vec2 ds = eyeRay * PARALLAX_OCCLUSION_SCALE;
                float dist = find_intersection(uv, ds);
                uv += dist * ds;
-#endif
-       } else if (GENERATE_NORMALMAPS == 1 && area_enable_parallax > 0.0) {
-               vec2 ds = eyeRay * PARALLAX_OCCLUSION_SCALE;
-               float dist = find_intersectionRGB(uv, ds);
-               uv += dist * ds;
        }
 #endif
+#endif
 
 #if USE_NORMALMAPS == 1
        if (normalTexturePresent) {
@@ -163,23 +145,16 @@ void main(void)
        }
 #endif
 
-       if (GENERATE_NORMALMAPS == 1 && normalTexturePresent == false) {
-               float tl = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y + SAMPLE_STEP));
-               float t  = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y - SAMPLE_STEP));
-               float tr = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y + SAMPLE_STEP));
-               float r  = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y));
-               float br = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y - SAMPLE_STEP));
-               float b  = get_rgb_height(vec2(uv.x, uv.y - SAMPLE_STEP));
-               float bl = get_rgb_height(vec2(uv.x -SAMPLE_STEP, uv.y - SAMPLE_STEP));
-               float l  = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y));
-               float dX = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl);
-               float dY = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr);
-               bump = vec4(normalize(vec3 (dX, dY, NORMALMAPS_STRENGTH)), 1.0);
-               use_normalmap = true;
-       }
-
        vec4 base = texture2D(baseTexture, uv).rgba;
 
+#ifdef USE_DISCARD
+       // If alpha is zero, we can just discard the pixel. This fixes transparency
+       // on GPUs like GC7000L, where GL_ALPHA_TEST is not implemented in mesa.
+       if (base.a == 0.0) {
+               discard;
+       }
+#endif
+
 #ifdef ENABLE_BUMPMAPPING
        if (use_normalmap) {
                vec3 L = normalize(lightVec);
@@ -200,20 +175,18 @@ void main(void)
        col = applyToneMapping(col);
 #endif
 
-       if (fogDistance != 0.0) {
-               // Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?),
-               // the fog will only be rendered correctly if the last operation before the
-               // clamp() is an addition. Else, the clamp() seems to be ignored.
-               // E.g. the following won't work:
-               //      float clarity = clamp(fogShadingParameter
-               //              * (fogDistance - length(eyeVec)) / fogDistance), 0.0, 1.0);
-               // As additions usually come for free following a multiplication, the new formula
-               // should be more efficient as well.
-               // Note: clarity = (1 - fogginess)
-               float clarity = clamp(fogShadingParameter
-                       - fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
-               col = mix(skyBgColor, col, clarity);
-       }
+       // Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?),
+       // the fog will only be rendered correctly if the last operation before the
+       // clamp() is an addition. Else, the clamp() seems to be ignored.
+       // E.g. the following won't work:
+       //      float clarity = clamp(fogShadingParameter
+       //              * (fogDistance - length(eyeVec)) / fogDistance), 0.0, 1.0);
+       // As additions usually come for free following a multiplication, the new formula
+       // should be more efficient as well.
+       // Note: clarity = (1 - fogginess)
+       float clarity = clamp(fogShadingParameter
+               - fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
+       col = mix(skyBgColor, col, clarity);
        col = vec4(col.rgb, base.a);
 
        gl_FragColor = col;