citra-emu
/
citra
Archived
1
0
Fork 0

Rasterizer: Implement the other color and alpha modifiers.

This commit is contained in:
bunnei 2015-02-03 18:32:29 -05:00
parent 8c93a28fed
commit 1eb591d6fd
2 changed files with 68 additions and 57 deletions

View File

@ -233,19 +233,29 @@ struct Regs {
}; };
enum class ColorModifier : u32 { enum class ColorModifier : u32 {
SourceColor = 0, SourceColor = 0x0,
OneMinusSourceColor = 1, OneMinusSourceColor = 0x1,
SourceAlpha = 2, SourceAlpha = 0x2,
OneMinusSourceAlpha = 3, OneMinusSourceAlpha = 0x3,
SourceRed = 0x4,
OneMinusSourceRed = 0x5,
// Other values seem to be non-standard extensions SourceGreen = 0x8,
OneMinusSourceGreen = 0x9,
SourceBlue = 0xc,
OneMinusSourceBlue = 0xd,
}; };
enum class AlphaModifier : u32 { enum class AlphaModifier : u32 {
SourceAlpha = 0, SourceAlpha = 0x0,
OneMinusSourceAlpha = 1, OneMinusSourceAlpha = 0x1,
SourceRed = 0x2,
// Other values seem to be non-standard extensions OneMinusSourceRed = 0x3,
SourceGreen = 0x4,
OneMinusSourceGreen = 0x5,
SourceBlue = 0x6,
OneMinusSourceBlue = 0x7,
}; };
enum class Operation : u32 { enum class Operation : u32 {

View File

@ -260,7 +260,7 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0,
using AlphaModifier = Regs::TevStageConfig::AlphaModifier; using AlphaModifier = Regs::TevStageConfig::AlphaModifier;
using Operation = Regs::TevStageConfig::Operation; using Operation = Regs::TevStageConfig::Operation;
auto GetColorSource = [&](Source source) -> Math::Vec4<u8> { auto GetSource = [&](Source source) -> Math::Vec4<u8> {
switch (source) { switch (source) {
case Source::PrimaryColor: case Source::PrimaryColor:
return primary_color; return primary_color;
@ -287,36 +287,8 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0,
} }
}; };
auto GetAlphaSource = [&](Source source) -> u8 {
switch (source) {
case Source::PrimaryColor:
return primary_color.a();
case Source::Texture0:
return texture_color[0].a();
case Source::Texture1:
return texture_color[1].a();
case Source::Texture2:
return texture_color[2].a();
case Source::Constant:
return tev_stage.const_a;
case Source::Previous:
return combiner_output.a();
default:
LOG_ERROR(HW_GPU, "Unknown alpha combiner source %d\n", (int)source);
_dbg_assert_(HW_GPU, 0);
return 0;
}
};
static auto GetColorModifier = [](ColorModifier factor, const Math::Vec4<u8>& values) -> Math::Vec3<u8> { static auto GetColorModifier = [](ColorModifier factor, const Math::Vec4<u8>& values) -> Math::Vec3<u8> {
switch (factor) switch (factor) {
{
case ColorModifier::SourceColor: case ColorModifier::SourceColor:
return values.rgb(); return values.rgb();
@ -324,27 +296,56 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0,
return (Math::Vec3<u8>(255, 255, 255) - values.rgb()).Cast<u8>(); return (Math::Vec3<u8>(255, 255, 255) - values.rgb()).Cast<u8>();
case ColorModifier::SourceAlpha: case ColorModifier::SourceAlpha:
return { values.a(), values.a(), values.a() }; return values.aaa();
default: case ColorModifier::OneMinusSourceAlpha:
LOG_ERROR(HW_GPU, "Unknown color factor %d\n", (int)factor); return (Math::Vec3<u8>(255, 255, 255) - values.aaa()).Cast<u8>();
_dbg_assert_(HW_GPU, 0);
return {}; case ColorModifier::SourceRed:
return values.rrr();
case ColorModifier::OneMinusSourceRed:
return (Math::Vec3<u8>(255, 255, 255) - values.rrr()).Cast<u8>();
case ColorModifier::SourceGreen:
return values.ggg();
case ColorModifier::OneMinusSourceGreen:
return (Math::Vec3<u8>(255, 255, 255) - values.ggg()).Cast<u8>();
case ColorModifier::SourceBlue:
return values.bbb();
case ColorModifier::OneMinusSourceBlue:
return (Math::Vec3<u8>(255, 255, 255) - values.bbb()).Cast<u8>();
} }
}; };
static auto GetAlphaModifier = [](AlphaModifier factor, u8 value) -> u8 { static auto GetAlphaModifier = [](AlphaModifier factor, const Math::Vec4<u8>& values) -> u8 {
switch (factor) { switch (factor) {
case AlphaModifier::SourceAlpha: case AlphaModifier::SourceAlpha:
return value; return values.a();
case AlphaModifier::OneMinusSourceAlpha: case AlphaModifier::OneMinusSourceAlpha:
return 255 - value; return 255 - values.a();
default: case AlphaModifier::SourceRed:
LOG_ERROR(HW_GPU, "Unknown alpha factor %d\n", (int)factor); return values.r();
_dbg_assert_(HW_GPU, 0);
return 0; case AlphaModifier::OneMinusSourceRed:
return 255 - values.r();
case AlphaModifier::SourceGreen:
return values.g();
case AlphaModifier::OneMinusSourceGreen:
return 255 - values.g();
case AlphaModifier::SourceBlue:
return values.b();
case AlphaModifier::OneMinusSourceBlue:
return 255 - values.b();
} }
}; };
@ -414,17 +415,17 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0,
// combiner_output.rgb(), but instead store it in a temporary variable until // combiner_output.rgb(), but instead store it in a temporary variable until
// alpha combining has been done. // alpha combining has been done.
Math::Vec3<u8> color_result[3] = { Math::Vec3<u8> color_result[3] = {
GetColorModifier(tev_stage.color_modifier1, GetColorSource(tev_stage.color_source1)), GetColorModifier(tev_stage.color_modifier1, GetSource(tev_stage.color_source1)),
GetColorModifier(tev_stage.color_modifier2, GetColorSource(tev_stage.color_source2)), GetColorModifier(tev_stage.color_modifier2, GetSource(tev_stage.color_source2)),
GetColorModifier(tev_stage.color_modifier3, GetColorSource(tev_stage.color_source3)) GetColorModifier(tev_stage.color_modifier3, GetSource(tev_stage.color_source3))
}; };
auto color_output = ColorCombine(tev_stage.color_op, color_result); auto color_output = ColorCombine(tev_stage.color_op, color_result);
// alpha combiner // alpha combiner
std::array<u8,3> alpha_result = { std::array<u8,3> alpha_result = {
GetAlphaModifier(tev_stage.alpha_modifier1, GetAlphaSource(tev_stage.alpha_source1)), GetAlphaModifier(tev_stage.alpha_modifier1, GetSource(tev_stage.alpha_source1)),
GetAlphaModifier(tev_stage.alpha_modifier2, GetAlphaSource(tev_stage.alpha_source2)), GetAlphaModifier(tev_stage.alpha_modifier2, GetSource(tev_stage.alpha_source2)),
GetAlphaModifier(tev_stage.alpha_modifier3, GetAlphaSource(tev_stage.alpha_source3)) GetAlphaModifier(tev_stage.alpha_modifier3, GetSource(tev_stage.alpha_source3))
}; };
auto alpha_output = AlphaCombine(tev_stage.alpha_op, alpha_result); auto alpha_output = AlphaCombine(tev_stage.alpha_op, alpha_result);