Implementing alpha testing.
This commit is contained in:
parent
a82587f943
commit
f7d0c427be
|
@ -1812,14 +1812,6 @@ CommandProcessor::UpdateStatus CommandProcessor::UpdateState() {
|
||||||
|
|
||||||
bool mismatch = false;
|
bool mismatch = false;
|
||||||
|
|
||||||
// Alpha testing -- ALPHAREF, ALPHAFUNC, ALPHATESTENABLE
|
|
||||||
// Deprecated in GL, implemented in shader.
|
|
||||||
// if(ALPHATESTENABLE && frag_out.a [<=/ALPHAFUNC] ALPHAREF) discard;
|
|
||||||
uint32_t color_control = regs[XE_GPU_REG_RB_COLORCONTROL].u32;
|
|
||||||
draw_batcher_.set_alpha_test((color_control & 0x4) != 0, // ALPAHTESTENABLE
|
|
||||||
color_control & 0x3, // ALPHAFUNC
|
|
||||||
regs[XE_GPU_REG_RB_ALPHA_REF].f32);
|
|
||||||
|
|
||||||
#define CHECK_UPDATE_STATUS(status, mismatch, error_message) \
|
#define CHECK_UPDATE_STATUS(status, mismatch, error_message) \
|
||||||
{ \
|
{ \
|
||||||
if (status == UpdateStatus::kError) { \
|
if (status == UpdateStatus::kError) { \
|
||||||
|
@ -2075,8 +2067,17 @@ CommandProcessor::UpdateStatus CommandProcessor::UpdateRasterizerState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandProcessor::UpdateStatus CommandProcessor::UpdateBlendState() {
|
CommandProcessor::UpdateStatus CommandProcessor::UpdateBlendState() {
|
||||||
|
auto& reg_file = *register_file_;
|
||||||
auto& regs = update_blend_state_regs_;
|
auto& regs = update_blend_state_regs_;
|
||||||
|
|
||||||
|
// Alpha testing -- ALPHAREF, ALPHAFUNC, ALPHATESTENABLE
|
||||||
|
// Deprecated in GL, implemented in shader.
|
||||||
|
// if(ALPHATESTENABLE && frag_out.a [<=/ALPHAFUNC] ALPHAREF) discard;
|
||||||
|
uint32_t color_control = reg_file[XE_GPU_REG_RB_COLORCONTROL].u32;
|
||||||
|
draw_batcher_.set_alpha_test((color_control & 0x4) != 0, // ALPAHTESTENABLE
|
||||||
|
color_control & 0x3, // ALPHAFUNC
|
||||||
|
reg_file[XE_GPU_REG_RB_ALPHA_REF].f32);
|
||||||
|
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
dirty |=
|
dirty |=
|
||||||
SetShadowRegister(regs.rb_blendcontrol[0], XE_GPU_REG_RB_BLENDCONTROL_0);
|
SetShadowRegister(regs.rb_blendcontrol[0], XE_GPU_REG_RB_BLENDCONTROL_0);
|
||||||
|
|
|
@ -171,9 +171,9 @@ class DrawBatcher {
|
||||||
|
|
||||||
// This must match GL4Shader's header.
|
// This must match GL4Shader's header.
|
||||||
struct CommonHeader {
|
struct CommonHeader {
|
||||||
float4 window_scale; // sx,sy, ?, ?
|
float4 window_scale; // sx,sy, ?, ?
|
||||||
float4 vtx_fmt; //
|
float4 vtx_fmt; //
|
||||||
float4 alpha_test; // alpha test enable, func, ref, ?
|
float4 alpha_test; // alpha test enable, func, ref, ?
|
||||||
|
|
||||||
// TODO(benvanik): pack tightly
|
// TODO(benvanik): pack tightly
|
||||||
GLuint64 texture_samplers[32];
|
GLuint64 texture_samplers[32];
|
||||||
|
|
|
@ -245,16 +245,32 @@ bool GL4Shader::PreparePixelShader(
|
||||||
}
|
}
|
||||||
has_prepared_ = true;
|
has_prepared_ = true;
|
||||||
|
|
||||||
std::string source = GetHeader() +
|
std::string source =
|
||||||
"layout(origin_upper_left) in vec4 gl_FragCoord;\n"
|
GetHeader() +
|
||||||
"layout(location = 0) flat in uint draw_id;\n"
|
"layout(origin_upper_left) in vec4 gl_FragCoord;\n"
|
||||||
"layout(location = 1) in VertexData vtx;\n"
|
"layout(location = 0) flat in uint draw_id;\n"
|
||||||
"layout(location = 0) out vec4 oC[4];\n"
|
"layout(location = 1) in VertexData vtx;\n"
|
||||||
"void processFragment(const in StateData state);\n"
|
"layout(location = 0) out vec4 oC[4];\n"
|
||||||
"void main() {\n" +
|
"void processFragment(const in StateData state);\n"
|
||||||
" const StateData state = states[draw_id];\n"
|
"void applyAlphaTest(int alpha_func, float alpha_ref) {\n"
|
||||||
" processFragment(state);\n"
|
" switch (alpha_func) {\n"
|
||||||
"}\n";
|
" case 0: discard;\n"
|
||||||
|
" case 1: if (oC[0].a < alpha_ref) discard; break;\n"
|
||||||
|
" case 2: if (oC[0].a == alpha_ref) discard; break;\n"
|
||||||
|
" case 3: if (oC[0].a <= alpha_ref) discard; break;\n"
|
||||||
|
" case 4: if (oC[0].a > alpha_ref) discard; break;\n"
|
||||||
|
" case 5: if (oC[0].a != alpha_ref) discard; break;\n"
|
||||||
|
" case 6: if (oC[0].a >= alpha_ref) discard; break;\n"
|
||||||
|
" case 7: break;\n"
|
||||||
|
" };\n"
|
||||||
|
"}\n"
|
||||||
|
"void main() {\n" +
|
||||||
|
" const StateData state = states[draw_id];\n"
|
||||||
|
" processFragment(state);\n"
|
||||||
|
" if (state.alpha_test.x != 0.0) {\n"
|
||||||
|
" applyAlphaTest(int(state.alpha_test.y), state.alpha_test.z);\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
std::string translated_source =
|
std::string translated_source =
|
||||||
shader_translator_.TranslatePixelShader(this, program_cntl);
|
shader_translator_.TranslatePixelShader(this, program_cntl);
|
||||||
|
|
|
@ -1166,6 +1166,10 @@ void DrawTextureInfo(TracePlayer& player, const Shader::SamplerDesc& desc) {
|
||||||
ImGui::Columns(1);
|
ImGui::Columns(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* kCompareFuncNames[] = {
|
||||||
|
"<false>", "<", "==", "<=", ">", "!=", ">=", "<true>",
|
||||||
|
};
|
||||||
|
|
||||||
void DrawStateUI(xe::ui::MainWindow* window, TracePlayer& player,
|
void DrawStateUI(xe::ui::MainWindow* window, TracePlayer& player,
|
||||||
uint8_t* membase) {
|
uint8_t* membase) {
|
||||||
auto gs = static_cast<gl4::GL4GraphicsSystem*>(player.graphics_system());
|
auto gs = static_cast<gl4::GL4GraphicsSystem*>(player.graphics_system());
|
||||||
|
@ -1464,14 +1468,25 @@ void DrawStateUI(xe::ui::MainWindow* window, TracePlayer& player,
|
||||||
blend_color.y, blend_color.z, blend_color.w);
|
blend_color.y, blend_color.z, blend_color.w);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::ColorButton(blend_color, true);
|
ImGui::ColorButton(blend_color, true);
|
||||||
|
|
||||||
|
// Alpha testing -- ALPHAREF, ALPHAFUNC, ALPHATESTENABLE
|
||||||
|
// if(ALPHATESTENABLE && frag_out.a [<=/ALPHAFUNC] ALPHAREF) discard;
|
||||||
|
uint32_t color_control = regs[XE_GPU_REG_RB_COLORCONTROL].u32;
|
||||||
|
if ((color_control & 0x4) != 0) {
|
||||||
|
ImGui::BulletText("Alpha Test: discard if %s %.2f",
|
||||||
|
kCompareFuncNames[color_control & 0x3],
|
||||||
|
regs[XE_GPU_REG_RB_ALPHA_REF].f32);
|
||||||
|
} else {
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Text, kColorIgnored);
|
||||||
|
ImGui::BulletText("Alpha Test: disabled");
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
if (ImGui::TreeNode("Depth-Stencil State")) {
|
if (ImGui::TreeNode("Depth-Stencil State")) {
|
||||||
auto rb_depthcontrol = regs[XE_GPU_REG_RB_DEPTHCONTROL].u32;
|
auto rb_depthcontrol = regs[XE_GPU_REG_RB_DEPTHCONTROL].u32;
|
||||||
auto rb_stencilrefmask = regs[XE_GPU_REG_RB_STENCILREFMASK].u32;
|
auto rb_stencilrefmask = regs[XE_GPU_REG_RB_STENCILREFMASK].u32;
|
||||||
static const char* kCompareFuncNames[] = {
|
|
||||||
"<false>", "<", "==", "<=", ">", "!=", ">=", "<true>",
|
|
||||||
};
|
|
||||||
if (rb_depthcontrol & 0x00000002) {
|
if (rb_depthcontrol & 0x00000002) {
|
||||||
ImGui::BulletText("Depth Test: enabled");
|
ImGui::BulletText("Depth Test: enabled");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue