Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsx: Remove zclip hackery #11268

Merged
merged 4 commits into from
Dec 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 8 additions & 16 deletions rpcs3/Emu/RSX/Program/GLSLCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.000001) ? (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"
Expand Down