mirror of
https://github.com/liuk7071/ChonkyStation.git
synced 2025-04-02 10:52:38 -04:00
50 lines
No EOL
1.3 KiB
GLSL
50 lines
No EOL
1.3 KiB
GLSL
|
|
#version 430 core
|
|
out vec4 FragColor;
|
|
|
|
in vec3 ourColor;
|
|
in vec2 TexCoord;
|
|
flat in vec2 texpageCoords;
|
|
flat in vec2 clut;
|
|
layout(std430, binding = 10) buffer clutData
|
|
{
|
|
int Clut[128];
|
|
};
|
|
uniform sampler2D vram;
|
|
uniform sampler2D vram8;
|
|
uniform sampler2D vram4;
|
|
uniform int colourDepth;
|
|
|
|
int floatToU5(float f) {
|
|
return int(floor(f * 31.0 + 0.5));
|
|
}
|
|
|
|
int sample16(ivec2 coords) {
|
|
vec4 colour = texelFetch(vram, coords, 0);
|
|
int r = floatToU5(colour.r);
|
|
int g = floatToU5(colour.g);
|
|
int b = floatToU5(colour.b);
|
|
int msb = int(ceil(colour.a)) << 15;
|
|
return r | (g << 5) | (b << 10) | msb;
|
|
}
|
|
|
|
vec4 fetchTexel4Bit(ivec2 coords) {
|
|
int texel = sample16(ivec2(coords.x / 4, coords.y) + ivec2(texpageCoords));
|
|
int idx = (texel >> ((coords.x % 4) * 4)) & 0xf;
|
|
return texelFetch(vram, ivec2(clut.x + idx, clut.y), 0);
|
|
}
|
|
|
|
void main()
|
|
{
|
|
vec4 colour;
|
|
if(colourDepth == 0) {
|
|
colour = fetchTexel4Bit(ivec2(TexCoord));
|
|
} else if (colourDepth == 2) {
|
|
vec2 TexCoords = vec2(float(TexCoord.x + texpageCoords.x) / 1024.f - 1, -(1 - float(TexCoord.y + texpageCoords.y) / 512.f));
|
|
colour = texture(vram, TexCoords);
|
|
} else colour = vec4(1.f, 0.f, 0.f, 1.f);
|
|
//if(colour.rgb == vec3(0.f, 0.f, 0.f)) discard;
|
|
colour.a = 1.f;
|
|
FragColor = colour;
|
|
}
|
|
|