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 { else {
if (textureAlpha || polyAlpha) { if (polyAlpha) {
return false; return false;
} }
} }

View file

@ -312,14 +312,18 @@ void CNew3D::RenderFrame(void)
glViewport (0, 0, m_totalXRes, m_totalYRes); // clear whole viewport glViewport (0, 0, m_totalXRes, m_totalYRes); // clear whole viewport
glClear (GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); 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); hasOverlay = RenderScene(pri, false, false);
m_r3dShader.DiscardAlpha(false);
hasOverlay = RenderScene(pri, false, true); hasOverlay = RenderScene(pri, false, true);
if (hasOverlay) { if (hasOverlay) {
//clear depth buffer and render high priority polys //clear depth buffer and render high priority polys
glViewport(0, 0, m_totalXRes, m_totalYRes); // clear whole viewport glViewport(0, 0, m_totalXRes, m_totalYRes); // clear whole viewport
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_r3dShader.DiscardAlpha(true);
RenderScene(pri, true, false); RenderScene(pri, true, false);
m_r3dShader.DiscardAlpha(false);
RenderScene(pri, true, true); RenderScene(pri, true, true);
} }
} }

View file

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

View file

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