glsl: improve the logz handling

This way only 0 and 1 will conflict
This commit is contained in:
Gregory Hainaut 2015-04-26 17:51:33 +02:00
parent 768ae342c3
commit 301fe869c7
2 changed files with 4 additions and 18 deletions

View File

@ -116,13 +116,6 @@ void vs_main()
else else
z = i_z; z = i_z;
if(VS_LOGZ == 1) {
// FIXME some games (FFX12 intro) uses MAX_INT as depth parameter. So I replace the +1 with an OR
// Initially a +1 was done to avoid log2(0) (If I'm correct)
// The or mask won't create any overflow
z |= 1u;
}
// pos -= 0.05 (1/320 pixel) helps avoiding rounding problems (integral part of pos is usually 5 digits, 0.05 is about as low as we can go) // pos -= 0.05 (1/320 pixel) helps avoiding rounding problems (integral part of pos is usually 5 digits, 0.05 is about as low as we can go)
// example: ceil(afterseveralvertextransformations(y = 133)) => 134 => line 133 stays empty // example: ceil(afterseveralvertextransformations(y = 133)) => 134 => line 133 stays empty
// input granularity is 1/16 pixel, anything smaller than that won't step drawing up/left by one pixel // input granularity is 1/16 pixel, anything smaller than that won't step drawing up/left by one pixel
@ -134,13 +127,13 @@ void vs_main()
p.w = 1.0f; p.w = 1.0f;
#ifdef ZERO_TO_ONE_DEPTH #ifdef ZERO_TO_ONE_DEPTH
if(VS_LOGZ == 1) { if(VS_LOGZ == 1) {
p.z = log2(float(z)) / 32.0f; p.z = max(0.0f, log2(float(z))) / 32.0f;
} else { } else {
p.z = float(z) * exp_min32; p.z = float(z) * exp_min32;
} }
#else #else
if(VS_LOGZ == 1) { if(VS_LOGZ == 1) {
p.z = log2(float(z)) / 31.0f - 1.0f; p.z = max(0.0f, log2(float(z))) / 31.0f - 1.0f;
} else { } else {
p.z = float(z) * exp_min31 - 1.0f; p.z = float(z) * exp_min31 - 1.0f;
} }

View File

@ -567,13 +567,6 @@ static const char* tfx_vgs_glsl =
" else\n" " else\n"
" z = i_z;\n" " z = i_z;\n"
"\n" "\n"
" if(VS_LOGZ == 1) {\n"
" // FIXME some games (FFX12 intro) uses MAX_INT as depth parameter. So I replace the +1 with an OR\n"
" // Initially a +1 was done to avoid log2(0) (If I'm correct)\n"
" // The or mask won't create any overflow\n"
" z |= 1u;\n"
" }\n"
"\n"
" // pos -= 0.05 (1/320 pixel) helps avoiding rounding problems (integral part of pos is usually 5 digits, 0.05 is about as low as we can go)\n" " // pos -= 0.05 (1/320 pixel) helps avoiding rounding problems (integral part of pos is usually 5 digits, 0.05 is about as low as we can go)\n"
" // example: ceil(afterseveralvertextransformations(y = 133)) => 134 => line 133 stays empty\n" " // example: ceil(afterseveralvertextransformations(y = 133)) => 134 => line 133 stays empty\n"
" // input granularity is 1/16 pixel, anything smaller than that won't step drawing up/left by one pixel\n" " // input granularity is 1/16 pixel, anything smaller than that won't step drawing up/left by one pixel\n"
@ -585,13 +578,13 @@ static const char* tfx_vgs_glsl =
" p.w = 1.0f;\n" " p.w = 1.0f;\n"
"#ifdef ZERO_TO_ONE_DEPTH\n" "#ifdef ZERO_TO_ONE_DEPTH\n"
" if(VS_LOGZ == 1) {\n" " if(VS_LOGZ == 1) {\n"
" p.z = log2(float(z)) / 32.0f;\n" " p.z = max(0.0f, log2(float(z))) / 32.0f;\n"
" } else {\n" " } else {\n"
" p.z = float(z) * exp_min32;\n" " p.z = float(z) * exp_min32;\n"
" }\n" " }\n"
"#else\n" "#else\n"
" if(VS_LOGZ == 1) {\n" " if(VS_LOGZ == 1) {\n"
" p.z = log2(float(z)) / 31.0f - 1.0f;\n" " p.z = max(0.0f, log2(float(z))) / 31.0f - 1.0f;\n"
" } else {\n" " } else {\n"
" p.z = float(z) * exp_min31 - 1.0f;\n" " p.z = float(z) * exp_min31 - 1.0f;\n"
" }\n" " }\n"