GPU: Two-pass rendering for B-F transparency

This commit is contained in:
Connor McLaughlin
2019-10-06 13:09:03 +10:00
parent 7254d48835
commit 5627955900
5 changed files with 65 additions and 47 deletions

View File

@ -245,12 +245,14 @@ void main()
return ss.str();
}
std::string GPU_HW::GenerateFragmentShader(bool transparent, bool textured, TextureColorMode texture_color_mode,
bool blending)
std::string GPU_HW::GenerateFragmentShader(TransparencyRenderMode transparency, bool textured,
TextureColorMode texture_color_mode, bool blending)
{
std::stringstream ss;
GenerateShaderHeader(ss);
DefineMacro(ss, "TRANSPARENT", transparent);
DefineMacro(ss, "TRANSPARENT", transparency != TransparencyRenderMode::Off);
DefineMacro(ss, "TRANSPARENT_ONLY_OPAQUE", transparency == TransparencyRenderMode::OnlyOpaque);
DefineMacro(ss, "TRANSPARENT_ONLY_TRANSPARENT", transparency == TransparencyRenderMode::OnlyTransparent);
DefineMacro(ss, "TEXTURED", textured);
DefineMacro(ss, "PALETTE",
textured && (texture_color_mode == GPU::TextureColorMode::Palette4Bit ||
@ -337,9 +339,19 @@ void main()
#if TRANSPARENT
// Apply semitransparency. If not a semitransparent texel, destination alpha is ignored.
if (texcol.a != 0)
{
#if TRANSPARENT_ONLY_OPAQUE
discard;
#endif
o_col0 = vec4(color * u_transparent_alpha.x, u_transparent_alpha.y);
}
else
{
#if TRANSPARENT_ONLY_TRANSPARENT
discard;
#endif
o_col0 = vec4(color, 0.0);
}
#else
// Mask bit from texture.
o_col0 = vec4(color, texcol.a);
@ -575,4 +587,5 @@ void GPU_HW::DispatchRenderCommand(RenderCommand rc, u32 num_vertices)
}
LoadVertices(rc, num_vertices);
FlushRender();
}