mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-21 09:21:02 +00:00
Bring back the depth range hack.
This commit is contained in:
parent
f1c06d25ea
commit
0e85225e29
@ -47,6 +47,7 @@ void Compatibility::Clear() {
|
||||
void Compatibility::CheckSettings(IniFile &iniFile, const std::string &gameID) {
|
||||
CheckSetting(iniFile, gameID, "VertexDepthRounding", flags_.VertexDepthRounding);
|
||||
CheckSetting(iniFile, gameID, "PixelDepthRounding", flags_.PixelDepthRounding);
|
||||
CheckSetting(iniFile, gameID, "DepthRangeHack", flags_.DepthRangeHack);
|
||||
}
|
||||
|
||||
void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, bool &flag) {
|
||||
|
@ -47,6 +47,7 @@
|
||||
struct CompatFlags {
|
||||
bool VertexDepthRounding;
|
||||
bool PixelDepthRounding;
|
||||
bool DepthRangeHack;
|
||||
};
|
||||
|
||||
class IniFile;
|
||||
|
@ -586,6 +586,11 @@ void GLES_GPU::CheckGPUFeatures() {
|
||||
}
|
||||
}
|
||||
|
||||
// The Phantasy Star hack :(
|
||||
if (PSP_CoreParameter().compat.flags().DepthRangeHack && (features & GPU_SUPPORTS_ACCURATE_DEPTH) == 0) {
|
||||
features |= GPU_USE_DEPTH_RANGE_HACK;
|
||||
}
|
||||
|
||||
#ifdef MOBILE_DEVICE
|
||||
// Arguably, we should turn off GPU_IS_MOBILE on like modern Tegras, etc.
|
||||
features |= GPU_IS_MOBILE;
|
||||
|
@ -437,6 +437,38 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid) {
|
||||
flippedMatrix[12] = -flippedMatrix[12];
|
||||
}
|
||||
|
||||
// In Phantasy Star Portable 2, depth range sometimes goes negative and is clamped by glDepthRange to 0,
|
||||
// causing graphics clipping glitch (issue #1788). This hack modifies the projection matrix to work around it.
|
||||
if (gstate_c.Supports(GPU_USE_DEPTH_RANGE_HACK)) {
|
||||
float zScale = gstate.getViewportZScale() / 65535.0f;
|
||||
float zCenter = gstate.getViewportZCenter() / 65535.0f;
|
||||
|
||||
// if far depth range < 0
|
||||
if (zCenter + zScale < 0.0f) {
|
||||
// if perspective projection
|
||||
if (flippedMatrix[11] < 0.0f) {
|
||||
float depthMax = gstate.getDepthRangeMax() / 65535.0f;
|
||||
float depthMin = gstate.getDepthRangeMin() / 65535.0f;
|
||||
|
||||
float a = flippedMatrix[10];
|
||||
float b = flippedMatrix[14];
|
||||
|
||||
float n = b / (a - 1.0f);
|
||||
float f = b / (a + 1.0f);
|
||||
|
||||
f = (n * f) / (n + ((zCenter + zScale) * (n - f) / (depthMax - depthMin)));
|
||||
|
||||
a = (n + f) / (n - f);
|
||||
b = (2.0f * n * f) / (n - f);
|
||||
|
||||
if (!my_isnan(a) && !my_isnan(b)) {
|
||||
flippedMatrix[10] = a;
|
||||
flippedMatrix[14] = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScaleProjMatrix(flippedMatrix);
|
||||
|
||||
glUniformMatrix4fv(u_proj, 1, GL_FALSE, flippedMatrix.m);
|
||||
|
@ -455,6 +455,7 @@ enum {
|
||||
GPU_SUPPORTS_UNPACK_SUBIMAGE = FLAG_BIT(3),
|
||||
GPU_SUPPORTS_BLEND_MINMAX = FLAG_BIT(4),
|
||||
GPU_SUPPORTS_LOGIC_OP = FLAG_BIT(5),
|
||||
GPU_USE_DEPTH_RANGE_HACK = FLAG_BIT(6),
|
||||
GPU_SUPPORTS_ACCURATE_DEPTH = FLAG_BIT(17),
|
||||
GPU_SUPPORTS_VAO = FLAG_BIT(18),
|
||||
GPU_SUPPORTS_ANY_COPY_IMAGE = FLAG_BIT(19),
|
||||
|
@ -87,3 +87,17 @@ NPJH90002 = true
|
||||
# Phantasy Star Portable 2 JP Demo
|
||||
ULJM91018 = true
|
||||
NPJH90062 = true
|
||||
|
||||
[DepthRangeHack]
|
||||
# Phantasy Star Portable 2 and Infinity both use viewport depth outside [0, 1].
|
||||
# This gets clamped in our current implementation, but attempts to fix it run into
|
||||
# Other bugs, so we've restored this hack for now.
|
||||
ULJM05493 = true
|
||||
NPJH50043 = true
|
||||
ULJM08030 = true
|
||||
ULES01439 = true
|
||||
ULUS10529 = true
|
||||
ULJM91018 = true # Infinity demo disc?
|
||||
NPJH90157 = true # Infinity demo
|
||||
ULJM05732 = true
|
||||
NPJH50332 = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user