Skip to content

Commit

Permalink
Experiment: Use glBlendFuncSeparate to not change dest alpha when ble…
Browse files Browse the repository at this point in the history
…nding.

Fixes Persona blending issues.
  • Loading branch information
hrydgard committed Aug 22, 2013
1 parent cbb7f02 commit 416f0c5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions GPU/GLES/FragmentShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void ComputeFragmentShaderID(FragmentShaderID *id) {
id->d[0] |= gstate.getTextureFunction() << 2;
id->d[0] |= (doTextureAlpha & 1) << 5; // rgb or rgba
}

id->d[0] |= (lmode & 1) << 7;
id->d[0] |= gstate.isAlphaTestEnabled() << 8;
if (enableAlphaTest)
Expand Down
8 changes: 7 additions & 1 deletion GPU/GLES/StateMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
}

// At this point, through all paths above, glBlendFuncA and glBlendFuncB will be set right somehow.
glstate.blendFunc.set(glBlendFuncA, glBlendFuncB);
#if 1
// Fixes some Persona 2 issues, may be correct? (that is, don't change dest alpha at all if blending)
// If this doesn't break anything else, it's likely to be right.
glstate.blendFuncSeparate.set(glBlendFuncA, glBlendFuncB, GL_ZERO, GL_ONE);
#else
glstate.blendFuncSeparate.set(glBlendFuncA, glBlendFuncB, glBlendFuncA, glBlendFuncB);
#endif
glstate.blendEquation.set(eqLookup[blendFuncEq]);
}

Expand Down
28 changes: 22 additions & 6 deletions GPU/GeDisasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,26 @@ void GeDisassembleOp(u32 pc, u32 op, u32 prev, char *buffer) {
"unsupported1",
"unsupported2",
};
const char *blendFactors[] = {
"a",
"1.0 - a",
const char *blendFactorsA[16] = {
"dst",
"1.0 - dst",
"src.a",
"1.0 - src.a",
"dst.a",
"1.0 - dst.a",
"2.0 * src.a",
"1.0 - 2.0 * src.a",
"2.0 * dst.a",
"1.0 - 2.0 * dst.a",
"fixed",
"fixed2",
"fixed3",
"fixed4",
"fixed5",
};
const char *blendFactorsB[16] = {
"src",
"1.0 - src",
"src.a",
"1.0 - src.a",
"dst.a",
Expand All @@ -765,11 +782,10 @@ void GeDisassembleOp(u32 pc, u32 op, u32 prev, char *buffer) {
"fixed3",
"fixed4",
"fixed5",
"fixed6",
};

const char *blendFactorA = blendFactors[(data >> 0) & 0xF];
const char *blendFactorB = blendFactors[(data >> 4) & 0xF];
const char *blendFactorA = blendFactorsA[(data >> 0) & 0xF];
const char *blendFactorB = blendFactorsB[(data >> 4) & 0xF];
const char *blendMode = blendModes[(data >> 8) & 0x7];

if (data & ~0xFF0007FF)
Expand Down
2 changes: 1 addition & 1 deletion UI/UIShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void UIShader_Prepare()
glstate.dither.enable();

glstate.blend.enable();
glstate.blendFunc.set(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glstate.blendFuncSeparate.set(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glstate.blendEquation.set(GL_FUNC_ADD);

glstate.depthWrite.set(GL_TRUE);
Expand Down
2 changes: 1 addition & 1 deletion native

10 comments on commit 416f0c5

@bonquacks
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This not only fixes Persona 1 and 2's issues but resolves the same issue (black boxes around transparencies) in quite a number of other games as well.

Bravo @hrydgard

@unknownbrackets
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so it never blends alpha? That will probably fix a lot of effects. Soft needs it too probably...

-[Unknown]

@hrydgard
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - it never writes the destination alpha channel when blending is enabled. @neobrain :)

@dbz400
Copy link
Contributor

@dbz400 dbz400 commented on 416f0c5 Aug 23, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm will try it out with those games which we previously have blending issues .

@dbz400
Copy link
Contributor

@dbz400 dbz400 commented on 416f0c5 Aug 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far i tested it breaks the shadow of FF CC only .Wondering any condition case we can apply it so persona 2 titel screen and the shadow in FF CC can be fixed together.

@crono3567
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just a casual user of ppsspp and am not knowledgeable about any of this stuff. What exactly am I supposed to do with these codes? Please forgive my ignorance.

@unknownbrackets
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crono3567: what are you trying to do? If you want to have a version of PPSSPP with this change, simply download the latest version off the buildbot. IT's already in there (has been for weeks, actually.)

-[Unknown]

@crono3567
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unknownbrackets I found this page after searching for fixes on google and I just set up an account here to ask these questions. I don't really have any idea what this site is or what buildbot is. Is there some sort of really simplistic guide for idiots I can read to figure out what to do to play Persona properly?

@unknownbrackets
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Here are the steps to get a recent build:

  1. http://ppsspp.org/downloads.html#devbuilds
  2. Download the latest one under "Windows 32bit" (64bit or Android is fine too.)
  3. Enjoy.

Well, I'm not sure that Persona plays completely perfect but this issue is fixed anyway.

-[Unknown]

@crono3567
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unknownbrackets Thank you so much!

Please sign in to comment.