Render the opaque part of texture transparency in the first pass. Fixes numerous transparency related issues in lemans24 and some in ocean hunter. I don't really know if this is the 'correct' way of solving this because the real3d pro-1000 is a complete black box. There is still a lot we don't understand about how it handles transparency.

This commit is contained in:
Ian Curtis 2018-05-02 20:10:02 +00:00
parent 11a3cdbfd1
commit c6b86c0812
4 changed files with 21 additions and 1 deletions

View file

@ -97,7 +97,7 @@ struct Mesh
}
}
else {
if (textureAlpha || polyAlpha) {
if (polyAlpha) {
return false;
}
}

View file

@ -312,14 +312,18 @@ void CNew3D::RenderFrame(void)
glViewport (0, 0, m_totalXRes, m_totalYRes); // clear whole viewport
glClear (GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
m_r3dShader.DiscardAlpha(true); // chuck out alpha pixels in texture alpha only polys
hasOverlay = RenderScene(pri, false, false);
m_r3dShader.DiscardAlpha(false);
hasOverlay = RenderScene(pri, false, true);
if (hasOverlay) {
//clear depth buffer and render high priority polys
glViewport(0, 0, m_totalXRes, m_totalYRes); // clear whole viewport
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_r3dShader.DiscardAlpha(true);
RenderScene(pri, true, false);
m_r3dShader.DiscardAlpha(false);
RenderScene(pri, true, true);
}
}

View file

@ -62,6 +62,7 @@ uniform vec2 baseTexSize;
uniform bool textureInverted;
uniform bool textureAlpha;
uniform bool alphaTest;
uniform bool discardAlpha;
// general
uniform vec3 fogColour;
@ -113,6 +114,12 @@ vec4 GetTextureValue()
}
}
if(discardAlpha && textureAlpha) {
if (tex1Data.a < 1.0) {
discard;
}
}
if (textureAlpha == false) {
tex1Data.a = 1.0;
}
@ -372,6 +379,7 @@ bool R3DShader::LoadShader(const char* vertexShader, const char* fragmentShader)
m_locModelScale = glGetUniformLocation(m_shaderProgram, "modelScale");
m_locHardwareStep = glGetUniformLocation(m_shaderProgram, "hardwareStep");
m_locDiscardAlpha = glGetUniformLocation(m_shaderProgram, "discardAlpha");
return success;
}
@ -386,6 +394,7 @@ void R3DShader::SetShader(bool enable)
if (enable) {
glUseProgram(m_shaderProgram);
Start();
DiscardAlpha(false); // need some default
}
else {
glUseProgram(0);
@ -512,4 +521,9 @@ void R3DShader::SetModelStates(const Model* model)
m_dirtyModel = false;
}
void R3DShader::DiscardAlpha(bool discard)
{
glUniform1i(m_locDiscardAlpha, discard);
}
} // New3D

View file

@ -19,6 +19,7 @@ public:
void Start ();
void SetShader (bool enable = true);
GLint GetVertexAttribPos (const char* attrib);
void DiscardAlpha (bool discard); // use to remove alpha from texture alpha only polys for 1st pass
private:
@ -93,6 +94,7 @@ private:
// global uniforms
GLint m_locHardwareStep;
GLint m_locDiscardAlpha;
};
} // New3D