Pre-round the colortest/alphatest reference val.

This commit is contained in:
Unknown W. Brackets 2013-05-07 07:52:49 -07:00
parent 6cdf5ea0c5
commit f2b4c4a0bc
2 changed files with 19 additions and 14 deletions

View file

@ -159,7 +159,7 @@ void GenerateFragmentShader(char *buffer) {
WRITE(p, "uniform sampler2D tex;\n");
if (enableAlphaTest || enableColorTest) {
WRITE(p, "uniform vec4 u_alphacolorref;\n");
WRITE(p, "uniform ivec4 u_alphacolorref;\n");
WRITE(p, "uniform vec4 u_colormask;\n");
}
if (gstate.isTextureMapEnabled())
@ -184,8 +184,8 @@ void GenerateFragmentShader(char *buffer) {
WRITE(p, "varying vec2 v_texcoord;\n");
}
WRITE(p, "float round255f(in float x) { return floor(x * 255.0 + 0.5); }\n");
WRITE(p, "vec3 round255v(in vec3 x) { return floor(x * 255.0 + 0.5); }\n");
WRITE(p, "int round255f(in float x) { return int(x * 255.0 + 0.5); }\n");
WRITE(p, "ivec3 round255v(in vec3 x) { return ivec3(x * 255.0 + 0.5); }\n");
WRITE(p, "void main() {\n");
@ -255,11 +255,7 @@ void GenerateFragmentShader(char *buffer) {
int alphaTestFunc = gstate.alphatest & 7;
const char *alphaTestFuncs[] = { "#", "#", " != ", " == ", " >= ", " > ", " <= ", " < " }; // never/always don't make sense
if (alphaTestFuncs[alphaTestFunc][0] != '#') {
// If it's an equality check (!=, ==, <=, >=), rounding is more likely to be important.
if (alphaTestFuncs[alphaTestFunc][2] == '=')
WRITE(p, " if (round255f(v.a) %s round255f(u_alphacolorref.a)) discard;\n", alphaTestFuncs[alphaTestFunc]);
else
WRITE(p, " if (v.a %s u_alphacolorref.a) discard;\n", alphaTestFuncs[alphaTestFunc]);
WRITE(p, " if (round255f(v.a) %s u_alphacolorref.a) discard;\n", alphaTestFuncs[alphaTestFunc]);
}
}
@ -271,11 +267,9 @@ void GenerateFragmentShader(char *buffer) {
int colorTestFunc = gstate.colortest & 3;
const char *colorTestFuncs[] = { "#", "#", " != ", " == " }; // never/always don't make sense
int colorTestMask = gstate.colormask;
if (colorTestFuncs[colorTestFunc][0] != '#')
if (colorTestFuncs[colorTestFunc][2] == '=')
WRITE(p, "if (round255v(v.rgb) %s round255v(u_alphacolorref.rgb)) discard;\n", colorTestFuncs[colorTestFunc]);
else
WRITE(p, "if (v.rgb %s u_alphacolorref.rgb) discard;\n", colorTestFuncs[colorTestFunc]);
if (colorTestFuncs[colorTestFunc][0] != '#') {
WRITE(p, "if (round255v(v.rgb) %s u_alphacolorref.rgb) discard;\n", colorTestFuncs[colorTestFunc]);
}
}
if (enableFog) {

View file

@ -179,6 +179,17 @@ static void SetColorUniform3Alpha(int uniform, u32 color, u8 alpha)
glUniform4fv(uniform, 1, col);
}
static void SetColorUniform3iAlpha(int uniform, u32 color, u8 alpha)
{
const GLint col[4] = {
((color & 0xFF)),
((color & 0xFF00) >> 8),
((color & 0xFF0000) >> 16),
alpha
};
glUniform4iv(uniform, 1, col);
}
static void SetColorUniform3ExtraFloat(int uniform, u32 color, float extra)
{
const float col[4] = {
@ -262,7 +273,7 @@ void LinkedShader::updateUniforms() {
SetColorUniform3(u_texenv, gstate.texenvcolor);
}
if (u_alphacolorref != -1 && (dirtyUniforms & DIRTY_ALPHACOLORREF)) {
SetColorUniform3Alpha(u_alphacolorref, gstate.colorref, (gstate.alphatest >> 8) & 0xFF);
SetColorUniform3iAlpha(u_alphacolorref, gstate.colorref, (gstate.alphatest >> 8) & 0xFF);
}
if (u_colormask != -1 && (dirtyUniforms & DIRTY_COLORMASK)) {
SetColorUniform3(u_colormask, gstate.colormask);