Commit 9976fb4b authored by Richard Gobeille's avatar Richard Gobeille
Browse files

engine: small polymost shader optimizations

parent 7d6a28a6
......@@ -141,7 +141,7 @@ bool glsurface_initialize(vec2_t bufferResolution)
void main()\n\
{\n\
vec4 color = texture2D(s_texture, v_texCoord.xy);\n\
color.r = c_paletteOffset + c_paletteScale*color.r;\n\
color.r = c_paletteScale * color.r + c_paletteOffset;\n\
color.rgb = texture2D(s_palette, color.rg).rgb;\n\
\n\
// DEBUG \n\
......
......@@ -197,7 +197,7 @@ static vec2f_t polymost1Clamp = { 0.f, 0.f };
static GLint polymost1ShadeLoc = -1;
static float polymost1Shade = 0.f;
static GLint polymost1NumShadesLoc = -1;
static float polymost1NumShades = 64.f;
static vec2f_t polymost1NumShades = { 64.f, 1.f / 64.f };
static GLint polymost1VisFactorLoc = -1;
static float polymost1VisFactor = 128.f;
static GLint polymost1FogEnabledLoc = -1;
......@@ -211,11 +211,7 @@ static float polymost1UseDetailMapping = 0.f;
static GLint polymost1UseGlowMappingLoc = -1;
static float polymost1UseGlowMapping = 0.f;
static GLint polymost1NPOTEmulationLoc = -1;
static float polymost1NPOTEmulation = 0.f;
static GLint polymost1NPOTEmulationFactorLoc = -1;
static float polymost1NPOTEmulationFactor = 1.f;
static GLint polymost1NPOTEmulationXOffsetLoc = -1;
static float polymost1NPOTEmulationXOffset = 0.f;
static vec4f_t polymost1NPOTEmulation = { 0.f, 1.f, 0.f, 1.f };
static GLint polymost1RotMatrixLoc = -1;
static float polymost1RotMatrix[16] = { 1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
......@@ -642,8 +638,6 @@ static void polymost_setCurrentShaderProgram(uint32_t programID)
polymost1UseDetailMappingLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_useDetailMapping");
polymost1UseGlowMappingLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_useGlowMapping");
polymost1NPOTEmulationLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulation");
polymost1NPOTEmulationFactorLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulationFactor");
polymost1NPOTEmulationXOffsetLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulationXOffset");
polymost1RotMatrixLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_rotMatrix");
polymost1ShadeInterpolateLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_shadeInterpolate");
polymost1ColorCorrectionLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_colorCorrection");
......@@ -655,16 +649,14 @@ static void polymost_setCurrentShaderProgram(uint32_t programID)
glUniform2f(polymost1PalswapSizeLoc, polymost1PalswapInnerSize.x, polymost1PalswapInnerSize.y);
glUniform2f(polymost1ClampLoc, polymost1Clamp.x, polymost1Clamp.y);
glUniform1f(polymost1ShadeLoc, polymost1Shade);
glUniform1f(polymost1NumShadesLoc, polymost1NumShades);
glUniform2f(polymost1NumShadesLoc, polymost1NumShades.x, polymost1NumShades.y);
glUniform1f(polymost1VisFactorLoc, polymost1VisFactor);
glUniform1f(polymost1FogEnabledLoc, polymost1FogEnabled);
glUniform1f(polymost1UseColorOnlyLoc, polymost1UseColorOnly);
glUniform1f(polymost1UsePaletteLoc, polymost1UsePalette);
glUniform1f(polymost1UseDetailMappingLoc, polymost1UseDetailMapping);
glUniform1f(polymost1UseGlowMappingLoc, polymost1UseGlowMapping);
glUniform1f(polymost1NPOTEmulationLoc, polymost1NPOTEmulation);
glUniform1f(polymost1NPOTEmulationFactorLoc, polymost1NPOTEmulationFactor);
glUniform1f(polymost1NPOTEmulationXOffsetLoc, polymost1NPOTEmulationXOffset);
glUniform4f(polymost1NPOTEmulationLoc, polymost1NPOTEmulation.x, polymost1NPOTEmulation.y, polymost1NPOTEmulation.z, polymost1NPOTEmulation.w);
glUniformMatrix4fv(polymost1RotMatrixLoc, 1, false, polymost1RotMatrix);
glUniform1f(polymost1ShadeInterpolateLoc, polymost1ShadeInterpolate);
glUniform4f(polymost1ColorCorrectionLoc, g_glColorCorrection.x, g_glColorCorrection.y, g_glColorCorrection.z, g_glColorCorrection.w);
......@@ -732,14 +724,12 @@ char polymost_getClamp()
void polymost_setClamp(char clamp)
{
char clampx = clamp&1;
char clampy = clamp>>1;
if (gl.currentShaderProgramID != polymost1CurrentShaderProgramID ||
(clampx == polymost1Clamp.x && clampy == polymost1Clamp.y))
vec2f_t clampy = { float(clamp & 1), float(clamp >> 1) };
if (gl.currentShaderProgramID != polymost1CurrentShaderProgramID || clampy == polymost1Clamp)
return;
polymost1Clamp.x = clampx;
polymost1Clamp.y = clampy;
polymost1Clamp = clampy;
glUniform2f(polymost1ClampLoc, polymost1Clamp.x, polymost1Clamp.y);
}
......@@ -764,8 +754,8 @@ static void polymost_setShade(int32_t shade)
if (numshades != lastNumShades)
{
lastNumShades = numshades;
polymost1NumShades = numshades;
glUniform1f(polymost1NumShadesLoc, polymost1NumShades);
polymost1NumShades = { (float)numshades, 1.f / numshades };
glUniform2f(polymost1NumShadesLoc, polymost1NumShades.x, polymost1NumShades.y);
}
}
......@@ -838,24 +828,20 @@ void polymost_useGlowMapping(char useGlowMapping)
void polymost_npotEmulation(char npotEmulation, float factor, float xOffset)
{
if (gl.currentShaderProgramID != polymost1CurrentShaderProgramID || npotEmulation == polymost1NPOTEmulation)
if (gl.currentShaderProgramID != polymost1CurrentShaderProgramID || npotEmulation == polymost1NPOTEmulation.z)
return;
polymost1NPOTEmulation = npotEmulation;
glUniform1f(polymost1NPOTEmulationLoc, polymost1NPOTEmulation);
polymost1NPOTEmulationFactor = factor;
glUniform1f(polymost1NPOTEmulationFactorLoc, polymost1NPOTEmulationFactor);
polymost1NPOTEmulationXOffset = xOffset;
glUniform1f(polymost1NPOTEmulationXOffsetLoc, polymost1NPOTEmulationXOffset);
polymost1NPOTEmulation = { xOffset, factor, (float)npotEmulation, 1.f/factor };
glUniform4f(polymost1NPOTEmulationLoc, polymost1NPOTEmulation.x, polymost1NPOTEmulation.y, polymost1NPOTEmulation.z, polymost1NPOTEmulation.w);
}
void polymost_shadeInterpolate(int32_t shadeInterpolate)
{
if (gl.currentShaderProgramID == polymost1CurrentShaderProgramID)
{
polymost1ShadeInterpolate = shadeInterpolate;
glUniform1f(polymost1ShadeInterpolateLoc, polymost1ShadeInterpolate);
}
if (gl.currentShaderProgramID != polymost1CurrentShaderProgramID || shadeInterpolate == polymost1ShadeInterpolate)
return;
polymost1ShadeInterpolate = shadeInterpolate;
glUniform1f(polymost1ShadeInterpolateLoc, polymost1ShadeInterpolate);
}
static void polymost_bindPth(pthtyp const * const pPth)
......
......@@ -25,15 +25,13 @@ uniform vec2 u_palswapSize;
uniform vec2 u_clamp;
uniform float u_shade;
uniform float u_numShades;
uniform vec2 u_numShades;
uniform float u_visFactor;
uniform float u_fogEnabled;
uniform float u_useColorOnly;
uniform float u_usePalette;
uniform float u_npotEmulation;
uniform float u_npotEmulationFactor;
uniform float u_npotEmulationXOffset;
uniform vec4 u_npotEmulation;
uniform float u_shadeInterpolate;
#ifdef POLYMOST1_EXTENDED
......@@ -59,12 +57,10 @@ const vec4 c_vec4_luma_709 = vec4(0.2126, 0.7152, 0.0722, 0.0);
void main()
{
float coordY = mix(gl_TexCoord[0].y,gl_TexCoord[0].x,u_usePalette);
float coordX = mix(gl_TexCoord[0].x,gl_TexCoord[0].y,u_usePalette);
float period = floor(coordY/u_npotEmulationFactor);
coordX += u_npotEmulationXOffset*floor(mod(coordY,u_npotEmulationFactor));
coordY = period+mod(coordY,u_npotEmulationFactor);
vec2 newCoord = mix(gl_TexCoord[0].xy,mix(vec2(coordX,coordY),vec2(coordY,coordX),u_usePalette),u_npotEmulation);
vec2 coord = mix(gl_TexCoord[0].xy,gl_TexCoord[0].yx,u_usePalette);
float modCoordYnpotEmulationFactor = mod(coord.y,u_npotEmulation.y);
coord.xy = vec2(floor(modCoordYnpotEmulationFactor)*u_npotEmulation.x+coord.x, floor(coord.y*u_npotEmulation.y)+modCoordYnpotEmulationFactor);
vec2 newCoord = mix(gl_TexCoord[0].xy,mix(coord.xy,coord.yx,u_usePalette),u_npotEmulation.z);
#ifdef GL_ARB_shader_texture_lod
vec2 texCoord = mix(fract(newCoord.xy), clamp(newCoord.xy, c_zero, c_one), u_clamp);
texCoord = clamp(u_texturePosSize.zw*texCoord, u_halfTexelSize, u_texturePosSize.zw-u_halfTexelSize);
......@@ -77,14 +73,12 @@ void main()
vec4 color = texture2D(s_texture, u_texturePosSize.xy+texCoord);
#endif
float shade = clamp((u_shade+max(u_visFactor*v_distance-0.5*u_shadeInterpolate,c_zero)), c_zero, u_numShades-c_one);
float shade = clamp((u_shade+clamp(u_visFactor*v_distance-0.5*u_shadeInterpolate,c_zero,u_numShades.x)), c_zero, u_numShades.x-c_one);
float shadeFrac = mod(shade, c_one);
float colorIndex = texture2D(s_palswap, u_palswapPos+u_palswapSize*vec2(color.r, floor(shade)/u_numShades)).r;
colorIndex = c_basepalOffset + c_basepalScale*colorIndex;
float colorIndex = texture2D(s_palswap, vec2(color.r, floor(shade)*u_numShades.y)*u_palswapSize+u_palswapPos).r * c_basepalScale + c_basepalOffset;
float colorIndexNext = texture2D(s_palswap, u_palswapSize*vec2(color.r, (floor(shade)+c_one)*u_numShades.y)+u_palswapPos).r * c_basepalScale + c_basepalOffset;
vec4 palettedColor = texture2D(s_palette, vec2(colorIndex, c_zero));
colorIndex = texture2D(s_palswap, u_palswapPos+u_palswapSize*vec2(color.r, (floor(shade)+c_one)/u_numShades)).r;
colorIndex = c_basepalOffset + c_basepalScale*colorIndex;
vec4 palettedColorNext = texture2D(s_palette, vec2(colorIndex, c_zero));
vec4 palettedColorNext = texture2D(s_palette, vec2(colorIndexNext, c_zero));
palettedColor.rgb = mix(palettedColor.rgb, palettedColorNext.rgb, shadeFrac*u_shadeInterpolate);
float fullbright = mix(u_usePalette*palettedColor.a, c_zero, u_useColorOnly);
palettedColor.a = c_one-floor(color.r);
......@@ -105,14 +99,14 @@ void main()
color.rgb = mix(v_color.rgb*color.rgb, color.rgb, fullbright);
fullbright = max(c_one-u_fogEnabled, fullbright);
fullbright = clamp(-(u_fogEnabled-c_one), fullbright, c_one);
float fogFactor = clamp((gl_Fog.end-gl_FogFragCoord)*gl_Fog.scale, fullbright, c_one);
//float fogFactor = clamp(gl_FogFragCoord, fullbright, c_one);
color.rgb = mix(gl_Fog.color.rgb, color.rgb, fogFactor);
#ifdef POLYMOST1_EXTENDED
vec4 glowColor = texture2D(s_glow, gl_TexCoord[4].xy);
color.rgb = mix(color.rgb, glowColor.rgb, u_useGlowMapping*glowColor.a*(c_one-u_useColorOnly));
color.rgb = mix(color.rgb, glowColor.rgb, u_useGlowMapping * glowColor.a * -(u_useColorOnly-c_one));
#endif
color.a *= v_color.a;
......
#version 110
#version 120
varying vec4 v_color;
varying float v_distance;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment