glsl: fix rounding error for shadow computation

Better shadow on Castlevania/Nemo (others :) )
This commit is contained in:
Gregory Hainaut 2015-06-30 22:12:00 +02:00
parent d46e41533d
commit a9f49ab9ab
2 changed files with 10 additions and 4 deletions

View File

@ -661,14 +661,17 @@ void ps_blend(inout vec4 c, in float As)
c.rgb = clamp(c.rgb, vec3(0.0f), vec3(1.0f));
#endif
// Warning: normally blending equation is mult(A, B) = A * B >> 7. GPU have the full accuracy
// GS: Color = 1, Alpha = 255 => output 1
// GPU: Color = 1/255, Alpha = 255/255 * 255/128 => output 1.9921875
#if PS_DFMT == FMT_16
// In 16 bits format, only 5 bits of colors are used. It impacts shadows computation of Castlevania
// Basically we want to do 'c.rgb &= 0xF8' in denormalized mode
c.rgb = vec3(uvec3((c.rgb * 255.0f) + 256.5f) & uvec3(0xF8)) / 255.0f;
c.rgb = vec3(uvec3(c.rgb * 255.0f) & uvec3(0xF8)) / 255.0f;
#elif PS_COLCLIP == 3
// Basically we want to do 'c.rgb &= 0xFF' in denormalized mode
c.rgb = vec3(uvec3((c.rgb * 255.0f) + 256.5f) & uvec3(0xFF)) / 255.0f;
c.rgb = vec3(uvec3(c.rgb * 255.0f) & uvec3(0xFF)) / 255.0f;
#endif
// Don't compile => unable to find compatible overloaded function "mod(vec3)"

View File

@ -1540,14 +1540,17 @@ static const char* tfx_fs_all_glsl =
" c.rgb = clamp(c.rgb, vec3(0.0f), vec3(1.0f));\n"
"#endif\n"
"\n"
" // Warning: normally blending equation is mult(A, B) = A * B >> 7. GPU have the full accuracy\n"
" // GS: Color = 1, Alpha = 255 => output 1\n"
" // GPU: Color = 1/255, Alpha = 255/255 * 255/128 => output 1.9921875\n"
"#if PS_DFMT == FMT_16\n"
" // In 16 bits format, only 5 bits of colors are used. It impacts shadows computation of Castlevania\n"
"\n"
" // Basically we want to do 'c.rgb &= 0xF8' in denormalized mode\n"
" c.rgb = vec3(uvec3((c.rgb * 255.0f) + 256.5f) & uvec3(0xF8)) / 255.0f;\n"
" c.rgb = vec3(uvec3(c.rgb * 255.0f) & uvec3(0xF8)) / 255.0f;\n"
"#elif PS_COLCLIP == 3\n"
" // Basically we want to do 'c.rgb &= 0xFF' in denormalized mode\n"
" c.rgb = vec3(uvec3((c.rgb * 255.0f) + 256.5f) & uvec3(0xFF)) / 255.0f;\n"
" c.rgb = vec3(uvec3(c.rgb * 255.0f) & uvec3(0xFF)) / 255.0f;\n"
"#endif\n"
"\n"
" // Don't compile => unable to find compatible overloaded function \"mod(vec3)\"\n"