Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
18489da
Moved transformation functions to util
PringlesGang Apr 26, 2025
ad2d530
Added ScrWorkAngleToRad function to util
PringlesGang Apr 26, 2025
8705e53
Moved renderer Quad methods to static base renderer methods
PringlesGang Apr 26, 2025
250accc
Added transformation DrawSprite methods to renderer
PringlesGang Apr 26, 2025
cefbc63
Changed Background2D to use quaternions
PringlesGang Apr 26, 2025
535c605
Fix rendering issues
PringlesGang Apr 26, 2025
fef6ee0
Fixed quad orientation
PringlesGang Apr 27, 2025
9cd2ddf
Added TODO notes
PringlesGang Apr 27, 2025
2baebc4
Added Transformation2D function
PringlesGang Apr 27, 2025
0e04d15
Added AxisAnglesToQuaternion function
PringlesGang Apr 27, 2025
c3bf795
Refactored out DrawSpriteOffset
PringlesGang Apr 27, 2025
71b5a04
Refactored out DrawMaskedSprite overload
PringlesGang Apr 27, 2025
7711e81
Removed DrawMaskedSpriteOffset
PringlesGang Apr 27, 2025
bbcbd54
Refactored out DrawSprite3DRotated
PringlesGang Apr 27, 2025
48cd1c9
Removed superfluous angle parameter from DrawSprite
PringlesGang Apr 27, 2025
cd594e3
Refactored out DrawRect
PringlesGang Apr 27, 2025
05b53c9
Refactored out DrawRect3DRotated
PringlesGang Apr 27, 2025
d006f98
Properly mark overridden methods
PringlesGang Apr 28, 2025
b7ff252
Changed pure virtual DrawMaskedSpriteOverlay to be more generic
PringlesGang Apr 28, 2025
6f8aabe
Changed pure virtual DrawCharacterMvl to be more generic
PringlesGang Apr 28, 2025
9ced0e9
Changed DrawRect into more generic DrawQuad
PringlesGang Apr 28, 2025
b9d2069
Changed pure virtual DrawVideoTexture to be more generic
PringlesGang Apr 28, 2025
e5a56ff
Changed some arrays to spans
PringlesGang Apr 28, 2025
fb0e878
Removed superfluous angle parameter from QuadSetUV
PringlesGang Apr 28, 2025
5bac30b
Removed superfluous transformed QuadSetUV methods
PringlesGang Apr 28, 2025
1921194
Improved QuadSet function definitions
PringlesGang Apr 28, 2025
a4cfe40
Implemented DrawMaskedSprite for DirectX9 and Vulkan
PringlesGang Apr 28, 2025
8455f08
Moved ScrWorkAnglesToQuaternion to inline header
PringlesGang Apr 30, 2025
8a1c899
Added monadic transformation methods to CornersQuad and RectF
PringlesGang Apr 30, 2025
24817e1
Fixed ScrWork variable order in files
PringlesGang May 1, 2025
6676729
Added position overloads to renderer
PringlesGang May 1, 2025
d43efd4
Changed DrawVideoTexture to take a RectF instead of CornersQuad
PringlesGang May 1, 2025
756d820
Improved sprite rendering tint API
PringlesGang May 3, 2025
a03459b
Disabled Vulkan face culling
PringlesGang May 3, 2025
04bc7ba
Made DesignToNDC pure virtual
PringlesGang May 3, 2025
6f3acac
Removed superfluous DrawMaskedSprite overload
PringlesGang May 4, 2025
6a00e47
Removed superfluous DrawSprite overload
PringlesGang May 4, 2025
46923ba
Removed superfluous DrawSpriteOffset method
PringlesGang May 4, 2025
73b5029
Removed superfluous DrawMaskedSpriteOverlay overload
PringlesGang May 4, 2025
459f211
Removed superfluous DrawRect method
PringlesGang May 4, 2025
3a73e84
Removed superfluous DrawRect3DRotated method
PringlesGang May 4, 2025
fba916c
Removed superfluous DrawCharacterMvl overload
PringlesGang May 4, 2025
74609ec
Removed another superfluous DrawSprite overload
PringlesGang May 4, 2025
ae4492b
Removed superfluous DrawSprite3DRotated methods
PringlesGang May 4, 2025
c66ae29
Added more transformation utilities
PringlesGang May 5, 2025
53f8cdd
Marked DesignToNDC as overridden
PringlesGang May 6, 2025
f5d20bf
Abstracted DrawCharacterMvl into DrawVertices
PringlesGang May 7, 2025
420d1ae
Added scaling around center overloads
PringlesGang May 7, 2025
19366ba
Removed superfluous vector reserve
PringlesGang May 10, 2025
8c597c5
Renamed cclcc delusion trigger topleft and offset to offset and origin
PringlesGang May 10, 2025
e0c2fff
Explicitly emptied out unused floats in DX9 shader constant array
PringlesGang May 10, 2025
edf1dd3
Re-added flush to DX9 and VK DrawMaskedSprite
PringlesGang May 10, 2025
3692b6a
Fixed DX9 and VK DrawMaskedSprite mask UVs
PringlesGang May 10, 2025
a759996
Replaced maxZ for loop with std::max_element
PringlesGang May 10, 2025
6abce58
Added 2d-scaling 3d-rotation TransformationMatrix overload
PringlesGang May 10, 2025
db86be4
Added MaskedSpriteOverlay overloads for setting the sprite and mask t…
PringlesGang May 10, 2025
a43597f
fixed chlcc delusion trigger mask rotation
PringlesGang May 10, 2025
d7f5124
Added MaskedSprite overloads for setting the sprite and mask transfor…
PringlesGang May 10, 2025
2c7648e
Fixed chlcc titlemenu circle rendering
PringlesGang May 10, 2025
6a6abf1
Changed 2d TransformationMatrix with 3d rotation method to take in 2d…
PringlesGang May 12, 2025
a3893fe
Moved vertex transformation to vertex shader
PringlesGang May 14, 2025
b95a416
Updated DrawProcessedText to issue only one draw call
PringlesGang May 19, 2025
56c125e
Reduced cclcc system menu background rendering to single quad
PringlesGang May 22, 2025
ada6fa0
More optimized transformation generation
PringlesGang Jun 5, 2025
e6212ec
Severe rewrite of shader logic
PringlesGang Jun 3, 2025
c2db354
Overhauled vertex and index buffers
PringlesGang Jun 6, 2025
7add5c2
Batched textures
PringlesGang Jun 6, 2025
2f7b99b
Added masked DrawVertices support
PringlesGang Jun 9, 2025
a615aa1
Added cache check to opengl scissor state
PringlesGang Jun 9, 2025
e88cfaf
Fix YUV frames
PringlesGang Jun 9, 2025
b235d23
Turned texture units into managed objects
PringlesGang Jun 10, 2025
6dbd9c0
Fix disable blending option
PringlesGang Jun 10, 2025
16885a5
Fix basic font rendering
PringlesGang Jun 10, 2025
7575cfb
Fix chlcc menu background
PringlesGang Jun 10, 2025
60b7313
Fixed MaskedSpriteShader's IsSameTexture uniform not being updated
PringlesGang Jun 10, 2025
0a9662c
'Fixed' DX9 and VK
PringlesGang Jun 11, 2025
44c14ff
Change vertex/index buffers to use vectors instead of arrays
PringlesGang Jun 11, 2025
7486955
Added override for cclcc system menu
PringlesGang Jun 11, 2025
6d18e54
Fix OpenGL DrawMaskedSpriteOverlay mask UVs
PringlesGang Jun 11, 2025
d817132
Altered pointer use
PringlesGang Jun 12, 2025
b45a557
Changed some initializations to brace initializations
PringlesGang Jun 12, 2025
cb19bc0
Removed some resize calls in favor of back_inserter
PringlesGang Jun 12, 2025
7da1885
Added TextureUnit assignment operators
PringlesGang Jun 12, 2025
f0dfb67
Changed DrawVertices to take in a nullable Sprite* for the mask
PringlesGang Jun 12, 2025
9ae2016
Turn sampler2D[] back into sampler2D uniforms
PringlesGang Jun 15, 2025
6db5d11
Fix scrollbar not rendering track when it doesn't have one
PringlesGang Jun 19, 2025
a43da76
Added masked DrawVertices support for Vulkan
PringlesGang Jun 22, 2025
27e9e62
Added masked DrawVertices support for DirectX9
PringlesGang Jun 22, 2025
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
6 changes: 5 additions & 1 deletion profiles/common/scriptvars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ root.ScriptVars = {
SW_MASK3ALPHA_OFS=2788,
SW_BGEFF1_OFSX=2800,
SW_BGEFF1_OFSY=2801,
SW_BGEFF1_ALPHA_OFS=2806,
SW_BGEFF1_SIZE_OFS=2802,
SW_BGEFF1_ROTX_OFS=2803,
SW_BGEFF1_ROTY_OFS=2804,
SW_BGEFF1_ROTZ_OFS=2805,
SW_BGEFF1_ALPHA_OFS=2806,
SW_BGEFF1_MASK_VERTEX1_OFSX=2809,
SW_BGEFF1_MASK_VERTEX1_OFSY=2810,
SW_MAINTHDP=3304,
Expand Down Expand Up @@ -347,6 +349,8 @@ root.ScriptVars = {
SW_BGEFF1_MASK_TYPE=6612,
SW_BGEFF1_FADECT=6613,
SW_BGEFF1_MODE=6614,
SW_BGEFF1_ROTX=6615,
SW_BGEFF1_ROTY=6616,
SW_BGEFF1_ROTZ=6617,
SW_BGEFF1_ALPHA=6618,
SW_BGEFF1_MASKNO=6619,
Expand Down
60 changes: 36 additions & 24 deletions src/background2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,13 @@ void Background2D::RenderBgEff(int bgId, int layer) {
FadeCount = ScrWork[SW_BGEFF1_FADECT + structOffset];
FadeRange = ScrWork[SW_BGEFF1_MASKFADERANGE + structOffset];

Angle = (ScrWork[SW_BGEFF1_ROTZ + structOffset] +
ScrWork[SW_BGEFF1_ROTZ_OFS + structOfsOffset]) *
(float)(2.0f * M_PI / (float)(1 << 16));
Rotation = ScrWorkAnglesToQuaternion(
ScrWork[SW_BGEFF1_ROTX + structOffset] +
ScrWork[SW_BGEFF1_ROTX_OFS + structOfsOffset],
ScrWork[SW_BGEFF1_ROTY + structOffset] +
ScrWork[SW_BGEFF1_ROTY_OFS + structOfsOffset],
ScrWork[SW_BGEFF1_ROTZ + structOffset] +
ScrWork[SW_BGEFF1_ROTZ_OFS + structOfsOffset]);

Scale = glm::vec2((ScrWork[SW_BGEFF1_SIZE + structOffset] +
ScrWork[SW_BGEFF1_SIZE_OFS + structOfsOffset]) /
Expand Down Expand Up @@ -222,6 +226,14 @@ void Background2D::RenderBgEff(int bgId, int layer) {
Origin = {0.0f, 0.0f};
for (const glm::vec2 vertex : vertices) Origin += vertex / (float)vertexCount;

// Transform vertices
const glm::mat4 transformation = TransformationMatrix(
Comment thread
KKhanhH marked this conversation as resolved.
Origin, Scale, {Origin, 0.0f}, Rotation, DisplayCoords);
std::transform(vertices.begin(), vertices.end(), vertices.begin(),
[transformation](const glm::vec2 vertex) {
return transformation * glm::vec4(vertex, 0.0f, 1.0f);
});

// Draw
if (maskType == 0) { // Rectangle
const glm::vec2 maskDimensions = vertices[3] - vertices[0];
Expand All @@ -241,43 +253,43 @@ void Background2D::RenderBgEff(int bgId, int layer) {
}

void Background2D::RenderRegular() {
Renderer->DrawSpriteOffset(BgSprite, DisplayCoords, Origin, Tint, Scale,
Angle, false);
const glm::mat4 transformation = TransformationMatrix(
Origin, Scale, {Origin, 0.0f}, Rotation, DisplayCoords);
Renderer->DrawSprite(BgSprite, transformation, Tint, false);

for (int i = 0; i < MaxLinkedBgBuffers; i++) {
if (Links[i].Direction != LD_Off && Links[i].LinkedBuffer != NULL) {
Renderer->DrawSpriteOffset(Links[i].LinkedBuffer->BgSprite,
Links[i].DisplayCoords, Origin, Tint, Scale,
Angle, false);
const glm::mat4 linkTransformation =
transformation *
glm::translate(glm::mat4(1.0f), {Links[i].DisplayCoords, 0.0f});

Renderer->DrawSprite(Links[i].LinkedBuffer->BgSprite, transformation,
Tint, false);
}
}
}

void Background2D::RenderMasked() {
Renderer->DrawMaskedSpriteOffset(BgSprite, Masks2D[MaskNumber].MaskSprite,
DisplayCoords, Origin, FadeCount, FadeRange,
Tint, Scale, Angle, false, false, false);
const glm::mat4 transformation = TransformationMatrix(
Origin, Scale, {Origin, 0.0f}, Rotation, DisplayCoords);

Renderer->DrawMaskedSprite(BgSprite, Masks2D[MaskNumber].MaskSprite,
FadeCount, FadeRange, transformation, Tint, false,
false);
}

void Background2D::RenderMaskedInverted() {
Renderer->DrawMaskedSpriteOffset(BgSprite, Masks2D[MaskNumber].MaskSprite,
DisplayCoords, Origin, FadeCount, FadeRange,
Tint, Scale, Angle, false, true, false);
const glm::mat4 transformation = TransformationMatrix(
Origin, Scale, {Origin, 0.0f}, Rotation, DisplayCoords);
Renderer->DrawMaskedSprite(BgSprite, Masks2D[MaskNumber].MaskSprite,
FadeCount, FadeRange, transformation, Tint, true,
false);
}

void Background2D::RenderFade() {
Tint.a *= FadeCount / 256.0f;

Renderer->DrawSpriteOffset(BgSprite, DisplayCoords, Origin, Tint, Scale,
Angle, false);

for (int i = 0; i < MaxLinkedBgBuffers; i++) {
if (Links[i].Direction != LD_Off && Links[i].LinkedBuffer != NULL) {
Renderer->DrawSpriteOffset(Links[i].LinkedBuffer->BgSprite,
Links[i].DisplayCoords, Origin, Tint, Scale,
Angle, false);
}
}
RenderRegular();
}

} // namespace Impacto
2 changes: 1 addition & 1 deletion src/background2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Background2D : public Loadable<Background2D> {
glm::vec2 DisplayCoords;
glm::vec2 Origin = {0.0f, 0.0f};
glm::vec2 Scale = {1.0f, 1.0f};
float Angle = 0.0f;
glm::quat Rotation = glm::quat();
glm::vec4 Tint = glm::vec4(1.0f);
int MaskNumber;

Expand Down
33 changes: 21 additions & 12 deletions src/character2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool Character2D::LoadSync(uint32_t charaId) {
// Skip to state data
stream->Seek(0x68, SEEK_CUR);

MvlVerticesCount = Io::ReadLE<int>(stream);
int vertexCount = Io::ReadLE<int>(stream);
int vertexOffset = Io::ReadLE<int>(stream);

for (int i = 0; i < stateCount; i++) {
Expand Down Expand Up @@ -79,8 +79,18 @@ bool Character2D::LoadSync(uint32_t charaId) {
// They seem to use the whole vertex array in all states, so... read it once
// and forget about it?
stream->Seek(vertexOffset, SEEK_SET);
MvlVertices.resize(MvlVerticesCount * 5);
Io::ReadArrayLE<float>(MvlVertices.data(), stream, MvlVerticesCount * 5);
std::vector<float> mvlVertexInfo(vertexCount * 5);
Io::ReadArrayLE<float>(mvlVertexInfo.data(), stream, vertexCount * 5);

MvlVertices.resize(vertexCount);
for (size_t i = 0; i < vertexCount; i++) {
MvlVertices[i] = VertexBufferSprites{
.Position = {mvlVertexInfo[i * 5], mvlVertexInfo[i * 5 + 1]},
.UV = glm::vec2(mvlVertexInfo[i * 5 + 3], mvlVertexInfo[i * 5 + 4]),
.Tint = Tint,
};
}

delete stream;
} else {
// LAY format
Expand Down Expand Up @@ -146,7 +156,7 @@ void Character2D::UnloadSync() {
Show = false;
std::fill(Layers.begin(), Layers.end(), -1);
MvlVertices.clear();
MvlIndicesCount = 0;
MvlIndices.clear();
States.clear();
StatesToDraw.clear();
}
Expand All @@ -165,7 +175,7 @@ void Character2D::MainThreadOnLoad() {

void Character2D::Update(float dt) {
if (Profile::CharaIsMvl) {
MvlIndicesCount = 0;
MvlIndices.clear();
StatesToDraw.clear();
StatesToDraw.push_back((Face & 0xFFFF0000) >> 16); // face
StatesToDraw.push_back(0x40000000 | ((Face & 0xFFFF0000) >> 8) |
Expand All @@ -178,9 +188,8 @@ void Character2D::Update(float dt) {
Character2DState const& state = stateItr->second;
auto& stateIndices =
std::get_if<Character2DState::MVLData>(&state.Data)->Indices;
std::copy(stateIndices.get(), stateIndices.get() + state.Count,
MvlIndices.begin() + MvlIndicesCount);
MvlIndicesCount += state.Count;
MvlIndices.insert(MvlIndices.end(), stateIndices.get(),
stateIndices.get() + state.Count);
}
}
} else {
Expand All @@ -202,10 +211,10 @@ void Character2D::Render(int layer) {
if (Status != LS_Loaded || !OnLayer(layer) || !Show) return;

if (Profile::CharaIsMvl) {
Renderer->DrawCharacterMvl(CharaSprite, glm::vec2(OffsetX, OffsetY),
MvlVerticesCount, MvlVertices.data(),
MvlIndicesCount, MvlIndices.data(), false, Tint,
glm::vec2(ScaleX, ScaleY));
const glm::mat4 transformation = TransformationMatrix(
{0.0f, 0.0f}, {ScaleX, ScaleY}, {0.0f, 0.0f}, 0.0f, {OffsetX, OffsetY});
Renderer->DrawVertices(CharaSpriteSheet, MvlVertices, MvlIndices,
transformation);
} else {
for (auto id : StatesToDraw) {
if (auto stateItr = States.find(id); stateItr != States.end()) {
Expand Down
8 changes: 2 additions & 6 deletions src/character2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ struct Character2DState {
}
};

int constexpr MaxMvlIndices = 128 * 1024;

class Character2D : public Loadable<Character2D> {
friend class Loadable<Character2D>;

Expand Down Expand Up @@ -86,10 +84,8 @@ class Character2D : public Loadable<Character2D> {
ankerl::unordered_dense::map<int, Character2DState> States;
std::vector<int> StatesToDraw;

int MvlVerticesCount;
std::vector<float> MvlVertices;
std::array<uint16_t, MaxMvlIndices> MvlIndices;
int MvlIndicesCount;
std::vector<VertexBufferSprites> MvlVertices;
std::vector<uint16_t> MvlIndices;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Have you tested if there's any perf hit to using vector instead of array here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There is, going from ~200fps to ~80fps in debug mode with three characters on screen, but frankly we should be doing these transformations in the vertex shader anyway...
Lemme know if I should look into that in this PR already or if this can wait until the full-scale refactor

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should leave it as an array for now then and move the transformation into the vertex shader later

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh wait I think I misunderstood your comment. I think most of the performance hit came from the matrix multiplication; I doubt the switch to vector really did anything noticable. Could profile a little more closely later

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah okay, you should also probably do profiling in optimized build, matrix multiplication will probably be a lot faster there. There's also probably some SIMD that gets done by default too

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah okay, I did some more profiling and it looks to me like the vectorization doesn't really seem to be an impact at all (as in, the loading of the vertices is so fast visual studio can't even process anything meaningful).

I've also checked the matrix multiplications in in release mode, and the fps in the cclcc system menu (which thus far is the worst case scenario I could find) goes from ~800fps on master down to ~340fps, which is a perf hit, but it's still 340fps, and again should be moved to the vertex shader anyway

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah we should just move it to the vertex shader. I'd like to see what the numbers are on a worse device like a steam deck though, I assume your computer is probably pretty beefy, so if the perf is a 60% hit on a crappy device it might be a lot worse

};

int constexpr MaxCharacters2D = 16;
Expand Down
4 changes: 2 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ static void RenderMain() {
}
glm::vec4 col = ScrWorkGetColor(SW_MASK1COLOR);
col.a = glm::min(maskAlpha / 255.0f, 1.0f);
Renderer->DrawRect(RectF(maskPosX, maskPosY, maskSizeX, maskSizeY),
Renderer->DrawQuad(RectF(maskPosX, maskPosY, maskSizeX, maskSizeY),
col);
}
}
Expand Down Expand Up @@ -522,7 +522,7 @@ void Render() {
break;
}
case DrawComponentType::Mask: {
Renderer->DrawRect(
Renderer->DrawQuad(
RectF(0.0f, 0.0f, Profile::DesignWidth, Profile::DesignHeight),
glm::vec4(0.0f, 0.0f, 0.0f, (ScrWork[SW_RESTARTMASK] / 256.0f)));
break;
Expand Down
2 changes: 1 addition & 1 deletion src/games/cc/dialoguebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void DialogueBox::Render(DialoguePageMode mode, bool hasName, float nameWidth,
}
} else {
glm::vec4 nvlBoxTint(0.0f, 0.0f, 0.0f, opacity * NVLBoxMaxOpacity);
Renderer->DrawRect(RectF(0, 0, Profile::DesignWidth, Profile::DesignHeight),
Renderer->DrawQuad(RectF(0, 0, Profile::DesignWidth, Profile::DesignHeight),
nvlBoxTint);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/games/cc/titlemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void TitleMenu::Render() {
OverlaySprite,
RectF(0.0f, 0.0f, Profile::DesignWidth, Profile::DesignHeight));
DrawSmoke(SmokeOpacityNormal);
Renderer->DrawRect(
Renderer->DrawQuad(
RectF(0.0f, 0.0f, Profile::DesignWidth, Profile::DesignHeight),
glm::vec4(1.0f, 1.0f, 1.0f,
1.0f - ScrWork[SW_TITLEDISPCT] / 60.0f));
Expand Down
Loading
Loading