Support flat shading.

This commit is contained in:
xebra 2014-11-28 18:59:14 +09:00
parent b0ab0295ba
commit 34fe8300ab
2 changed files with 12 additions and 4 deletions

View file

@ -400,6 +400,7 @@ void ComputeFragmentShaderID(FragmentShaderID *id) {
bool enableColorDoubling = gstate.isColorDoublingEnabled() && gstate.isTextureMapEnabled();
bool doTextureProjection = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX;
bool doTextureAlpha = gstate.isTextureAlphaUsed();
bool doFlatShading = gstate.getShadeMode() == GE_SHADE_FLAT;
ReplaceBlendType replaceBlend = ReplaceBlendWithShader();
ReplaceAlphaType stencilToAlpha = ReplaceAlphaWithStencil(replaceBlend);
@ -466,6 +467,7 @@ void ComputeFragmentShaderID(FragmentShaderID *id) {
id1 |= gstate.getBlendFuncA() << 6;
id1 |= gstate.getBlendFuncB() << 10;
}
id1 |= (doFlatShading & 1) << 14;
}
id->d[0] = id0;
@ -575,6 +577,8 @@ void GenerateFragmentShader(char *buffer) {
ReplaceBlendType replaceBlend = ReplaceBlendWithShader();
ReplaceAlphaType stencilToAlpha = ReplaceAlphaWithStencil(replaceBlend);
char *shading = gstate.getShadeMode() == GE_SHADE_FLAT ? "flat" : "smooth";
if (gstate_c.textureFullAlpha && gstate.getTextureFunction() != GE_TEXFUNC_REPLACE)
doTextureAlpha = false;
@ -617,9 +621,9 @@ void GenerateFragmentShader(char *buffer) {
if (gstate.isTextureMapEnabled() && gstate.getTextureFunction() == GE_TEXFUNC_BLEND)
WRITE(p, "uniform vec3 u_texenv;\n");
WRITE(p, "%s vec4 v_color0;\n", varying);
WRITE(p, "%s %s vec4 v_color0;\n", shading, varying);
if (lmode)
WRITE(p, "%s vec3 v_color1;\n", varying);
WRITE(p, "%s %s vec3 v_color1;\n", shading, varying);
if (enableFog) {
WRITE(p, "uniform vec3 u_fogcolor;\n");
WRITE(p, "%s %s float v_fogdepth;\n", varying, highpFog ? "highp" : "mediump");

View file

@ -52,6 +52,7 @@ void ComputeVertexShaderID(VertexShaderID *id, u32 vertType, int prim, bool useH
bool doTexture = gstate.isTextureMapEnabled() && !gstate.isModeClear();
bool doTextureProjection = gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX;
bool doShadeMapping = gstate.getUVGenMode() == GE_TEXMAP_ENVIRONMENT_MAP;
bool doFlatShading = gstate.getShadeMode() == GE_SHADE_FLAT;
bool hasColor = (vertType & GE_VTYPE_COL_MASK) != 0;
bool hasNormal = (vertType & GE_VTYPE_NRM_MASK) != 0;
@ -115,6 +116,7 @@ void ComputeVertexShaderID(VertexShaderID *id, u32 vertType, int prim, bool useH
id1 |= (hasTexcoord & 1) << 28;
}
}
id1 |= (doFlatShading & 1) << 29;
id->d[0] = id0;
id->d[1] = id1;
@ -222,6 +224,8 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf
bool flipV = gstate_c.flipTexture; // This also means that we are texturing from a render target
bool flipNormal = gstate.areNormalsReversed();
char *shading = gstate.getShadeMode() == GE_SHADE_FLAT ? "flat" : "smooth";
DoLightComputation doLight[4] = {LIGHT_OFF, LIGHT_OFF, LIGHT_OFF, LIGHT_OFF};
if (useHWTransform) {
int shadeLight0 = doShadeMapping ? gstate.getUVLS0() : -1;
@ -326,9 +330,9 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf
WRITE(p, "uniform highp vec2 u_fogcoef;\n");
}
WRITE(p, "%s lowp vec4 v_color0;\n", varying);
WRITE(p, "%s %s lowp vec4 v_color0;\n", shading, varying);
if (lmode) {
WRITE(p, "%s lowp vec3 v_color1;\n", varying);
WRITE(p, "%s %s lowp vec3 v_color1;\n", shading, varying);
}
if (doTexture) {
if (doTextureProjection)