GLES: Fixed palette mode and interpolation

This commit is contained in:
Emile Belanger 2021-12-10 18:22:55 +00:00 committed by Christoph Oelckers
parent 5a8c57040f
commit 9e1e824f5e
4 changed files with 26 additions and 23 deletions

View file

@ -158,6 +158,7 @@ bool FGLRenderState::ApplyShader()
flavour.blendFlags = (int)(mStreamData.uTextureAddColor.a + 0.01);
flavour.paletteInterpolate = !!(flavour.blendFlags & 0x4000);
flavour.twoDFog = false;
flavour.fogEnabled = false;

View file

@ -686,7 +686,7 @@ bool FShader::Bind(ShaderFlavourData& flavour)
variantConfig.AppendFormat("#define MAXIMUM_LIGHT_VECTORS %d\n", gles.numlightvectors);
variantConfig.AppendFormat("#define DEF_TEXTURE_MODE %d\n", flavour.textureMode);
variantConfig.AppendFormat("#define DEF_TEXTURE_FLAGS %d\n", flavour.texFlags);
variantConfig.AppendFormat("#define DEF_BLEND_FLAGS %d\n", flavour.blendFlags);
variantConfig.AppendFormat("#define DEF_BLEND_FLAGS %d\n", flavour.blendFlags & 0x7);
variantConfig.AppendFormat("#define DEF_FOG_2D %d\n", flavour.twoDFog);
variantConfig.AppendFormat("#define DEF_FOG_ENABLED %d\n", flavour.fogEnabled);
variantConfig.AppendFormat("#define DEF_FOG_RADIAL %d\n", flavour.fogEquationRadial);
@ -714,6 +714,7 @@ bool FShader::Bind(ShaderFlavourData& flavour)
#endif
variantConfig.AppendFormat("#define DEF_HAS_SPOTLIGHT %d\n", flavour.hasSpotLight);
variantConfig.AppendFormat("#define DEF_PALETTE_INTERPOLATE %d\n", flavour.paletteInterpolate);
//Printf("Shader: %s, %08x %s", mFragProg2.GetChars(), tag, variantConfig.GetChars());

View file

@ -277,6 +277,7 @@ public:
#endif
bool hasSpotLight;
bool paletteInterpolate;
};
class FShader
@ -419,8 +420,8 @@ public:
#ifdef NPOT_EMULATION
tag |= (flavour.npotEmulation & 1) << 22;
#endif
tag |= (flavour.hasSpotLight & 1) << 23;
tag |= (flavour.paletteInterpolate & 1) << 24;
return tag;
}

View file

@ -1,5 +1,16 @@
const int RF_ShadeInterpolate = 64;
const float pixleHalf = (1.0 / 256.0) / 2.0; // Half way through a pixel on 256 sized image
const float pixleIndexScale = 255.0 / 256.0;
vec4 getColor(float palindex, float shadeindex)
{
float colorIndexF = texture2D(texture3, vec2(palindex, shadeindex)).a;
vec4 palettedColor = texture2D(texture2, vec2((colorIndexF * pixleIndexScale) + pixleHalf, 0.5));
return palettedColor;
}
vec4 ProcessTexel()
{
float fullbright = 0.0;
@ -24,43 +35,32 @@ vec4 ProcessTexel()
newCoord = vec2(coordX, coordY);
color = texture2D(tex, newCoord);
#if 0 // Disable Interpolation for now
#if ((DEF_BLEND_FLAGS & 16384) != 0)
#if (DEF_PALETTE_INTERPOLATE == 1)
float visibility = max(uGlobVis * uLightFactor * z - 0.5, 0.0);
#else
float visibility = max(uGlobVis * uLightFactor * z, 0.0);
#endif
#else
float visibility = max(uGlobVis * uLightFactor * z, 0.0);
#endif
float numShades = float(uPalLightLevels);
float shade = (1.0 - uLightLevel) * (numShades);
shade = clamp((shade + visibility), 0.0, numShades - 1.0);
float comp = (1.0 / 256.0) / 2.0; // Half way through a pixel on 256 sized image
float palindex = (color.a * pixleIndexScale) + pixleHalf;
float shadeindex = (shade / (numShades)) + pixleHalf;
float palindex = color.a + comp;
float shadeindex = (shade / (numShades)) + comp;
vec4 palettedColor = getColor(palindex, shadeindex);
float colorIndexF = texture2D(texture3, vec2(palindex, shadeindex)).a;
vec4 palettedColor = texture2D(texture2, vec2(colorIndexF + comp, 0.5));
#if 0 // Disable Interpolation for now
#if ((DEF_BLEND_FLAGS & 16384) != 0)
#if (DEF_PALETTE_INTERPOLATE == 1)
// Get the next shaded palette index for interpolation
colorIndexF = texelFetch(texture3, ivec2(palindex, shadeindex+1), 0).a;
colorIndex = int(colorIndexF * 255.0 + 0.1); // The 0.1 is for roundoff error compensation.
vec4 palettedColorNext = texelFetch(texture2, ivec2(colorIndex, 0), 0);
shadeindex = ((shade + 1.0) / (numShades));
shadeindex = clamp(shadeindex, 0.0, 1.0);
vec4 palettedColorNext = getColor(palindex, shadeindex);
float shadeFrac = mod(shade, 1.0);
palettedColor.rgb = mix(palettedColor.rgb, palettedColorNext.rgb, shadeFrac);
#endif
#endif