forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 253
feat: Terrain conforming particles #3245
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
Open
stephanmeesters
wants to merge
7
commits into
TheSuperHackers:main
Choose a base branch
from
stephanmeesters:feat/terrain-conforming-particles
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d648b1b
feat(terrainparticle): Add utility functions to WorldHeightMap
stephanmeesters 379eeaa
refactor(particlesys): Update particle batching to use new alignment …
stephanmeesters ab8c6b7
feat(terrainparticle): Expand particle alignment enum with Conforming…
stephanmeesters 906c571
refactor(particlesys): Introduce isFieldParticle
stephanmeesters 91741ac
feat(terrainparticle): Add terrain conforming particle renderer
stephanmeesters 0df7ccf
feat(terrainparticle): Add terrain conforming particle statistics
stephanmeesters e389227
feat(terrainparticle): Add define guard for terrain conforming particles
stephanmeesters File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DTerrainParticle.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| ** Command & Conquer Generals Zero Hour(tm) | ||
| ** Copyright 2026 TheSuperHackers | ||
| ** | ||
| ** This program is free software: you can redistribute it and/or modify | ||
| ** it under the terms of the GNU General Public License as published by | ||
| ** the Free Software Foundation, either version 3 of the License, or | ||
| ** (at your option) any later version. | ||
| ** | ||
| ** This program is distributed in the hope that it will be useful, | ||
| ** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ** GNU General Public License for more details. | ||
| ** | ||
| ** You should have received a copy of the GNU General Public License | ||
| ** along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <vector> | ||
|
|
||
| #include "Common/MapObject.h" | ||
| #include "Lib/BaseType.h" | ||
| #include "WW3D2/shader.h" | ||
| #include "WWLib/sharebuf.h" | ||
| #include "WWMath/vector3.h" | ||
| #include "WWMath/vector4.h" | ||
|
|
||
| constexpr const UnsignedShort MAX_VERTICES = 32768; | ||
| constexpr const UnsignedShort MAX_INDICES = 65535; | ||
| constexpr const UnsignedShort INVALID_VERTEX = MAX_VERTICES + 1; | ||
| constexpr const Real Z_OFFSET = MAP_HEIGHT_SCALE / 10; | ||
|
|
||
| static_assert(MAX_VERTICES < INVALID_VERTEX, "Vertex indices must leave room for the INVALID_VERTEX sentinel value."); | ||
|
|
||
| class AABoxClass; | ||
| class TextureClass; | ||
| class WorldHeightMap; | ||
| struct VertexFormatXYZNDUV2; | ||
|
|
||
| /** | ||
| * Render particles as terrain conforming overlays. For each particle, form an initial region by calculating the bounds | ||
| * of its rotated square and intersecting that with the map bounds and visible-terrain bounds. Recursively subdivide this | ||
| * region until each sub-region is either a single terrain cell or is on perfectly flat terrain. Flat regions become one | ||
| * large quad, while non-flat regions must match the terrain's topology exactly. | ||
| */ | ||
| class W3DTerrainParticle | ||
| { | ||
| public: | ||
| W3DTerrainParticle(); | ||
| ~W3DTerrainParticle(); | ||
|
|
||
| void setTexture(TextureClass* texture); | ||
| void setShader(ShaderClass shader); | ||
| void setArrays(ShareBufferClass<Vector3>* locs, | ||
| ShareBufferClass<Vector4>* diffuse = nullptr, | ||
| ShareBufferClass<Real>* sizes = nullptr, | ||
| ShareBufferClass<UnsignedByte>* orientations = nullptr, | ||
| Int activePointCount = -1); | ||
| void setBoundingBox(const AABoxClass& worldBoundingBox); | ||
| void render(); | ||
|
|
||
| private: | ||
|
|
||
| struct ParticleContext; | ||
|
|
||
| void drawRegion(WorldHeightMap& map, const ParticleContext& particle, const IRegion2D& bounds); | ||
| void drawQuad(WorldHeightMap& map, const ParticleContext& particle, const IRegion2D& bounds); | ||
| UnsignedShort addVertex(WorldHeightMap& map, const ParticleContext& particle, Int x, Int y); | ||
| void addTriangle(UnsignedShort a, UnsignedShort b, UnsignedShort c);void resetVertexLookup(); | ||
| void flushBatch(); | ||
| IRegion2D calcTerrainBounds(WorldHeightMap& map, const Vector3& loc, Real projectedRadius) const; | ||
| void updateSettings(); | ||
|
|
||
| std::vector<VertexFormatXYZNDUV2> m_vertexData; ///< Vertices of the current batch. | ||
| std::vector<UnsignedShort> m_indexData; ///< Indices defining the triangles of the current batch. | ||
| std::vector<UnsignedByte> m_outcodes; ///< UV outcodes indexed by batch vertex. | ||
| std::vector<UnsignedShort> m_vertexLookup; ///< Map grid location to index in m_vertexData. | ||
| UnsignedShort m_numVertices; ///< Number of vertices used in m_vertexData. | ||
| UnsignedShort m_numIndices; ///< Number of indices used in m_indexData. | ||
|
|
||
| TextureClass* m_texture; | ||
| ShaderClass m_shader; | ||
|
|
||
| ShareBufferClass<Vector3>* m_pointLoc; ///< World space point locations. | ||
| ShareBufferClass<Vector4>* m_pointDiffuse; ///< RGBA values (nullptr if not used). | ||
| ShareBufferClass<Real>* m_pointSize; ///< Size override table (nullptr if not used). | ||
| ShareBufferClass<UnsignedByte>* m_pointOrientation; ///< Orientation indices (nullptr if not used). | ||
| Int m_pointCount; ///< Total point count. | ||
| IRegion2D m_terrainInViewBounds; ///< Bounding box of which terrain cell indices are on the screen. | ||
|
|
||
| Real m_defaultPointSize; ///< Point size (size array overrides if present). | ||
| Vector3 m_defaultPointColor; ///< Point color (color array overrides if present). | ||
| Real m_defaultPointAlpha; ///< Point alpha (alpha array overrides if present). | ||
| UnsignedByte m_defaultPointOrientation; ///< Point orientation (orientation array overrides if present). | ||
| UnsignedInt m_defaultDiffuse; ///< Diffuse built from m_defaultPointColor and m_defaultPointAlpha. | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7. Editing effects removes terrain alignment🐞 Bug⚙ MaintainabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation toolsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ParticleEditor support for conforming particles should be handled in a later PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dismissed — deferred.