2016-06-15 18:53:26 +02:00
|
|
|
#version 150
|
2016-06-09 00:13:49 +02:00
|
|
|
|
2016-07-22 23:49:55 +02:00
|
|
|
uniform vec4 uPalette[256];
|
2016-07-23 18:33:53 +02:00
|
|
|
uniform usampler2DArray uTexture;
|
2016-07-23 00:56:41 +02:00
|
|
|
|
|
|
|
flat in ivec4 fClip;
|
|
|
|
flat in int fFlags;
|
|
|
|
in vec4 fColour;
|
2016-07-23 20:43:03 +02:00
|
|
|
flat in int fTexColourAtlas;
|
2016-07-23 16:55:47 +02:00
|
|
|
in vec2 fTexColourCoords;
|
2016-07-23 20:43:03 +02:00
|
|
|
flat in int fTexMaskAtlas;
|
2016-07-23 16:55:47 +02:00
|
|
|
in vec2 fTexMaskCoords;
|
2016-09-18 16:40:27 +02:00
|
|
|
flat in int fTexPaletteAtlas;
|
|
|
|
flat in vec4 fTexPaletteBounds;
|
2016-07-23 02:30:13 +02:00
|
|
|
flat in int fMask;
|
2016-06-09 00:13:49 +02:00
|
|
|
|
|
|
|
in vec2 fPosition;
|
|
|
|
in vec2 fTextureCoordinate;
|
|
|
|
|
2016-06-15 18:53:26 +02:00
|
|
|
out vec4 oColour;
|
2016-06-09 00:13:49 +02:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2016-07-23 00:56:41 +02:00
|
|
|
if (fPosition.x < fClip.x || fPosition.x > fClip.z ||
|
|
|
|
fPosition.y < fClip.y || fPosition.y > fClip.w)
|
2016-06-09 00:13:49 +02:00
|
|
|
{
|
|
|
|
discard;
|
|
|
|
}
|
|
|
|
|
2016-09-18 16:40:27 +02:00
|
|
|
vec4 texel;
|
|
|
|
|
|
|
|
// If remap palette used
|
|
|
|
if ((fFlags & (1 << 1)) != 0)
|
|
|
|
{
|
|
|
|
// z is the size of each x pixel in the atlas
|
|
|
|
float x = fTexPaletteBounds.x + texture(uTexture, vec3(fTexColourCoords, float(fTexColourAtlas))).r * fTexPaletteBounds.z;
|
|
|
|
texel = uPalette[texture(uTexture, vec3(x, fTexPaletteBounds.y, float(fTexPaletteAtlas))).r];
|
|
|
|
} // If transparent or special transparent
|
|
|
|
else if ((fFlags & ((1 << 2) | (1 << 3))) != 0)
|
|
|
|
{
|
|
|
|
float line = texture(uTexture,vec3(fTexColourCoords, float(fTexColourAtlas))).r;
|
|
|
|
if (line == 0.0)
|
|
|
|
{
|
|
|
|
discard;
|
|
|
|
}
|
|
|
|
float alpha = 0.5;
|
|
|
|
if ((fFlags & (1 << 2)) != 0)
|
|
|
|
{
|
|
|
|
alpha = 0.5 + (line - 1.0) / 10.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// z is the size of each x pixel in the atlas
|
|
|
|
float x = fTexPaletteBounds.x + fTexPaletteBounds.z * 50.0;
|
|
|
|
oColour = vec4(uPalette[texture(uTexture, vec3(x, fTexPaletteBounds.y, float(fTexPaletteAtlas))).r].rgb, alpha);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
texel = uPalette[texture(uTexture, vec3(fTexColourCoords, float(fTexColourAtlas))).r];
|
|
|
|
}
|
2016-07-23 20:43:03 +02:00
|
|
|
vec4 mask = uPalette[texture(uTexture, vec3(fTexMaskCoords, float(fTexMaskAtlas))).r];
|
2016-07-23 02:30:13 +02:00
|
|
|
|
2016-07-23 16:55:47 +02:00
|
|
|
if (fMask != 0)
|
2016-06-11 19:28:03 +02:00
|
|
|
{
|
2016-07-23 02:30:13 +02:00
|
|
|
oColour = texel * mask;
|
2016-06-11 19:28:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-23 02:30:13 +02:00
|
|
|
if ((fFlags & 1) != 0)
|
|
|
|
{
|
|
|
|
oColour = vec4(fColour.rgb, fColour.a * texel.a);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
oColour = texel;
|
|
|
|
}
|
2016-06-11 19:28:03 +02:00
|
|
|
}
|
2016-06-09 00:13:49 +02:00
|
|
|
}
|