Merge pull request #15583 from hrydgard/echochrome-lines

Fix and further improve line drawing in Echochrome
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2022-06-11 11:39:03 +02:00
commit 59352bd78f
10 files changed
+116 -46

No files matched your search

+2 -1
View File
@@ -97,6 +97,7 @@ asciifont_atlas.zim.png
ppge_atlas.zim.png
local.properties
r.sh
Windows/compileData*
# For vim
*.swp
@@ -124,4 +125,4 @@ debian/ppsspp/
CMakeFiles
# Clangd
.cache/
.cache/
+2
View File
@@ -19,6 +19,8 @@
#endif
#include <ctime>
// TODO: https://github.com/floooh/sokol/blob/9a6237fcdf213e6da48e4f9201f144bcb2dcb46f/sokol_time.h#L229-L248
static double curtime = 0;
#ifdef _WIN32
+1
View File
@@ -80,6 +80,7 @@ void Compatibility::CheckSettings(IniFile &iniFile, const std::string &gameID) {
CheckSetting(iniFile, gameID, "DisableRangeCulling", &flags_.DisableRangeCulling);
CheckSetting(iniFile, gameID, "MpegAvcWarmUp", &flags_.MpegAvcWarmUp);
CheckSetting(iniFile, gameID, "BlueToAlpha", &flags_.BlueToAlpha);
CheckSetting(iniFile, gameID, "CenteredLines", &flags_.CenteredLines);
}
void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, bool *flag) {
+1
View File
@@ -79,6 +79,7 @@ struct CompatFlags {
bool DisableRangeCulling;
bool MpegAvcWarmUp;
bool BlueToAlpha;
bool CenteredLines;
};
class IniFile;
+91 -43
View File
@@ -758,8 +758,8 @@ void SoftwareTransform::ExpandLines(int vertexCount, int &maxIndex, u16 *&inds,
u16 *newInds = inds + vertexCount;
u16 *indsOut = newInds;
float dx = 1.0f * gstate_c.vpWidthScale * (1.0f / gstate.getViewportXScale());
float dy = 1.0f * gstate_c.vpHeightScale * (1.0f / gstate.getViewportYScale());
float dx = 1.0f * gstate_c.vpWidthScale * (1.0f / fabsf(gstate.getViewportXScale()));
float dy = 1.0f * gstate_c.vpHeightScale * (1.0f / fabsf(gstate.getViewportYScale()));
float du = 1.0f / gstate_c.curTextureWidth;
float dv = 1.0f / gstate_c.curTextureHeight;
@@ -769,57 +769,105 @@ void SoftwareTransform::ExpandLines(int vertexCount, int &maxIndex, u16 *&inds,
}
maxIndex = 4 * (vertexCount / 2);
for (int i = 0; i < vertexCount; i += 2) {
const TransformedVertex &transVtx1 = transformed[indsIn[i + 0]];
const TransformedVertex &transVtx2 = transformed[indsIn[i + 1]];
const TransformedVertex &transVtxT = transVtx1.y <= transVtx2.y ? transVtx1 : transVtx2;
const TransformedVertex &transVtxB = transVtx1.y <= transVtx2.y ? transVtx2 : transVtx1;
const TransformedVertex &transVtxL = transVtx1.x <= transVtx2.x ? transVtx1 : transVtx2;
const TransformedVertex &transVtxR = transVtx1.x <= transVtx2.x ? transVtx2 : transVtx1;
if (PSP_CoreParameter().compat.flags().CenteredLines) {
// Lines meant to be pretty in 3D like in Echochrome.
// Sort the points so our perpendicular will bias the right direction.
const TransformedVertex &transVtxTL = transVtxT.y != transVtxB.y || transVtxT.x > transVtxB.x ? transVtxT : transVtxB;
const TransformedVertex &transVtxBL = transVtxT.y != transVtxB.y || transVtxT.x > transVtxB.x ? transVtxB : transVtxT;
// We expand them in both directions for symmetry, so we need to halve the expansion.
dx *= 0.5f;
dy *= 0.5f;
// Okay, let's calculate the perpendicular.
float horizontal = transVtxTL.x - transVtxBL.x;
float vertical = transVtxTL.y - transVtxBL.y;
Vec2f addWidth = Vec2f(-vertical, horizontal).Normalized();
for (int i = 0; i < vertexCount; i += 2) {
const TransformedVertex &transVtx1 = transformed[indsIn[i + 0]];
const TransformedVertex &transVtx2 = transformed[indsIn[i + 1]];
// bottom right
trans[0] = transVtxBL;
trans[0].x += addWidth.x * dx;
trans[0].y += addWidth.y * dy;
trans[0].u += addWidth.x * du;
trans[0].v += addWidth.y * dv;
// Okay, let's calculate the perpendicular.
float horizontal = transVtx2.x - transVtx1.x;
float vertical = transVtx2.y - transVtx1.y;
Vec2f addWidth = Vec2f(-vertical, horizontal).Normalized();
// top right
trans[1] = transVtxTL;
trans[1].x += addWidth.x * dx;
trans[1].y += addWidth.y * dy;
trans[1].u += addWidth.x * du;
trans[1].v += addWidth.y * dv;
float xoff = addWidth.x * dx;
float yoff = addWidth.y * dy;
// top left
trans[2] = transVtxTL;
// bottom right
trans[0].CopyFromWithOffset(transVtx2, xoff, yoff);
// top right
trans[1].CopyFromWithOffset(transVtx1, xoff, yoff);
// top left
trans[2].CopyFromWithOffset(transVtx1, -xoff, -yoff);
// bottom left
trans[3].CopyFromWithOffset(transVtx2, -xoff, -yoff);
// bottom left
trans[3] = transVtxBL;
// Triangle: BR-TR-TL
indsOut[0] = i * 2 + 0;
indsOut[1] = i * 2 + 1;
indsOut[2] = i * 2 + 2;
// Triangle: BL-BR-TL
indsOut[3] = i * 2 + 3;
indsOut[4] = i * 2 + 0;
indsOut[5] = i * 2 + 2;
trans += 4;
indsOut += 6;
// Triangle: BR-TR-TL
indsOut[0] = i * 2 + 0;
indsOut[1] = i * 2 + 1;
indsOut[2] = i * 2 + 2;
// Triangle: BL-BR-TL
indsOut[3] = i * 2 + 3;
indsOut[4] = i * 2 + 0;
indsOut[5] = i * 2 + 2;
trans += 4;
indsOut += 6;
numTrans += 6;
}
} else {
// Lines meant to be as closely compatible with upscaled 2D drawing as possible.
// We use this as default.
numTrans += 6;
for (int i = 0; i < vertexCount; i += 2) {
const TransformedVertex &transVtx1 = transformed[indsIn[i + 0]];
const TransformedVertex &transVtx2 = transformed[indsIn[i + 1]];
const TransformedVertex &transVtxT = transVtx1.y <= transVtx2.y ? transVtx1 : transVtx2;
const TransformedVertex &transVtxB = transVtx1.y <= transVtx2.y ? transVtx2 : transVtx1;
const TransformedVertex &transVtxL = transVtx1.x <= transVtx2.x ? transVtx1 : transVtx2;
const TransformedVertex &transVtxR = transVtx1.x <= transVtx2.x ? transVtx2 : transVtx1;
// Sort the points so our perpendicular will bias the right direction.
const TransformedVertex &transVtxTL = (transVtxT.y != transVtxB.y || transVtxT.x > transVtxB.x) ? transVtxT : transVtxB;
const TransformedVertex &transVtxBL = (transVtxT.y != transVtxB.y || transVtxT.x > transVtxB.x) ? transVtxB : transVtxT;
// Okay, let's calculate the perpendicular.
float horizontal = transVtxTL.x - transVtxBL.x;
float vertical = transVtxTL.y - transVtxBL.y;
Vec2f addWidth = Vec2f(-vertical, horizontal).Normalized();
// bottom right
trans[0] = transVtxBL;
trans[0].x += addWidth.x * dx;
trans[0].y += addWidth.y * dy;
trans[0].u += addWidth.x * du;
trans[0].v += addWidth.y * dv;
// top right
trans[1] = transVtxTL;
trans[1].x += addWidth.x * dx;
trans[1].y += addWidth.y * dy;
trans[1].u += addWidth.x * du;
trans[1].v += addWidth.y * dv;
// top left
trans[2] = transVtxTL;
// bottom left
trans[3] = transVtxBL;
// Triangle: BR-TR-TL
indsOut[0] = i * 2 + 0;
indsOut[1] = i * 2 + 1;
indsOut[2] = i * 2 + 2;
// Triangle: BL-BR-TL
indsOut[3] = i * 2 + 3;
indsOut[4] = i * 2 + 0;
indsOut[5] = i * 2 + 2;
trans += 4;
indsOut += 6;
numTrans += 6;
}
}
inds = newInds;
}
+7
View File
@@ -57,6 +57,13 @@ struct TransformedVertex {
u8 color1[4]; // prelit
u32 color1_32;
};
void CopyFromWithOffset(const TransformedVertex &other, float xoff, float yoff) {
this->x = other.x + xoff;
this->y = other.y + yoff;
memcpy(&this->z, &other.z, sizeof(*this) - sizeof(float) * 2);
}
};
class GPUCommon : public GPUInterface, public GPUDebugInterface {
+1
View File
@@ -23,6 +23,7 @@ namespace Math3D {
template<>
float Vec2<float>::Length() const
{
// Doubt this is worth it for a vec2 :/
#if defined(_M_SSE)
float ret;
__m128 xy = _mm_loadu_ps(&x);
+9
View File
@@ -1110,3 +1110,12 @@ ULUS10107 = true
ULJM05101 = true
ULES00724 = true
ULJM05320 = true
[CenteredLines]
# Echochrome looks better with these. Related: #15556
UCES01011 = true
UCAS40197 = true
NPEG00006 = true
NPUG80135 = true
UCES
+1 -1
View File
@@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.android.tools.build:gradle:7.2.1'
}
}
+1 -1
View File
@@ -3,6 +3,6 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
android.useAndroidX=true
android.enableJetifier=true