diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index 7eb7a0608..0047eb78a 100644 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -307,7 +307,7 @@ static const char *fragmentShader_100 = {"\ uniform float stateAlphaTestRef;\n\ \n\ uniform int polyMode;\n\ - uniform bool polyIsTranslucent;\n\ + uniform bool polyIsWireframe;\n\ uniform bool polySetNewDepthForTranslucent;\n\ uniform int polyID;\n\ \n\ @@ -365,17 +365,17 @@ static const char *fragmentShader_100 = {"\ \n\ newFragColor = mainTexColor * vtxColor;\n\ \n\ - if(polyMode == 1)\n\ + if (polyMode == 1)\n\ {\n\ newFragColor.rgb = (polyEnableTexture) ? mix(vtxColor.rgb, mainTexColor.rgb, mainTexColor.a) : vtxColor.rgb;\n\ newFragColor.a = vtxColor.a;\n\ }\n\ - else if(polyMode == 2)\n\ + else if (polyMode == 2)\n\ {\n\ - vec3 toonColor = vec3(texture1D(texToonTable, vtxColor.r).rgb);\n\ - newFragColor.rgb = (stateToonShadingMode == 0) ? mainTexColor.rgb * toonColor.rgb : min((mainTexColor.rgb * vtxColor.r) + toonColor.rgb, 1.0);\n\ + vec3 newToonColor = vec3(texture1D(texToonTable, vtxColor.r).rgb);\n\ + newFragColor.rgb = (stateToonShadingMode == 0) ? mainTexColor.rgb * newToonColor.rgb : min((mainTexColor.rgb * vtxColor.r) + newToonColor.rgb, 1.0);\n\ }\n\ - else if(polyMode == 3)\n\ + else if (polyMode == 3)\n\ {\n\ newFragColor = vtxColor;\n\ }\n\ @@ -390,8 +390,8 @@ static const char *fragmentShader_100 = {"\ newFragDepth = vec4(packVec3FromFloat(newFragDepthValue), 1.0);\n\ }\n\ \n\ - newPolyID = vec4(float(polyID)/63.0, 0.0, 0.0, float(newFragColor.a > 0.999));\n\ - newFogAttributes = vec4(float(polyEnableFog), 0.0, 0.0, float((newFragColor.a > 0.999) ? 1.0 : 0.5));\n\ + newPolyID = vec4( float(polyID)/63.0, float(polyIsWireframe), 0.0, float(newFragColor.a > 0.999) );\n\ + newFogAttributes = vec4( float(polyEnableFog), 0.0, 0.0, float((newFragColor.a > 0.999) ? 1.0 : 0.5) );\n\ }\n\ \n\ gl_FragData[0] = newFragColor;\n\ @@ -439,12 +439,26 @@ static const char *EdgeMarkFragShader_100 = {"\ \n\ void main()\n\ {\n\ + vec4 polyIDInfo[5];\n\ + polyIDInfo[0] = texture2D(texInPolyID, texCoord[0]);\n\ + polyIDInfo[1] = texture2D(texInPolyID, texCoord[1]);\n\ + polyIDInfo[2] = texture2D(texInPolyID, texCoord[2]);\n\ + polyIDInfo[3] = texture2D(texInPolyID, texCoord[3]);\n\ + polyIDInfo[4] = texture2D(texInPolyID, texCoord[4]);\n\ + \n\ int polyID[5];\n\ - polyID[0] = int((texture2D(texInPolyID, texCoord[0]).r * 63.0) + 0.5);\n\ - polyID[1] = int((texture2D(texInPolyID, texCoord[1]).r * 63.0) + 0.5);\n\ - polyID[2] = int((texture2D(texInPolyID, texCoord[2]).r * 63.0) + 0.5);\n\ - polyID[3] = int((texture2D(texInPolyID, texCoord[3]).r * 63.0) + 0.5);\n\ - polyID[4] = int((texture2D(texInPolyID, texCoord[4]).r * 63.0) + 0.5);\n\ + polyID[0] = int((polyIDInfo[0].r * 63.0) + 0.5);\n\ + polyID[1] = int((polyIDInfo[1].r * 63.0) + 0.5);\n\ + polyID[2] = int((polyIDInfo[2].r * 63.0) + 0.5);\n\ + polyID[3] = int((polyIDInfo[3].r * 63.0) + 0.5);\n\ + polyID[4] = int((polyIDInfo[4].r * 63.0) + 0.5);\n\ + \n\ + bool isWireframe[5];\n\ + isWireframe[0] = bool(polyIDInfo[0].g);\n\ + isWireframe[1] = bool(polyIDInfo[1].g);\n\ + isWireframe[2] = bool(polyIDInfo[2].g);\n\ + isWireframe[3] = bool(polyIDInfo[3].g);\n\ + isWireframe[4] = bool(polyIDInfo[4].g);\n\ \n\ float depth[5];\n\ depth[0] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[0]).rgb);\n\ @@ -453,18 +467,21 @@ static const char *EdgeMarkFragShader_100 = {"\ depth[3] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[3]).rgb);\n\ depth[4] = unpackFloatFromVec3(texture2D(texInFragDepth, texCoord[4]).rgb);\n\ \n\ - vec4 edgeColor = vec4(0.0, 0.0, 0.0, 0.0);\n\ + vec4 newEdgeColor = vec4(0.0, 0.0, 0.0, 0.0);\n\ \n\ - for (int i = 1; i < 5; i++)\n\ + if (!isWireframe[0])\n\ {\n\ - if (polyID[0] != polyID[i] && depth[0] >= depth[i])\n\ + for (int i = 1; i < 5; i++)\n\ {\n\ - edgeColor = stateEdgeColor[polyID[i]/8];\n\ - break;\n\ + if ( (polyID[0] != polyID[i]) && (depth[0] >= depth[i]) && !isWireframe[i] )\n\ + {\n\ + newEdgeColor = stateEdgeColor[polyID[i]/8];\n\ + break;\n\ + }\n\ }\n\ }\n\ \n\ - gl_FragData[0] = edgeColor;\n\ + gl_FragData[0] = newEdgeColor;\n\ }\n\ "}; @@ -1653,7 +1670,7 @@ Render3DError OpenGLRenderer_1_2::InitGeometryProgramShaderLocations() OGLRef.uniformPolyTexScale = glGetUniformLocation(OGLRef.programGeometryID, "polyTexScale"); OGLRef.uniformPolyMode = glGetUniformLocation(OGLRef.programGeometryID, "polyMode"); - OGLRef.uniformPolyIsTranslucent = glGetUniformLocation(OGLRef.programGeometryID, "polyIsTranslucent"); + OGLRef.uniformPolyIsWireframe = glGetUniformLocation(OGLRef.programGeometryID, "polyIsWireframe"); OGLRef.uniformPolySetNewDepthForTranslucent = glGetUniformLocation(OGLRef.programGeometryID, "polySetNewDepthForTranslucent"); OGLRef.uniformPolyAlpha = glGetUniformLocation(OGLRef.programGeometryID, "polyAlpha"); OGLRef.uniformPolyID = glGetUniformLocation(OGLRef.programGeometryID, "polyID"); @@ -3071,7 +3088,7 @@ Render3DError OpenGLRenderer_1_2::SetupPolygon(const POLY &thePoly) glUniform1i(OGLRef.uniformPolyEnableFog, (attr.enableRenderFog) ? GL_TRUE : GL_FALSE); glUniform1f(OGLRef.uniformPolyAlpha, (attr.isWireframe) ? 1.0f : divide5bitBy31_LUT[attr.alpha]); glUniform1i(OGLRef.uniformPolyID, attr.polygonID); - glUniform1i(OGLRef.uniformPolyIsTranslucent, (attr.isTranslucent && !isOpaqueDecal) ? GL_TRUE : GL_FALSE); + glUniform1i(OGLRef.uniformPolyIsWireframe, (attr.isWireframe) ? GL_TRUE : GL_FALSE); glUniform1i(OGLRef.uniformPolySetNewDepthForTranslucent, (attr.enableAlphaDepthWrite) ? GL_TRUE : GL_FALSE); } else diff --git a/desmume/src/OGLRender.h b/desmume/src/OGLRender.h index 4390a26cf..5daccd88f 100644 --- a/desmume/src/OGLRender.h +++ b/desmume/src/OGLRender.h @@ -377,7 +377,7 @@ struct OGLPolyStates { union { - struct { GLubyte enableTexture, enableFog, isTranslucent, setNewDepthForTranslucent; }; + struct { GLubyte enableTexture, enableFog, isWireframe, setNewDepthForTranslucent; }; GLubyte flags[4]; }; @@ -474,7 +474,7 @@ struct OGLRenderRef GLint uniformPolyTexScale; GLint uniformPolyMode; - GLint uniformPolyIsTranslucent; + GLint uniformPolyIsWireframe; GLint uniformPolySetNewDepthForTranslucent; GLint uniformPolyAlpha; GLint uniformPolyID; diff --git a/desmume/src/OGLRender_3_2.cpp b/desmume/src/OGLRender_3_2.cpp index d7f4cc0bb..75bc6caca 100644 --- a/desmume/src/OGLRender_3_2.cpp +++ b/desmume/src/OGLRender_3_2.cpp @@ -116,7 +116,7 @@ static const char *GeometryVtxShader_150 = {"\ out vec4 vtxColor; \n\ flat out uint polyEnableTexture;\n\ flat out uint polyEnableFog;\n\ - flat out uint polyIsTranslucent;\n\ + flat out uint polyIsWireframe;\n\ flat out uint polySetNewDepthForTranslucent;\n\ flat out uint polyMode;\n\ flat out uint polyID;\n\ @@ -133,7 +133,7 @@ static const char *GeometryVtxShader_150 = {"\ \n\ polyEnableTexture = polyStateFlags[0];\n\ polyEnableFog = polyStateFlags[1];\n\ - polyIsTranslucent = polyStateFlags[2];\n\ + polyIsWireframe = polyStateFlags[2];\n\ polySetNewDepthForTranslucent = polyStateFlags[3];\n\ polyMode = polyStateValues[1];\n\ polyID = polyStateValues[2];\n\ @@ -159,7 +159,7 @@ static const char *GeometryFragShader_150 = {"\ in vec4 vtxColor;\n\ flat in uint polyEnableTexture;\n\ flat in uint polyEnableFog;\n\ - flat in uint polyIsTranslucent;\n\ + flat in uint polyIsWireframe;\n\ flat in uint polySetNewDepthForTranslucent;\n\ flat in uint polyMode;\n\ flat in uint polyID;\n\ @@ -274,8 +274,8 @@ static const char *GeometryFragShader_150 = {"\ newFragDepth = vec4(packVec3FromFloat(newFragDepthValue), 1.0);\n\ }\n\ \n\ - newPolyID = vec4(float(polyID)/63.0, 0.0, 0.0, float(newFragColor.a > 0.999));\n\ - newFogAttributes = vec4(float(polyEnableFog), 0.0, 0.0, float((newFragColor.a > 0.999) ? 1.0 : 0.5));\n\ + newPolyID = vec4( float(polyID)/63.0, float(polyIsWireframe == 1u), 0.0, float(newFragColor.a > 0.999) );\n\ + newFogAttributes = vec4( float(polyEnableFog), 0.0, 0.0, float((newFragColor.a > 0.999) ? 1.0 : 0.5) );\n\ }\n\ \n\ outFragColor = newFragColor;\n\ @@ -365,12 +365,26 @@ static const char *EdgeMarkFragShader_150 = {"\ \n\ void main()\n\ {\n\ + vec4 polyIDInfo[5];\n\ + polyIDInfo[0] = texture(texInPolyID, texCoord[0]);\n\ + polyIDInfo[1] = texture(texInPolyID, texCoord[1]);\n\ + polyIDInfo[2] = texture(texInPolyID, texCoord[2]);\n\ + polyIDInfo[3] = texture(texInPolyID, texCoord[3]);\n\ + polyIDInfo[4] = texture(texInPolyID, texCoord[4]);\n\ + \n\ int polyID[5];\n\ - polyID[0] = int((texture(texInPolyID, texCoord[0]).r * 63.0) + 0.5);\n\ - polyID[1] = int((texture(texInPolyID, texCoord[1]).r * 63.0) + 0.5);\n\ - polyID[2] = int((texture(texInPolyID, texCoord[2]).r * 63.0) + 0.5);\n\ - polyID[3] = int((texture(texInPolyID, texCoord[3]).r * 63.0) + 0.5);\n\ - polyID[4] = int((texture(texInPolyID, texCoord[4]).r * 63.0) + 0.5);\n\ + polyID[0] = int((polyIDInfo[0].r * 63.0) + 0.5);\n\ + polyID[1] = int((polyIDInfo[1].r * 63.0) + 0.5);\n\ + polyID[2] = int((polyIDInfo[2].r * 63.0) + 0.5);\n\ + polyID[3] = int((polyIDInfo[3].r * 63.0) + 0.5);\n\ + polyID[4] = int((polyIDInfo[4].r * 63.0) + 0.5);\n\ + \n\ + bool isWireframe[5];\n\ + isWireframe[0] = bool(polyIDInfo[0].g);\n\ + isWireframe[1] = bool(polyIDInfo[1].g);\n\ + isWireframe[2] = bool(polyIDInfo[2].g);\n\ + isWireframe[3] = bool(polyIDInfo[3].g);\n\ + isWireframe[4] = bool(polyIDInfo[4].g);\n\ \n\ float depth[5];\n\ depth[0] = unpackFloatFromVec3(texture(texInFragDepth, texCoord[0]).rgb);\n\ @@ -381,12 +395,15 @@ static const char *EdgeMarkFragShader_150 = {"\ \n\ vec4 newEdgeColor = vec4(0.0, 0.0, 0.0, 0.0);\n\ \n\ - for (int i = 1; i < 5; i++)\n\ + if (!isWireframe[0])\n\ {\n\ - if (polyID[0] != polyID[i] && depth[0] >= depth[i])\n\ + for (int i = 1; i < 5; i++)\n\ {\n\ - newEdgeColor = state.edgeColor[polyID[i]/8];\n\ - break;\n\ + if ( (polyID[0] != polyID[i]) && (depth[0] >= depth[i]) && !isWireframe[i] )\n\ + {\n\ + newEdgeColor = state.edgeColor[polyID[i]/8];\n\ + break;\n\ + }\n\ }\n\ }\n\ \n\ @@ -1465,7 +1482,7 @@ Render3DError OpenGLRenderer_3_2::BeginRender(const GFX3D &engine) polyStates[i].enableTexture = (this->_textureList[i]->IsSamplingEnabled()) ? GL_TRUE : GL_FALSE; polyStates[i].enableFog = (polyAttr.enableRenderFog) ? GL_TRUE : GL_FALSE; - polyStates[i].isTranslucent = (polyAttr.isTranslucent && !((polyAttr.polygonMode == POLYGON_MODE_DECAL) && polyAttr.isOpaque)) ? GL_TRUE : GL_FALSE; + polyStates[i].isWireframe = (polyAttr.isWireframe) ? GL_TRUE : GL_FALSE; polyStates[i].setNewDepthForTranslucent = (polyAttr.enableAlphaDepthWrite) ? GL_TRUE : GL_FALSE; polyStates[i].polyAlpha = (polyAttr.isWireframe) ? 0x1F : polyAttr.alpha; polyStates[i].polyMode = polyAttr.polygonMode;