mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-30 01:25:51 +00:00
GPU: Preserve low bits in upscaled texture coordinates
This commit is contained in:
parent
12ce777e30
commit
49be3efb35
|
@ -220,10 +220,10 @@ void main()
|
||||||
v_tex0 = a_tex0;
|
v_tex0 = a_tex0;
|
||||||
|
|
||||||
// base_x,base_y,palette_x,palette_y
|
// base_x,base_y,palette_x,palette_y
|
||||||
v_texpage.x = (a_texpage & 15) * 64;
|
v_texpage.x = (a_texpage & 15) * 64 * RESOLUTION_SCALE;
|
||||||
v_texpage.y = ((a_texpage >> 4) & 1) * 256;
|
v_texpage.y = ((a_texpage >> 4) & 1) * 256 * RESOLUTION_SCALE;
|
||||||
v_texpage.z = ((a_texpage >> 16) & 63) * 16;
|
v_texpage.z = ((a_texpage >> 16) & 63) * 16 * RESOLUTION_SCALE;
|
||||||
v_texpage.w = ((a_texpage >> 22) & 511);
|
v_texpage.w = ((a_texpage >> 22) & 511) * RESOLUTION_SCALE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
@ -260,17 +260,27 @@ uniform vec2 u_transparent_alpha;
|
||||||
out vec4 o_col0;
|
out vec4 o_col0;
|
||||||
|
|
||||||
#if TEXTURED
|
#if TEXTURED
|
||||||
ivec2 ApplyTextureWindow(ivec2 coords)
|
ivec2 ApplyNativeTextureWindow(ivec2 coords)
|
||||||
{
|
{
|
||||||
uint x = (uint(coords.x) & ~(u_texture_window.x * 8u)) | ((u_texture_window.z & u_texture_window.x) * 8u);
|
uint x = (uint(coords.x) & ~(u_texture_window.x * 8u)) | ((u_texture_window.z & u_texture_window.x) * 8u);
|
||||||
uint y = (uint(coords.y) & ~(u_texture_window.y * 8u)) | ((u_texture_window.w & u_texture_window.y) * 8u);
|
uint y = (uint(coords.y) & ~(u_texture_window.y * 8u)) | ((u_texture_window.w & u_texture_window.y) * 8u);
|
||||||
return ivec2(int(x), int(y));
|
return ivec2(int(x), int(y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ivec2 ApplyTextureWindow(ivec2 coords)
|
||||||
|
{
|
||||||
|
if (RESOLUTION_SCALE == 1)
|
||||||
|
return ApplyNativeTextureWindow(coords);
|
||||||
|
|
||||||
|
ivec2 downscaled_coords = coords / ivec2(RESOLUTION_SCALE);
|
||||||
|
ivec2 coords_offset = coords % ivec2(RESOLUTION_SCALE);
|
||||||
|
return (ApplyNativeTextureWindow(downscaled_coords) * ivec2(RESOLUTION_SCALE)) + coords_offset;
|
||||||
|
}
|
||||||
|
|
||||||
vec4 SampleFromVRAM(vec2 coord)
|
vec4 SampleFromVRAM(vec2 coord)
|
||||||
{
|
{
|
||||||
// from 0..1 to 0..255
|
// from 0..1 to 0..255
|
||||||
ivec2 icoord = ivec2(coord * vec2(255.0));
|
ivec2 icoord = ivec2(coord * vec2(255 * RESOLUTION_SCALE));
|
||||||
icoord = ApplyTextureWindow(icoord);
|
icoord = ApplyTextureWindow(icoord);
|
||||||
|
|
||||||
// adjust for tightly packed palette formats
|
// adjust for tightly packed palette formats
|
||||||
|
@ -282,8 +292,7 @@ vec4 SampleFromVRAM(vec2 coord)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// fixup coords
|
// fixup coords
|
||||||
ivec2 vicoord = ivec2((v_texpage.x + index_coord.x) * RESOLUTION_SCALE,
|
ivec2 vicoord = ivec2(v_texpage.x + index_coord.x, fixYCoord(v_texpage.y + index_coord.y));
|
||||||
fixYCoord((v_texpage.y + index_coord.y) * RESOLUTION_SCALE));
|
|
||||||
|
|
||||||
// load colour/palette
|
// load colour/palette
|
||||||
vec4 color = texelFetch(samp0, vicoord, 0);
|
vec4 color = texelFetch(samp0, vicoord, 0);
|
||||||
|
@ -291,16 +300,15 @@ vec4 SampleFromVRAM(vec2 coord)
|
||||||
// apply palette
|
// apply palette
|
||||||
#if PALETTE
|
#if PALETTE
|
||||||
#if PALETTE_4_BIT
|
#if PALETTE_4_BIT
|
||||||
int subpixel = int(icoord.x) & 3;
|
int subpixel = int(icoord.x / RESOLUTION_SCALE) & 3;
|
||||||
uint vram_value = RGBA8ToRGBA5551(color);
|
uint vram_value = RGBA8ToRGBA5551(color);
|
||||||
int palette_index = int((vram_value >> (subpixel * 4)) & 0x0Fu);
|
int palette_index = int((vram_value >> (subpixel * 4)) & 0x0Fu);
|
||||||
#elif PALETTE_8_BIT
|
#elif PALETTE_8_BIT
|
||||||
int subpixel = int(icoord.x) & 1;
|
int subpixel = int(icoord.x / RESOLUTION_SCALE) & 1;
|
||||||
uint vram_value = RGBA8ToRGBA5551(color);
|
uint vram_value = RGBA8ToRGBA5551(color);
|
||||||
int palette_index = int((vram_value >> (subpixel * 8)) & 0xFFu);
|
int palette_index = int((vram_value >> (subpixel * 8)) & 0xFFu);
|
||||||
#endif
|
#endif
|
||||||
ivec2 palette_icoord = ivec2((v_texpage.z + palette_index) * RESOLUTION_SCALE,
|
ivec2 palette_icoord = ivec2(v_texpage.z + (palette_index * RESOLUTION_SCALE), fixYCoord(v_texpage.w));
|
||||||
fixYCoord(v_texpage.w * RESOLUTION_SCALE));
|
|
||||||
color = texelFetch(samp0, palette_icoord, 0);
|
color = texelFetch(samp0, palette_icoord, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue