diff --git a/rpcs3/Emu/RSX/Program/GLSLCommon.cpp b/rpcs3/Emu/RSX/Program/GLSLCommon.cpp index d8c0689323..3af0c083b7 100644 --- a/rpcs3/Emu/RSX/Program/GLSLCommon.cpp +++ b/rpcs3/Emu/RSX/Program/GLSLCommon.cpp @@ -603,27 +603,19 @@ namespace glsl { if (props.emulate_depth_clip_only) { - // Declare rcp_precise. Requires f64 support in the drivers. - // This is required to handle precision drift during division for extended depth range. - OS << - "double rcp_precise(double x)\n" - "{\n" - " double scaled = x * 0.0009765625;\n" - " double inv = 1.0 / scaled;\n" - " return inv * 0.0009765625;\n" - "}\n" - "\n" // Technically the depth value here is the 'final' depth that should be stored in the Z buffer. // Forward mapping eqn is d' = d * (f - n) + n, where d' is the stored Z value (this) and d is the normalized API value. + OS << "vec4 apply_zclip_xform(const in vec4 pos, const in float near_plane, const in float far_plane)\n" "{\n" - " if (far_plane != 0.0 && pos.w != 0.0)\n" + " if (pos.w != 0.0)\n" " {\n" - " double z_range = (far_plane > near_plane)? (far_plane - near_plane) : far_plane;\n" - " double inv_range = rcp_precise(z_range);\n" - " float d = float(pos.z * rcp_precise(pos.w));\n" - " float new_d = (d - near_plane) * float(inv_range);\n" - " return vec4(pos.x, pos.y, (new_d * pos.w), pos.w);\n" + " const float real_n = min(far_plane, near_plane);\n" + " const float real_f = max(far_plane, near_plane);\n" + " const double depth_range = double(real_f - real_n);\n" + " const double inv_range = (depth_range > 0.0) ? (1.0 / (depth_range * pos.w)) : 0.0;\n" + " const double d = (double(pos.z) - real_n) * inv_range;\n" + " return vec4(pos.xy, float(d * pos.w), pos.w);\n" " }\n" " else\n" " {\n"