Unify the spongebob depth inverse check

This commit is contained in:
Henrik Rydgård committed 2022-08-28 07:11:00 +02:00
1 parent 322f29ce80
commit df92f72ac3
5 files changed
+15 -18

No files matched your search

+11
View File
@@ -4,6 +4,7 @@
#include "Common/CommonTypes.h"
#include "GPU/ge_constants.h"
#include "GPU/GPUState.h"
// TODO: Replace enums and structs with same from thin3d.h, for convenient mapping.
@@ -198,3 +199,13 @@ struct GenericStencilFuncState {
};
void ConvertStencilFuncState(GenericStencilFuncState &stencilFuncState);
// See issue #15898
inline bool SpongebobDepthInverseConditions(const GenericStencilFuncState &stencilState) {
return gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() && stencilState.zFail == GE_STENCILOP_ZERO &&
stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP &&
stencilState.testFunc == GE_COMP_ALWAYS &&
stencilState.writeMask == 0xFF && stencilState.testMask == 0xFF && stencilState.testRef == 0xFF &&
// Also verify no color is written.
true;
}
+1 -4
View File
@@ -297,10 +297,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {
// Nasty special case for Spongebob and similar where it tries to write zeros to alpha/stencil during
// depth-fail. We can't write to alpha then because the pixel is killed. However, we can invert the depth
// test and modify the alpha function...
if (gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() && stencilState.zFail == GE_STENCILOP_ZERO &&
stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP &&
stencilState.testFunc == GE_COMP_ALWAYS &&
stencilState.writeMask == 0xFF && stencilState.testMask == 0xFF && stencilState.testRef == 0xFF) {
if (SpongebobDepthInverseConditions(stencilState)) {
keys_.blend.blendEnable = true;
keys_.blend.blendOpAlpha = D3D11_BLEND_OP_ADD;
keys_.blend.blendOpColor = D3D11_BLEND_OP_ADD;
+1 -5
View File
@@ -251,11 +251,7 @@ void DrawEngineDX9::ApplyDrawState(int prim) {
// Nasty special case for Spongebob and similar where it tries to write zeros to alpha/stencil during
// depth-fail. We can't write to alpha then because the pixel is killed. However, we can invert the depth
// test and modify the alpha function...
if (gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() && stencilState.zFail == GE_STENCILOP_ZERO &&
stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP &&
stencilState.testFunc == GE_COMP_ALWAYS &&
stencilState.writeMask == 0xFF && stencilState.testMask == 0xFF && stencilState.testRef == 0xFF) {
if (SpongebobDepthInverseConditions(stencilState)) {
dxstate.blend.set(true);
dxstate.blendEquation.set(D3DBLENDOP_ADD, D3DBLENDOP_ADD);
dxstate.blendFunc.set(D3DBLEND_ZERO, D3DBLEND_ZERO, D3DBLEND_ZERO, D3DBLEND_ZERO);
+1 -5
View File
@@ -263,11 +263,7 @@ void DrawEngineGLES::ApplyDrawState(int prim) {
// Nasty special case for Spongebob and similar where it tries to write zeros to alpha/stencil during
// depth-fail. We can't write to alpha then because the pixel is killed. However, we can invert the depth
// test and modify the alpha function...
if (gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() && stencilState.zFail == GE_STENCILOP_ZERO &&
stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP &&
stencilState.testFunc == GE_COMP_ALWAYS &&
stencilState.writeMask == 0xFF && stencilState.testMask == 0xFF && stencilState.testRef == 0xFF) {
if (SpongebobDepthInverseConditions(stencilState)) {
renderManager->SetBlendAndMask(0x8, true, GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, GL_FUNC_ADD, GL_FUNC_ADD);
renderManager->SetDepth(true, false, GL_LESS);
renderManager->SetStencilFunc(true, GL_ALWAYS, 0xFF, 0xFF);
+1 -4
View File
@@ -305,10 +305,7 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
// Nasty special case for Spongebob and similar where it tries to write zeros to alpha/stencil during
// depth-fail. We can't write to alpha then because the pixel is killed. However, we can invert the depth
// test and modify the alpha function...
if (gstate.isDepthTestEnabled() && !gstate.isDepthWriteEnabled() && stencilState.zFail == GE_STENCILOP_ZERO &&
stencilState.sFail == GE_STENCILOP_KEEP && stencilState.zPass == GE_STENCILOP_KEEP &&
stencilState.testFunc == GE_COMP_ALWAYS &&
stencilState.writeMask == 0xFF && stencilState.testMask == 0xFF && stencilState.testRef == 0xFF) {
if (SpongebobDepthInverseConditions(stencilState)) {
key.blendEnable = true;
key.blendOpAlpha = VK_BLEND_OP_ADD;
key.blendOpColor = VK_BLEND_OP_ADD;