diff --git a/Source/Contents/Actors/GraffiSkill.cpp b/Source/Contents/Actors/GraffiSkill.cpp index b6e52e23..f8584f80 100644 --- a/Source/Contents/Actors/GraffiSkill.cpp +++ b/Source/Contents/Actors/GraffiSkill.cpp @@ -4,7 +4,6 @@ #include "Client/Mode/ModeMgr.h" #include "Contents/Actors/Pc.h" #include "Contents/Ground/GroundGeometry.h" -#include "Contents/Ground/GroundRendering.h" #include "Contents/World/World.h" #include "Render/Primitives/RenderQueues.h" #include "Render/Projection/RenderProjection.h" @@ -114,12 +113,6 @@ void CGraffiSkill::Render(int argument) { const float sine = static_cast(std::sin(static_cast(this->m_angle / 180.0f * 3.141592f))); const float cosine = static_cast(std::cos(static_cast(this->m_angle / 180.0f * 3.141592f))); - const RenderProjection projection = g_renderer->viewport.Projection(); - const bool depthAlpha = g_renderer->fog.supported != 0; - GroundRenderContext context{ - projection, g_renderer->primitives, g_renderer->queues, g_renderer->viewport.width, g_renderer->viewport.height, g_renderer->frame, depthAlpha, - g_depthStart, g_depthEnd - }; for (int row = 0; row < 18; ++row) { for (int column = 0; column < 18; ++column) { @@ -137,8 +130,7 @@ void CGraffiSkill::Render(int argument) { uv[6] = 1.0f - (row1 * sine + column1 * cosine + 9.0f) / 18.0f; uv[7] = (row1 * cosine - column1 * sine + 9.0f) / 18.0f; ground->DrawGridDecal( - *mode->scene->terrain, reinterpret_cast(argument), cellX - 9 + column, cellY - 9 + row, 0xFFFFFFFF, *this->m_canvas, uv, context - ); + *mode->scene->terrain, reinterpret_cast(argument), cellX - 9 + column, cellY - 9 + row, 0xFFFFFFFF, *this->m_canvas, uv); } } } diff --git a/Source/Contents/Actors/GroundScope.cpp b/Source/Contents/Actors/GroundScope.cpp index 5495009a..b1ed9c33 100644 --- a/Source/Contents/Actors/GroundScope.cpp +++ b/Source/Contents/Actors/GroundScope.cpp @@ -4,7 +4,6 @@ #include "Client/Mode/ModeMgr.h" #include "Contents/Configuration/ServiceOptions.h" #include "Contents/Ground/GroundGeometry.h" -#include "Contents/Ground/GroundRendering.h" #include "Contents/Skills/SkillInfo.h" #include "Contents/World/World.h" #include "Render/Primitives/RenderQueues.h" @@ -140,12 +139,6 @@ void CGroundScope::Render(int argument) { const float cosine = static_cast(std::cos(static_cast(this->m_angle))); const std::uint32_t color = (static_cast(sine * 40.0f) << 24) + 0x80FFFFFF; - const RenderProjection projection = g_renderer->viewport.Projection(); - const bool depthAlpha = g_renderer->fog.supported != 0; - GroundRenderContext context{ - projection, g_renderer->primitives, g_renderer->queues, g_renderer->viewport.width, g_renderer->viewport.height, g_renderer->frame, depthAlpha, - g_depthStart, g_depthEnd - }; for (int row = 0; row < this->m_size; ++row) { for (int column = 0; column < this->m_size; ++column) { @@ -179,7 +172,7 @@ void CGroundScope::Render(int argument) { } CTexture* texture = g_texMgr.Load(name, 0, false, true, false); - ground->DrawGridDecal(*mode->scene->terrain, reinterpret_cast(argument), left + column, top + row, tint, *texture, uv, context); + ground->DrawGridDecal(*mode->scene->terrain, reinterpret_cast(argument), left + column, top + row, tint, *texture, uv); } } diff --git a/Source/Contents/Actors/Player.cpp b/Source/Contents/Actors/Player.cpp index e07a5988..6a4eb9d8 100644 --- a/Source/Contents/Actors/Player.cpp +++ b/Source/Contents/Actors/Player.cpp @@ -34,7 +34,6 @@ #include "Contents/SpriteRidingOffset.h" #include "Contents/World/World.h" #include "Contents/Ground/GroundGeometry.h" -#include "Contents/Ground/GroundRendering.h" #include "Contents/Ground/TerrainHeight.h" #include "Contents/MovementRouteInterpolation.h" #include "Contents/NavigationManager.h" @@ -4597,12 +4596,6 @@ void CGrannyPc::RenderShadow(int argument, vector3d lightDirection, bool cached) const float groundSine = std::sin(0.0f); const float groundCosine = std::cos(0.0f); - const RenderProjection projection = g_renderer->viewport.Projection(); - const bool depthAlpha = g_renderer->fog.supported != 0; - GroundRenderContext context{ - projection, g_renderer->primitives, g_renderer->queues, g_renderer->viewport.width, g_renderer->viewport.height, g_renderer->frame, depthAlpha, - g_depthStart, g_depthEnd - }; for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) { @@ -4620,8 +4613,7 @@ void CGrannyPc::RenderShadow(int argument, vector3d lightDirection, bool cached) uv[6] = (row1 * groundSine + column1 * groundCosine + 2.5f) / 5.0f; uv[7] = (row1 * groundCosine - column1 * groundSine + 2.5f) / 5.0f; ground->DrawGridDecal( - *mode->scene->terrain, reinterpret_cast(argument), column + j, row + i, 0x70FFFFFF, *this->unknown_2554, uv, context - ); + *mode->scene->terrain, reinterpret_cast(argument), column + j, row + i, 0x70FFFFFF, *this->unknown_2554, uv); } } } diff --git a/Source/Contents/Effects/EffectPrimitiveRendering.cpp b/Source/Contents/Effects/EffectPrimitiveRendering.cpp index a72b9d54..d3b569a9 100644 --- a/Source/Contents/Effects/EffectPrimitiveRendering.cpp +++ b/Source/Contents/Effects/EffectPrimitiveRendering.cpp @@ -17,7 +17,6 @@ #include "Contents/Camera/Camera.h" #include "Contents/World/World.h" #include "Contents/Ground/GroundGeometry.h" -#include "Contents/Ground/GroundRendering.h" #include "Render/Textures/TextureCache.h" #include "Contents/MapSkyMgr.h" #include "Client/Replay.h" @@ -6150,12 +6149,6 @@ void CEffectPrim::RenderGrandCross2(matrix& wtm) { // OFFSET: 0x00BD9180 // FUNCTION: fn_19891 void CEffectPrim::RenderMagicTarget(matrix& wtm) { - const RenderProjection projection = g_renderer->viewport.Projection(); - const bool depthAlpha = g_renderer->fog.supported != 0; - GroundRenderContext context{ - projection, g_renderer->primitives, g_renderer->queues, g_renderer->viewport.width, g_renderer->viewport.height, g_renderer->frame, depthAlpha, - g_depthStart, g_depthEnd - }; for (int ec = 0; ec < 4; ++ec) { const EffectPrimitiveSlot& slot = this->state.slots[ec]; @@ -6196,8 +6189,7 @@ void CEffectPrim::RenderMagicTarget(matrix& wtm) { (u01 * scale + 3.5f) / 7.0f, (v01 * scale + 3.5f) / 7.0f, (u11 * scale + 3.5f) / 7.0f, (v11 * scale + 3.5f) / 7.0f, }; ground->DrawGridDecal( - *gameMode->scene->terrain, wtm.values, column + x, row + z, 0xAA9999FF, *g_texMgr.Load("effect\\magic_target.tga", 0, false, true, false), uv, context - ); + *gameMode->scene->terrain, wtm.values, column + x, row + z, 0xAA9999FF, *g_texMgr.Load("effect\\magic_target.tga", 0, false, true, false), uv); scale = slot.maxHeight + 0.1f; uv[0] = (scale * u00 + 3.5f) / 7.0f; @@ -6209,8 +6201,7 @@ void CEffectPrim::RenderMagicTarget(matrix& wtm) { uv[6] = (scale * u11 + 3.5f) / 7.0f; uv[7] = (scale * v11 + 3.5f) / 7.0f; ground->DrawGridDecal( - *gameMode->scene->terrain, wtm.values, column + x, row + z, 0x559999FF, *g_texMgr.Load("effect\\magic_target.tga", 0, false, true, false), uv, context - ); + *gameMode->scene->terrain, wtm.values, column + x, row + z, 0x559999FF, *g_texMgr.Load("effect\\magic_target.tga", 0, false, true, false), uv); } } } diff --git a/Source/Contents/Ground/GroundDecals.cpp b/Source/Contents/Ground/GroundDecals.cpp index 9173e2f6..92bbde12 100644 --- a/Source/Contents/Ground/GroundDecals.cpp +++ b/Source/Contents/Ground/GroundDecals.cpp @@ -3,6 +3,8 @@ #include "Render/Primitives/RenderPrimitivePool.h" #include "Render/Projection/RenderProjection.h" #include "Render/Primitives/RenderQueues.h" +#include "Render/Renderer.h" +#include "Render/TextureQuad.h" #include "Render/Textures/Texture.h" #include "Render/Textures/TextureCache.h" #include "Resource/World/TerrainResource.h" @@ -32,7 +34,7 @@ namespace { // INLINED void DrawDecal( const GroundGeometry& ground, const C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture& texture, const float* uv, - float bias, GroundRenderContext& context + float bias ) { float vertices[4][3]{}; @@ -58,10 +60,10 @@ namespace { } } - RenderPrimitive* primitive = context.primitives.Acquire(); + RenderPrimitive* primitive = g_renderer->primitives.Acquire(); for (unsigned corner = 0; corner < 4; ++corner) { - context.projection.Project(vertices[corner], matrix, primitive->vertices[corner]); + g_renderer->viewport.Projection().Project(vertices[corner], matrix, primitive->vertices[corner]); primitive->vertices[corner].z = primitive->vertices[corner].z - bias; } @@ -77,16 +79,16 @@ namespace { primitive->unknown_0018 = 5; primitive->unknown_001C = 6; primitive->texture = &texture; - context.queues.Submit(primitive, 1, context.depthAlpha, context.depthStart, context.depthEnd); + g_renderer->queues.Submit(primitive, 1, g_renderer->fog.supported != 0, g_depthStart, g_depthEnd); } } // OFFSET: 0x00AC3380 // FUNCTION: fn_17602 void GroundGeometry::DrawCellDecal( - const C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture& texture, const float* uv, GroundRenderContext& context + const C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture& texture, const float* uv ) const { - DrawDecal(*this, terrain, matrix, column, row, color, texture, uv, 0.10003052f, context); + DrawDecal(*this, terrain, matrix, column, row, color, texture, uv, 0.10003052f); } // OFFSET: 0x00AC1710 @@ -97,20 +99,20 @@ void GroundGeometry::Slot14(int, int, int, int) { // OFFSET: 0x00AC1720 // FUNCTION: fn_17589 void GroundGeometry::DrawGridDecal( - const C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture& texture, const float* uv, GroundRenderContext& context + const C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture& texture, const float* uv ) const { - DrawDecal(*this, terrain, matrix, column, row, color, texture, uv, 3.0517578e-05f, context); + DrawDecal(*this, terrain, matrix, column, row, color, texture, uv, 3.0517578e-05f); } // OFFSET: 0x00AC16D0 // FUNCTION: fn_17587 void GroundGeometry::DrawGrid( - const C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, GroundRenderContext& context + const C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color ) const { CTexture* texture = g_texMgr.Load("grid.tga", 0, false, true, false); // STATIC: 0x01347EB0 constexpr float uv[8] = {0, 0, 1, 0, 0, 1, 1, 1}; - this->DrawGridDecal(terrain, matrix, column, row, color, *texture, uv, context); + this->DrawGridDecal(terrain, matrix, column, row, color, *texture, uv); } // OFFSET: 0x00AC3600 @@ -121,7 +123,7 @@ void GroundGeometry::Slot16(int, int, int, int, int, int) { // OFFSET: 0x00AC3610 // FUNCTION: fn_17604 void GroundGeometry::DrawTerrainOverlay( - const C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture* texture, GroundRenderContext& context + const C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture* texture ) const { const auto half = [](int value) { return TruncateToInt(static_cast(value) * 0.5f); }; const int cellColumn = half(column); @@ -150,10 +152,10 @@ void GroundGeometry::DrawTerrainOverlay( const float vertices[4][3] = { {left, cell->heights[0], top}, {right, cell->heights[1], top}, {left, cell->heights[2], bottom}, {right, cell->heights[3], bottom} }; - RenderPrimitive* primitive = context.primitives.Acquire(); + RenderPrimitive* primitive = g_renderer->primitives.Acquire(); for (unsigned corner = 0; corner < 4; ++corner) { - context.projection.Project(vertices[corner], matrix, primitive->vertices[corner]); + g_renderer->viewport.Projection().Project(vertices[corner], matrix, primitive->vertices[corner]); primitive->vertices[corner].u = static_cast(corner & 1); primitive->vertices[corner].v = static_cast(corner >> 1); primitive->vertices[corner].diffuse = color; @@ -162,5 +164,5 @@ void GroundGeometry::DrawTerrainOverlay( primitive->unknown_0018 = 5; primitive->unknown_001C = 6; primitive->texture = texture; - context.queues.Submit(primitive, 1, context.depthAlpha, context.depthStart, context.depthEnd); + g_renderer->queues.Submit(primitive, 1, g_renderer->fog.supported != 0, g_depthStart, g_depthEnd); } diff --git a/Source/Contents/Ground/GroundGeometry.cpp b/Source/Contents/Ground/GroundGeometry.cpp index 5df9780d..242bebee 100644 --- a/Source/Contents/Ground/GroundGeometry.cpp +++ b/Source/Contents/Ground/GroundGeometry.cpp @@ -98,11 +98,6 @@ void GroundGeometry::Reset(int columns, int rows) { void GroundGeometry::Slot01(int, int) { } -// INLINED -GroundSpatial GroundGeometry::Spatial() const { - return {this->width, this->height, this->cellSize, this->cells}; -} - // OFFSET: 0x00ABDEF0 // FUNCTION: fn_17556 void GroundGeometry::Build(CGndRes& resource, const float* lightDirection, const float* diffuse, const float* ambient) { diff --git a/Source/Contents/Ground/GroundGeometry.h b/Source/Contents/Ground/GroundGeometry.h index 439afde1..bbe78a89 100644 --- a/Source/Contents/Ground/GroundGeometry.h +++ b/Source/Contents/Ground/GroundGeometry.h @@ -9,7 +9,6 @@ class CGndRes; class TextureCache; -struct GroundRenderContext; struct GroundLightmap { /* 0000 */ unsigned char color[4]; @@ -27,29 +26,26 @@ public: void Build(CGndRes& resource, const float* lightDirection, const float* diffuse, const float* ambient); void ClearGeometry(); void Reset(int columns, int rows); - GroundSpatial Spatial() const; - void Draw(const float* matrix, const int* rectangle, bool clip, GroundRenderContext& context); + void SpatialCell(float x, float z, int& column, int& row) const; + void HeightBounds(const int* rectangle, float& minimum, float& maximum) const; + void Draw(const float* matrix, const int* rectangle, bool clip); void CellBounds(int column, int row, float& minimum, float& maximum) const; bool OverlayHeights(const class C3dAttr& terrain, float* vertices, int column, int row) const; bool CellVertices(const class C3dAttr& terrain, float* vertices, int column, int row) const; void MarkRay(const float* ray, int column, int row, float limit); bool CellRectangle(const class C3dAttr& terrain, int column, int row, float* vertices) const; void DrawCellDecal( - const class C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture& texture, const float* uv, - GroundRenderContext& context + const class C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture& texture, const float* uv ) const; void DrawGridDecal( - const class C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture& texture, const float* uv, - GroundRenderContext& context + const class C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture& texture, const float* uv ) const; - void DrawGrid( - const class C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, GroundRenderContext& context - ) const; - void DrawTerrainOverlay( - const class C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture* texture, GroundRenderContext& context - ) const; - void DrawWaterCell(int column, int row, GroundCell& cell, const float* matrix, const float* ambient, bool overrideColor, GroundRenderContext& context); - void DrawLit(const float* matrix, const int* rectangle, bool clip, struct GroundLightingContext& context); + void DrawGrid(const class C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color) const; + void DrawTerrainOverlay(const class C3dAttr& terrain, const float* matrix, int column, int row, std::uint32_t color, CTexture* texture) const; + void DrawWaterCell(int column, int row, GroundCell& cell, const float* matrix, const float* ambient); + void DrawLit(const float* matrix, const int* rectangle, bool clip); + __declspec(noinline) void DrawLightmapped(const float* matrix, const struct GroundQuad& quad, bool clip); + __declspec(noinline) void DrawSide(const float* matrix, const struct GroundQuad& quad, bool clip); void WorldColor(float x, float unusedY, float z, std::uint32_t* output) const; void Lighting(int column, int row, float& red, float& green, float& blue) const; void Slot01(int first, int second); diff --git a/Source/Contents/Ground/GroundLighting.cpp b/Source/Contents/Ground/GroundLighting.cpp index c7bb1ac7..de33f455 100644 --- a/Source/Contents/Ground/GroundLighting.cpp +++ b/Source/Contents/Ground/GroundLighting.cpp @@ -1,29 +1,36 @@ #include "Contents/Ground/GroundGeometry.h" #include "Contents/Ground/GroundRendering.h" #include "Contents/Configuration/ServiceOptions.h" +#include "Contents/Effects/EffectPrim.h" #include "Render/Primitives/LightmappedPrimitive.h" #include "Render/Primitives/RenderPrimitivePool.h" #include "Render/Projection/RenderProjection.h" #include "Render/Primitives/RenderQueues.h" +#include "Render/Renderer.h" +#include "Render/TextureQuad.h" +#include "Resource/World/WorldResource.h" #include "Utility/Math/ScalarConversion.h" #include #include +// GLOBAL: gl_24589 +float g_groundColorScale[3]; + // OFFSET: 0x00AC1D30 // FUNCTION: fn_17592 -void DrawLightmappedGround(const float* matrix, const GroundQuad& quad, bool clip, GroundLightingContext& context) { +void GroundGeometry::DrawLightmapped(const float* matrix, const GroundQuad& quad, bool clip) { RenderVertex vertices[4]{}; float lightUV[4][2]; float scales[3]; - std::memcpy(scales, context.colorScale, sizeof(scales)); + std::memcpy(scales, g_groundColorScale, sizeof(scales)); for (unsigned corner = 0; corner < 4; ++corner) { vertices[corner].specular = 0xFF000000u; - context.render.projection.Project(quad.vertices[corner], matrix, vertices[corner]); + g_renderer->viewport.Projection().Project(quad.vertices[corner], matrix, vertices[corner]); } - if (clip && !GroundQuadVisible(vertices, context.render)) { + if (clip && !GroundQuadVisible(vertices)) { return; } @@ -34,7 +41,7 @@ void DrawLightmappedGround(const float* matrix, const GroundQuad& quad, bool cli lightUV[corner][1] = quad.vertices[corner][7]; std::uint32_t color = std::bit_cast(quad.vertices[corner][3]); - if (!context.overrideColor && quad.selected != 0) { + if (!g_overrideColor && quad.selected != 0) { color = (color & 0x00FFFFFFu) | 0x80000000u; } else { for (unsigned channel = 0; channel < 3; ++channel) { @@ -48,10 +55,10 @@ void DrawLightmappedGround(const float* matrix, const GroundQuad& quad, bool cli vertices[corner].diffuse = color; } - const bool enabled = context.options.Get(119) != 0; + const bool enabled = g_serviceOptions.Get(119) != 0; - if (context.multitexture && enabled) { - LightmappedPrimitive* primitive = context.primitives.Acquire(); + if (g_multitexture && enabled) { + LightmappedPrimitive* primitive = g_renderer->lightmapped.Acquire(); for (unsigned corner = 0; corner < 4; ++corner) { std::memcpy(&primitive->vertices[corner], &vertices[corner], sizeof(RenderVertex)); @@ -61,13 +68,13 @@ void DrawLightmappedGround(const float* matrix, const GroundQuad& quad, bool cli primitive->texture = quad.texture; primitive->lightmap = quad.lightmapTexture; - context.render.queues.lightmapped.Submit(primitive, 0, context.render.depthAlpha, context.render.depthStart, context.render.depthEnd); + g_renderer->queues.lightmapped.Submit(primitive, 0, g_renderer->fog.supported != 0, g_depthStart, g_depthEnd); return; } - if (context.options.Get(119) != 0) { - RenderPrimitive* lightmap = context.render.primitives.Acquire(); + if (g_serviceOptions.Get(119) != 0) { + RenderPrimitive* lightmap = g_renderer->primitives.Acquire(); std::memcpy(lightmap->vertices, vertices, sizeof(vertices)); for (unsigned corner = 0; corner < 4; ++corner) { @@ -76,18 +83,20 @@ void DrawLightmappedGround(const float* matrix, const GroundQuad& quad, bool cli } lightmap->texture = quad.lightmapTexture; - context.render.queues.Submit(lightmap, 0x1000, context.render.depthAlpha, context.render.depthStart, context.render.depthEnd); + g_renderer->queues.Submit(lightmap, 0x1000, g_renderer->fog.supported != 0, g_depthStart, g_depthEnd); } - RenderPrimitive* primitive = context.render.primitives.Acquire(); + RenderPrimitive* primitive = g_renderer->primitives.Acquire(); std::memcpy(primitive->vertices, vertices, sizeof(vertices)); primitive->texture = quad.texture; - context.render.queues.Submit(primitive, 0x800, context.render.depthAlpha, context.render.depthStart, context.render.depthEnd); + g_renderer->queues.Submit(primitive, 0x800, g_renderer->fog.supported != 0, g_depthStart, g_depthEnd); } // OFFSET: 0x00AC15A0 // FUNCTION: fn_17585 -void GroundGeometry::DrawLit(const float* matrix, const int* rectangle, bool clip, GroundLightingContext& context) { +void GroundGeometry::DrawLit(const float* matrix, const int* rectangle, bool clip) { + float ambient[3]; + std::memcpy(ambient, g_worldLighting.ambient, sizeof(ambient)); int row = rectangle[1]; while (row <= rectangle[3]) { @@ -97,20 +106,20 @@ void GroundGeometry::DrawLit(const float* matrix, const int* rectangle, bool cli const unsigned index = static_cast(column) + static_cast(row) * static_cast(this->width); GroundCell& cell = this->cells[index]; - if (cell.frame != context.render.frame) { - cell.frame = context.render.frame; + if (cell.frame != g_renderer->frame) { + cell.frame = g_renderer->frame; if (cell.top) { - this->DrawWaterCell(column, row, cell, matrix, context.waterAmbient, context.overrideColor, context.render); - DrawLightmappedGround(matrix, *cell.top, clip, context); + this->DrawWaterCell(column, row, cell, matrix, ambient); + this->DrawLightmapped(matrix, *cell.top, clip); } if (cell.side2) { - DrawLightmappedGround(matrix, *cell.side2, clip, context); + this->DrawLightmapped(matrix, *cell.side2, clip); } if (cell.side1) { - DrawLightmappedGround(matrix, *cell.side1, clip, context); + this->DrawLightmapped(matrix, *cell.side1, clip); } } diff --git a/Source/Contents/Ground/GroundRendering.cpp b/Source/Contents/Ground/GroundRendering.cpp index 723e1ed5..d5073881 100644 --- a/Source/Contents/Ground/GroundRendering.cpp +++ b/Source/Contents/Ground/GroundRendering.cpp @@ -3,6 +3,8 @@ #include "Render/Primitives/RenderPrimitivePool.h" #include "Render/Projection/RenderProjection.h" #include "Render/Primitives/RenderQueues.h" +#include "Render/Renderer.h" +#include "Render/TextureQuad.h" #include #include @@ -24,10 +26,10 @@ namespace { } // INLINED -bool GroundQuadVisible(const RenderVertex* vertices, const GroundRenderContext& context) { +bool GroundQuadVisible(const RenderVertex* vertices) { const float minimumX = Minimum4(vertices[0].x, vertices[1].x, vertices[2].x, vertices[3].x); - if (minimumX >= static_cast(context.width)) { + if (minimumX >= static_cast(g_renderer->viewport.width)) { return false; } @@ -39,7 +41,7 @@ bool GroundQuadVisible(const RenderVertex* vertices, const GroundRenderContext& const float minimumY = Minimum4(vertices[0].y, vertices[1].y, vertices[2].y, vertices[3].y); - if (minimumY >= static_cast(context.height)) { + if (minimumY >= static_cast(g_renderer->viewport.height)) { return false; } @@ -60,15 +62,15 @@ bool GroundQuadVisible(const RenderVertex* vertices, const GroundRenderContext& namespace { // INLINED - void Submit(const float* matrix, const GroundQuad& quad, bool clip, GroundRenderContext& context) { + void Submit(const float* matrix, const GroundQuad& quad, bool clip) { RenderVertex vertices[4]{}; for (unsigned corner = 0; corner < 4; ++corner) { vertices[corner].specular = 0xFF000000u; - context.projection.Project(quad.vertices[corner], matrix, vertices[corner]); + g_renderer->viewport.Projection().Project(quad.vertices[corner], matrix, vertices[corner]); } - if (clip && !GroundQuadVisible(vertices, context)) { + if (clip && !GroundQuadVisible(vertices)) { return; } @@ -78,22 +80,22 @@ namespace { vertices[corner].v = quad.vertices[corner][5]; } - RenderPrimitive* primitive = context.primitives.Acquire(); + RenderPrimitive* primitive = g_renderer->primitives.Acquire(); std::memcpy(primitive->vertices, vertices, sizeof(vertices)); primitive->texture = quad.texture; - context.queues.Submit(primitive, 0x800, context.depthAlpha, context.depthStart, context.depthEnd); + g_renderer->queues.Submit(primitive, 0x800, g_renderer->fog.supported != 0, g_depthStart, g_depthEnd); } } // OFFSET: 0x00AC2530 // FUNCTION: fn_17593 -void DrawGroundSide(const float* matrix, const GroundQuad& quad, bool clip, GroundRenderContext& context) { - Submit(matrix, quad, clip, context); +void GroundGeometry::DrawSide(const float* matrix, const GroundQuad& quad, bool clip) { + Submit(matrix, quad, clip); } // OFFSET: 0x00AC19A0 // FUNCTION: fn_17590 -void GroundGeometry::Draw(const float* matrix, const int* rectangle, bool clip, GroundRenderContext& context) { +void GroundGeometry::Draw(const float* matrix, const int* rectangle, bool clip) { int row = rectangle[1]; while (row <= rectangle[3]) { @@ -103,19 +105,19 @@ void GroundGeometry::Draw(const float* matrix, const int* rectangle, bool clip, const unsigned index = static_cast(column) + static_cast(row) * static_cast(this->width); GroundCell& cell = this->cells[index]; - if (cell.frame != context.frame) { - cell.frame = context.frame; + if (cell.frame != g_renderer->frame) { + cell.frame = g_renderer->frame; if (cell.top) { - Submit(matrix, *cell.top, clip, context); + Submit(matrix, *cell.top, clip); } if (cell.side2) { - DrawGroundSide(matrix, *cell.side2, clip, context); + this->DrawSide(matrix, *cell.side2, clip); } if (cell.side1) { - DrawGroundSide(matrix, *cell.side1, clip, context); + this->DrawSide(matrix, *cell.side1, clip); } } diff --git a/Source/Contents/Ground/GroundRendering.h b/Source/Contents/Ground/GroundRendering.h index 857958b6..910c5553 100644 --- a/Source/Contents/Ground/GroundRendering.h +++ b/Source/Contents/Ground/GroundRendering.h @@ -1,41 +1,8 @@ #ifndef RAGNAROK_SOURCE_CONTENTS_GROUND_GROUNDRENDERING_H #define RAGNAROK_SOURCE_CONTENTS_GROUND_GROUNDRENDERING_H -#include - -struct GroundQuad; -struct RenderProjection; -struct RenderQueues; struct RenderVertex; -class LightmappedPrimitivePool; -struct ServiceOptions; -class RenderPrimitivePool; -struct GroundRenderContext { - const RenderProjection& projection; - RenderPrimitivePool& primitives; - RenderQueues& queues; - const int& width; - const int& height; - const std::uint32_t& frame; - const bool& depthAlpha; - const float& depthStart; - const float& depthEnd; -}; - -struct GroundLightingContext { - GroundRenderContext& render; - LightmappedPrimitivePool& primitives; - const ServiceOptions& options; - const float* colorScale; - const float* waterAmbient; - const bool& overrideColor; - const bool& multitexture; -}; - -bool GroundQuadVisible(const RenderVertex* vertices, const GroundRenderContext& context); -void DrawLightmappedGround(const float* matrix, const GroundQuad& quad, bool clip, GroundLightingContext& context); - -void DrawGroundSide(const float* matrix, const GroundQuad& quad, bool clip, GroundRenderContext& context); +bool GroundQuadVisible(const RenderVertex* vertices); #endif diff --git a/Source/Contents/Ground/GroundSamples.cpp b/Source/Contents/Ground/GroundSamples.cpp index 8cf3f49c..30314aaf 100644 --- a/Source/Contents/Ground/GroundSamples.cpp +++ b/Source/Contents/Ground/GroundSamples.cpp @@ -6,7 +6,7 @@ void GroundGeometry::WorldColor(float x, float, float z, std::uint32_t* output) const { int column; int row; - this->Spatial().SpatialCell(x, z, column, row); + this->SpatialCell(x, z, column, row); if (column < 0 || row < 0 || column >= this->width || row >= this->height) { output[1] = 255; diff --git a/Source/Contents/Ground/GroundSpatial.cpp b/Source/Contents/Ground/GroundSpatial.cpp index f54a6190..51e00337 100644 --- a/Source/Contents/Ground/GroundSpatial.cpp +++ b/Source/Contents/Ground/GroundSpatial.cpp @@ -1,4 +1,4 @@ -#include "Contents/Ground/GroundSpatial.h" +#include "Contents/Ground/GroundGeometry.h" #include "Utility/Math/ScalarConversion.h" #include @@ -20,7 +20,7 @@ GroundCell::GroundCell() : corners{}, top(nullptr), side1(nullptr), side2(nullpt // OFFSET: 0x00AC0180 // FUNCTION: fn_17562 -void GroundSpatial::SpatialCell(float x, float z, int& column, int& row) const { +void GroundGeometry::SpatialCell(float x, float z, int& column, int& row) const { const float first = static_cast(std::floor(static_cast(x / this->cellSize))); column = TruncateToInt(first) + this->width / 2; const float second = static_cast(std::floor(static_cast(z / this->cellSize))); @@ -29,7 +29,7 @@ void GroundSpatial::SpatialCell(float x, float z, int& column, int& row) const { // OFFSET: 0x00AC0EA0 // FUNCTION: fn_17573 -void GroundSpatial::HeightBounds(const int* rectangle, float& minimum, float& maximum) const { +void GroundGeometry::HeightBounds(const int* rectangle, float& minimum, float& maximum) const { if (rectangle[0] < 0 || rectangle[0] >= this->width || rectangle[2] < 0 || rectangle[2] >= this->width || rectangle[1] < 0 || rectangle[1] >= this->height || rectangle[3] < 0 || rectangle[3] >= this->height || rectangle[2] <= rectangle[0] || rectangle[3] <= rectangle[1]) { minimum = 0.0f; diff --git a/Source/Contents/Ground/GroundSpatial.h b/Source/Contents/Ground/GroundSpatial.h index 2e5536e9..9c2dd315 100644 --- a/Source/Contents/Ground/GroundSpatial.h +++ b/Source/Contents/Ground/GroundSpatial.h @@ -34,16 +34,6 @@ struct GroundCell { /* 0053 */ unsigned char unknown_0053; }; -struct GroundSpatial { - const int& width; - const int& height; - const float& cellSize; - const std::vector& cells; - - void SpatialCell(float x, float z, int& column, int& row) const; - void HeightBounds(const int* rectangle, float& minimum, float& maximum) const; -}; - #if defined(_WIN32) && !defined(_WIN64) static_assert(sizeof(GroundQuad) == 156); static_assert(offsetof(GroundQuad, texture) == 0x84); diff --git a/Source/Contents/Ground/GroundWaterRendering.cpp b/Source/Contents/Ground/GroundWaterRendering.cpp index d9f4a29f..d157174e 100644 --- a/Source/Contents/Ground/GroundWaterRendering.cpp +++ b/Source/Contents/Ground/GroundWaterRendering.cpp @@ -3,6 +3,9 @@ #include "Render/Primitives/RenderPrimitivePool.h" #include "Render/Projection/RenderProjection.h" #include "Render/Primitives/RenderQueues.h" +#include "Contents/Effects/EffectPrim.h" +#include "Render/Renderer.h" +#include "Render/TextureQuad.h" #include "Utility/Math/AffineMatrix.h" #include "Utility/Math/ScalarConversion.h" @@ -12,7 +15,7 @@ // OFFSET: 0x00AC2B80 // FUNCTION: fn_17594 void GroundGeometry::DrawWaterCell( - int column, int row, GroundCell& cell, const float* matrix, const float* ambient, bool overrideColor, GroundRenderContext& context + int column, int row, GroundCell& cell, const float* matrix, const float* ambient ) { const float level = this->water.Level(this->width, this->height, column, row); unsigned partition = 0; @@ -61,7 +64,7 @@ void GroundGeometry::DrawWaterCell( for (unsigned corner = 0; corner < 4; ++corner) { vertices[corner].specular = 0xFF000000u; - context.projection.Project(cell.corners[corner], matrix, vertices[corner]); + g_renderer->viewport.Projection().Project(cell.corners[corner], matrix, vertices[corner]); } const float firstArea = (vertices[2].x - vertices[0].x) * (vertices[1].y - vertices[0].y); @@ -71,11 +74,11 @@ void GroundGeometry::DrawWaterCell( return; } - RenderPrimitive* primitive = context.primitives.Acquire(); + RenderPrimitive* primitive = g_renderer->primitives.Acquire(); std::memcpy(primitive->vertices, vertices, sizeof(vertices)); std::uint32_t color = 0x90FFFFFFu; - if (!overrideColor && this->water.type == 4) { + if (!g_overrideColor && this->water.type == 4) { color = 0xFF000000u; for (unsigned channel = 0; channel < 3; ++channel) { @@ -97,5 +100,5 @@ void GroundGeometry::DrawWaterCell( primitive->unknown_0014 = (primitive->unknown_0014 & 0xFF00u) | 1u; primitive->texture = surface.texture; - context.queues.Submit(primitive, 1, context.depthAlpha, context.depthStart, context.depthEnd); + g_renderer->queues.Submit(primitive, 1, g_renderer->fog.supported != 0, g_depthStart, g_depthEnd); } diff --git a/Source/Contents/NavigationRoute.cpp b/Source/Contents/NavigationRoute.cpp index 354deb9a..5904302c 100644 --- a/Source/Contents/NavigationRoute.cpp +++ b/Source/Contents/NavigationRoute.cpp @@ -29,7 +29,6 @@ #include "Client/Mode/CGameMode.h" #include "Client/Mode/ModeMgr.h" #include "Contents/Ground/GroundGeometry.h" -#include "Contents/Ground/GroundRendering.h" #include "Contents/World/World.h" #include "Render/Primitives/RenderQueues.h" #include "Render/Projection/RenderProjection.h" @@ -56,11 +55,6 @@ void CNavigationManager::DrawRoute(const float* matrix) { mode->PlayerCell(&playerX, &playerY); } - const RenderProjection projection = g_renderer->viewport.Projection(); - GroundRenderContext context{ - projection, g_renderer->primitives, g_renderer->queues, g_renderer->viewport.width, g_renderer->viewport.height, g_renderer->frame, - g_renderer->fog.supported != 0, g_depthStart, g_depthEnd - }; int visible = 0; const int maxY = playerY + 10; @@ -93,7 +87,7 @@ void CNavigationManager::DrawRoute(const float* matrix) { GroundGeometry* ground = mode->scene->ground; const std::string name = FormatOwnedString("유저인터페이스\\navigation_interface3\\location%d.tga", g_locationFrame); CTexture* texture = g_texMgr.Load(name.c_str(), 0, false, true, false); - ground->DrawTerrainOverlay(*mode->scene->terrain, matrix, lastX, lastY, color, texture, context); + ground->DrawTerrainOverlay(*mode->scene->terrain, matrix, lastX, lastY, color, texture); } } @@ -111,7 +105,7 @@ void CNavigationManager::DrawRoute(const float* matrix) { CTexture* texture = g_texMgr.Load(this->labels[points[index + 1].metadata].c_str(), 0, false, true, false); constexpr float uv[8] = {0, 0, 1, 0, 0, 1, 1, 1}; const std::uint32_t color = blink == static_cast(index) % 10 ? 0xEEFFFFFF : 0x99FFFFFF; - this->ground->DrawGridDecal(*mode->scene->terrain, matrix, x, y, color, *texture, uv, context); + this->ground->DrawGridDecal(*mode->scene->terrain, matrix, x, y, color, *texture, uv); } } } diff --git a/Source/Contents/World/WorldModelLoading.cpp b/Source/Contents/World/WorldModelLoading.cpp index 2ebe7908..a270ac98 100644 --- a/Source/Contents/World/WorldModelLoading.cpp +++ b/Source/Contents/World/WorldModelLoading.cpp @@ -271,7 +271,7 @@ void CWorld::InitWorld() { } } - InitializeWorldSpatial(this->spatial, reinterpret_cast(*this->ground), *this->terrain, this->models, this->serializedSpatial); + InitializeWorldSpatial(this->spatial, *this->ground, *this->terrain, this->models, this->serializedSpatial); this->LoadMapEffects(); reinterpret_cast(groundVtbl[11])(this->ground); diff --git a/Source/Contents/World/WorldModelView.cpp b/Source/Contents/World/WorldModelView.cpp index a69de56b..50d7d411 100644 --- a/Source/Contents/World/WorldModelView.cpp +++ b/Source/Contents/World/WorldModelView.cpp @@ -133,7 +133,7 @@ int ClassifyModelView(const OrientedBounds& bounds, const ModelViewPlanes& plane // INLINED void DrawWorldModelLeaves( std::list& clipped, std::list& inside, const ModelViewPlanes& planes, const float* matrix, unsigned frame, int updates, - GroundGeometry& ground, ModelRenderContext& models, GroundLightingContext& lighting, int* visibleRectangle + GroundGeometry& ground, ModelRenderContext& models, int* visibleRectangle ) { visibleRectangle[0] = visibleRectangle[1] = 999; visibleRectangle[2] = visibleRectangle[3] = 0; @@ -157,7 +157,7 @@ void DrawWorldModelLeaves( model->renderFrame = frame; } - ground.DrawLit(matrix, node->groundCells, true, lighting); + ground.DrawLit(matrix, node->groundCells, true); IncludeRectangle(node->groundCells, visibleRectangle); } @@ -173,7 +173,7 @@ void DrawWorldModelLeaves( } } - ground.DrawLit(matrix, node->groundCells, false, lighting); + ground.DrawLit(matrix, node->groundCells, false); IncludeRectangle(node->groundCells, visibleRectangle); } } diff --git a/Source/Contents/World/WorldModelView.h b/Source/Contents/World/WorldModelView.h index e418bab1..79fc2700 100644 --- a/Source/Contents/World/WorldModelView.h +++ b/Source/Contents/World/WorldModelView.h @@ -7,7 +7,6 @@ struct OrientedBounds; struct WorldSpatialTree; struct ModelRenderContext; -struct GroundLightingContext; class GroundGeometry; struct ModelViewPlanes { @@ -47,7 +46,7 @@ int ClassifyModelView(const OrientedBounds& bounds, const ModelViewPlanes& plane void DrawWorldModelLeaves( std::list& clipped, std::list& inside, const ModelViewPlanes& planes, const float* matrix, unsigned frame, int updates, - GroundGeometry& ground, ModelRenderContext& models, GroundLightingContext& lighting, int* visibleRectangle + GroundGeometry& ground, ModelRenderContext& models, int* visibleRectangle ); extern int g_groundOverlayA; diff --git a/Source/Contents/World/WorldSpatialInitialization.cpp b/Source/Contents/World/WorldSpatialInitialization.cpp index 0f088153..ce0913ee 100644 --- a/Source/Contents/World/WorldSpatialInitialization.cpp +++ b/Source/Contents/World/WorldSpatialInitialization.cpp @@ -1,4 +1,4 @@ -#include "Contents/Ground/GroundSpatial.h" +#include "Contents/Ground/GroundGeometry.h" #include "Contents/Models/ModelActor.h" #include "Contents/World/WorldSpatialInitialization.h" #include "Contents/World/WorldSpatialTree.h" @@ -9,7 +9,7 @@ // OFFSET: 0x00AC79C0 // FUNCTION: fn_17660 void InitializeWorldSpatial( - WorldSpatialTree& root, GroundSpatial& ground, C3dAttr& terrain, std::span models, const WorldSpatialTree* serialized + WorldSpatialTree& root, GroundGeometry& ground, C3dAttr& terrain, std::span models, const WorldSpatialTree* serialized ) { root.ClearChildren(); const int halfWidth = ground.width / 2; diff --git a/Source/Contents/World/WorldSpatialInitialization.h b/Source/Contents/World/WorldSpatialInitialization.h index 4b703e19..f922d97b 100644 --- a/Source/Contents/World/WorldSpatialInitialization.h +++ b/Source/Contents/World/WorldSpatialInitialization.h @@ -4,12 +4,12 @@ #include struct WorldSpatialTree; -struct GroundSpatial; +class GroundGeometry; class C3dAttr; class C3dActor; void InitializeWorldSpatial( - WorldSpatialTree& root, GroundSpatial& ground, C3dAttr& terrain, std::span models, const WorldSpatialTree* serialized + WorldSpatialTree& root, GroundGeometry& ground, C3dAttr& terrain, std::span models, const WorldSpatialTree* serialized ); void PublishWorldModels(WorldSpatialTree& root, C3dActor* const* models, int& published, int& pending); diff --git a/Source/Contents/World/WorldSpatialTree.cpp b/Source/Contents/World/WorldSpatialTree.cpp index 96ff5ea3..38cfc357 100644 --- a/Source/Contents/World/WorldSpatialTree.cpp +++ b/Source/Contents/World/WorldSpatialTree.cpp @@ -1,6 +1,6 @@ #include "Client/Session.h" #include "Contents/Ground/GroundGeometry.h" -#include "Contents/Ground/GroundSpatial.h" +#include "Contents/Ground/GroundGeometry.h" #include "Contents/Models/ModelActor.h" #include "Contents/Movies/BinkMovies.h" #include "Contents/World/World.h" @@ -146,7 +146,7 @@ void WorldSpatialTree::BindTerrain(C3dAttr& resource, int depth) { // OFFSET: 0x00AC8620 // FUNCTION: fn_17675 -void WorldSpatialTree::BindGround(GroundSpatial& resource, int depth) { +void WorldSpatialTree::BindGround(GroundGeometry& resource, int depth) { this->dirty = 1; this->ground = &resource; resource.SpatialCell(this->minimum[0], this->minimum[2], this->groundCells[0], this->groundCells[1]); diff --git a/Source/Contents/World/WorldSpatialTree.h b/Source/Contents/World/WorldSpatialTree.h index ffc81d70..bccac941 100644 --- a/Source/Contents/World/WorldSpatialTree.h +++ b/Source/Contents/World/WorldSpatialTree.h @@ -6,7 +6,7 @@ class CFile; class C3dAttr; -struct GroundSpatial; +class GroundGeometry; class C3dActor; struct WorldSpatialTree { @@ -18,7 +18,7 @@ struct WorldSpatialTree { void ReadBounds(CFile& input, int depth); void ClearChildren(); void BindTerrain(C3dAttr& resource, int depth); - void BindGround(GroundSpatial& resource, int depth); + void BindGround(GroundGeometry& resource, int depth); void CopyBounds(int depth, const WorldSpatialTree& source); void RefreshBounds(int depth); void RefreshModelBounds(int depth); @@ -34,7 +34,7 @@ struct WorldSpatialTree { /* 0038 */ float halfSize[3]; /* 0044 */ int dirty; /* 0048 */ std::vector objects; - /* 0054 */ GroundSpatial* ground; + /* 0054 */ GroundGeometry* ground; /* 0058 */ int groundCells[4]; /* 0068 */ C3dAttr* terrain; /* 006C */ int terrainCells[4];