Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and further improve line drawing in Echochrome #15583

Merged
merged 5 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ asciifont_atlas.zim.png
ppge_atlas.zim.png
local.properties
r.sh
Windows/compileData*

# For vim
*.swp
Expand Down Expand Up @@ -124,4 +125,4 @@ debian/ppsspp/
CMakeFiles

# Clangd
.cache/
.cache/
2 changes: 2 additions & 0 deletions Common/TimeUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Core/Compatibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions Core/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct CompatFlags {
bool DisableRangeCulling;
bool MpegAvcWarmUp;
bool BlueToAlpha;
bool CenteredLines;
};

class IniFile;
Expand Down
150 changes: 99 additions & 51 deletions GPU/Common/SoftwareTransformCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

// 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;
if (PSP_CoreParameter().compat.flags().CenteredLines) {
// Lines meant to be pretty in 3D like in Echochrome.

// We expand them in both directions for symmetry, so we need to halve the expansion.
dx *= 0.5f;
dy *= 0.5f;

for (int i = 0; i < vertexCount; i += 2) {
const TransformedVertex &transVtx1 = transformed[indsIn[i + 0]];
const TransformedVertex &transVtx2 = transformed[indsIn[i + 1]];

// Okay, let's calculate the perpendicular.
float horizontal = transVtx2.x - transVtx1.x;
float vertical = transVtx2.y - transVtx1.y;
Vec2f addWidth = Vec2f(-vertical, horizontal).Normalized();

float xoff = addWidth.x * dx;
float yoff = addWidth.y * dy;

// 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);

// 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.

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;
}

Expand Down
7 changes: 7 additions & 0 deletions GPU/GPUCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions GPU/Math3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions assets/compat.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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