vec3 ssr_Block(vec3 RVec, float Dist, vec3 ViewPos, float Fresnel, float WNy, bool IsDH, sampler2D lightmap,vec2 lmcoord,float SkyBrightness,vec3 color) {
    vec3 ScreenPos = vec3(gl_FragCoord.xy * resolutionInv, gl_FragCoord.z);

    // Robust ray setup to prevent visual artifacts from zero-length or axis-aligned rays.
    vec3 deltaPos = view_screen(ViewPos + RVec, IsDH) - ScreenPos;
    if (dot(deltaPos, deltaPos) < 1e-6) {
       return sky_reflection(RVec, WNy, Dist, ViewPos, lightmap, lmcoord) * SSR_BRIGHTNESS * 0.5;
    }
    vec3 Offset = normalize(deltaPos);

    // Division-by-zero protection.
    vec3 safeOffset = Offset;
    if (abs(safeOffset.x) < 1e-5) safeOffset.x = 1e-5;
    if (abs(safeOffset.y) < 1e-5) safeOffset.y = 1e-5;
    if (abs(safeOffset.z) < 1e-5) safeOffset.z = 1e-5;

    vec3 Len = (step(0.0, Offset) - ScreenPos) / safeOffset;
    float MinLen = min(Len.x, min(Len.y, Len.z)) / SSR_STEPS;
    Offset *= MinLen;

    float Noise = dither(gl_FragCoord.xy);
    vec3 ExpectedPos = ScreenPos + Offset * Noise;
    for (int i = 1; i <= SSR_STEPS; i++) {
        float RealDepth = get_depth_solid(ExpectedPos.xy, IsDH);
        if (RealDepth < 0.56) { // Avoid reflecting the hand model, which is in the foreground
            break;
        }

        if (ExpectedPos.z > RealDepth) {
            if (ExpectedPos.z - RealDepth > Offset.z * (0.5 * SSR_STEPS)) {
                break;
            }
            for (int j = 1; j <= int(round(Fresnel * 3)); j++) {
                Offset /= 2.0;
                vec3 EPos1 = ExpectedPos - Offset;
                float RDepth1 = get_depth_solid(EPos1.xy, IsDH);
                if (EPos1.z > RDepth1) {
                    ExpectedPos = EPos1;
                }
            }
            // TINT THE SSR REFLECTIONS BLUE TOO
            vec3 rawSSR = texture2D(gaux1, ExpectedPos.xy).rgb;
            if(IsDH){
                 return clamp(rawSSR ,0.0,1.0);
            }else {
                // Soften the brightness reduction during sunrise/sunset for a more natural look.
                float brightness = SSR_BRIGHTNESS * (1.0 - (sunriseStrength + sunsetStrength) * 0.2);
                return clamp(rawSSR * brightness, 0.0, 1.0);
            }
        }
        ExpectedPos += Offset;
    }
    // Fallback to a dimmed sky reflection. Mixing with the block's own color can look muddy.
    return sky_reflection(RVec, WNy, Dist, ViewPos, lightmap, lmcoord) * SSR_BRIGHTNESS * 0.5;
}