GPU-first shallow-water (2D Saint-Venant) free-surface solver. 更多...
#include <ShallowWaterField.h>
Public 成员函数 | |
| ~ShallowWaterField () | |
| ShallowWaterField (const ShallowWaterField &)=delete | |
| ShallowWaterField & | operator= (const ShallowWaterField &)=delete |
| Result< void > | step (float dt) |
Advance the free surface by dt seconds (CFL substeps). | |
| Result< void > | setColliders (std::span< const ShallowWaterCollider > colliders) |
| Replace analytic interactors atomically. | |
| Result< void > | setBed (std::span< const float > beds) |
| Replace bed heights; call fillSurface afterwards to initialize a level lake. | |
| Result< void > | fillDepth (float depth) |
| Fill every cell with a uniform water depth (momentum cleared). | |
| Result< void > | fillSurface (float surfaceY) |
| Fill to a world-space free-surface elevation, leaving high terrain dry. | |
| Result< void > | disturbAt (float worldX, float worldZ, float radius, float heightDelta, float radialSpeed=0.f) |
| Inject a localized height bump and radial outflow (mouse / splash). | |
| Result< void > | addImpulse (float worldX, float worldZ, float radius, float strength) |
| Convenience splash: positive strength raises water, negative digs. | |
| int | resolutionX () const noexcept |
| int | resolutionZ () const noexcept |
| float | cellSize () const noexcept |
| int | cellCount () const noexcept |
| glm::vec3 | origin () const noexcept |
| bool | usingGpu () const noexcept |
| bool | usedBackendFallback () const noexcept |
| std::span< const float > | depths () const noexcept |
| std::span< const float > | beds () const noexcept |
| std::span< const float > | momentumX () const noexcept |
| std::span< const float > | momentumZ () const noexcept |
| std::span< const ShallowWaterCollider > | colliders () const noexcept |
| float | surfaceHeightAt (float worldX, float worldZ) const noexcept |
Bilinear free-surface height b + h at a world XZ point. | |
| float | depthAt (float worldX, float worldZ) const noexcept |
| Bilinear water depth at a world XZ point. | |
| glm::vec2 | velocityAt (float worldX, float worldZ) const noexcept |
| Bilinear horizontal velocity at a world XZ point. | |
| Result< void > | buildSurfaceMesh (std::vector< float > &positionsXYZ, std::vector< float > &normalsXYZ, std::vector< float > &uvsST, std::vector< uint32_t > &indices, float visualHeightGain=1.f, std::vector< float > *colorsRGBA=nullptr) const |
| Build a Y-up triangle mesh of the free surface for Graphics upload. | |
| Result< void > | copyFieldToImage (image::ImageData &image, float velocityScale=2.f, float depthContrast=0.f) const |
Pack per-cell depth / velocity into an RGBA8 image (resolutionX × resolutionZ). | |
| Result< void > | copyShadedAlbedoToImage (image::ImageData &image, float restDepth, float velocityScale=2.f) const |
| Write a shaded water albedo (RGBA8, same size as the grid) for Material upload. | |
| Result< void > | copyNormalToImage (image::ImageData &image, float normalStrength=6.f) const |
| Write tangent-space normals from free-surface slopes (RGBA8, same grid size). | |
| ShallowWaterSettings | settings () const noexcept |
静态 Public 成员函数 | |
| static Result< std::unique_ptr< ShallowWaterField > > | create (const ShallowWaterSettings &settings) |
| Validate settings and allocate a filled lake. | |
详细描述
GPU-first shallow-water (2D Saint-Venant) free-surface solver.
Owns height h, momentum (hu, hv) and bed b on a Cartesian XZ grid. The CPU reference mirrors the GLSL kernels 1:1 and is selected automatically when compute is unavailable. Character-leg capsules write displacement / momentum sources before each integrate pass.
@thread Graphics/device owner thread for GPU path; CPU path is reentrant for distinct instances only.
在文件 ShallowWaterField.h 第 100 行定义.
构造及析构函数说明
◆ ~ShallowWaterField()
| eve::fluids::ShallowWaterField::~ShallowWaterField | ( | ) |
在文件 ShallowWaterField.cpp 第 140 行定义.
◆ ShallowWaterField()
|
delete |
成员函数说明
◆ addImpulse()
| Result< void > eve::fluids::ShallowWaterField::addImpulse | ( | float | worldX, |
| float | worldZ, | ||
| float | radius, | ||
| float | strength | ||
| ) |
Convenience splash: positive strength raises water, negative digs.
在文件 ShallowWaterField.cpp 第 289 行定义.
引用了 disturbAt(), radius , 以及 strength.
◆ beds()
◆ buildSurfaceMesh()
| Result< void > eve::fluids::ShallowWaterField::buildSurfaceMesh | ( | std::vector< float > & | positionsXYZ, |
| std::vector< float > & | normalsXYZ, | ||
| std::vector< float > & | uvsST, | ||
| std::vector< uint32_t > & | indices, | ||
| float | visualHeightGain = 1.f, |
||
| std::vector< float > * | colorsRGBA = nullptr |
||
| ) | const |
Build a Y-up triangle mesh of the free surface for Graphics upload.
- 参数
-
[out] positionsXYZ Vertex positions (3 floats each). [out] normalsXYZ Vertex normals (3 floats each). [out] uvsST Vertex UVs in [0,1]^2 (2 floats each). [out] indices Triangle indices. visualHeightGain Display-only scale for (h - rest)relative to the last fill depth per cell; 1 keeps physical heights. Values in (0, 32] exaggerate centimetre waves for readability.[out] colorsRGBA Optional per-vertex RGBA (4 floats each) for coloured meshes; pass nullptr to skip. Packs the same channel layout as copyFieldToImagewith rest-relative depth (depthContrast = 0.12 * meanH,velocityScale = 1.5).
在文件 ShallowWaterField.cpp 第 349 行定义.
引用了 c, cellCount(), cx, dx, dz, h, index, indices, n, p, pos, reference, eve::Result< T >::success(), u, eve::fluids::ocean_script::vector(), vx, vz, x, y , 以及 z.
◆ cellCount()
|
inlinenoexcept |
- 返回
- Cell count (
resolutionX * resolutionZ).
在文件 ShallowWaterField.h 第 169 行定义.
被这些函数引用 buildSurfaceMesh(), copyFieldToImage(), setBed() , 以及 step().
◆ cellSize()
|
inlinenoexcept |
- 返回
- Cell edge length in meters.
在文件 ShallowWaterField.h 第 167 行定义.
◆ colliders()
|
inlinenoexcept |
◆ copyFieldToImage()
| Result< void > eve::fluids::ShallowWaterField::copyFieldToImage | ( | image::ImageData & | image, |
| float | velocityScale = 2.f, |
||
| float | depthContrast = 0.f |
||
| ) | const |
Pack per-cell depth / velocity into an RGBA8 image (resolutionX × resolutionZ).
- 参数
-
image Destination; must be RGBA8 with width= resolutionXand height=resolutionZ.velocityScale Horizontal speed that maps to the full channel range, in (0, 50]. depthContrast When <= 0, R stores absoluteh / maxDepth. When> 0, R stores a crest heat mapclamp((h - meanH) / depthContrast, 0, 1)so rest water stays dark and centimetre waves still paint red (range(0, maxDepth]).
Channel layout (row z, column x, matching mesh UVs):
- R: water depth (absolute
h/maxDepth, or crest heat whendepthContrast > 0) - G:
0.5 + 0.5 * clamp(vx / velocityScale, -1, 1) - B:
0.5 + 0.5 * clamp(vz / velocityScale, -1, 1) - A:
clamp(|v| / velocityScale, 0, 1)(foam / speed mask) @ownership Does not retainimage; caller owns the pixel buffer for the call duration.- 返回
- Success, or InvalidArgument when the image shape/format/scale is rejected.
在文件 ShallowWaterField.cpp 第 449 行定义.
引用了 cellCount(), h, image, index, p, pixels, shape, eve::Result< T >::success(), eve::fluids::ocean_script::vector(), vx, vz, x , 以及 z.
◆ copyNormalToImage()
| Result< void > eve::fluids::ShallowWaterField::copyNormalToImage | ( | image::ImageData & | image, |
| float | normalStrength = 6.f |
||
| ) | const |
Write tangent-space normals from free-surface slopes (RGBA8, same grid size).
- 参数
-
image Destination RGBA8 resolutionX×resolutionZ.normalStrength Slope exaggeration in (0, 64]; higher values make small waves catch light.
RGB stores 0.5 + 0.5 * n with n in tangent space (Z-up in texture); A = 1. @ownership Does not retain image.
在文件 ShallowWaterField.cpp 第 530 行定义.
引用了 cx, image, index, n, normalStrength, p, pixels, shape, eve::Result< T >::success(), eve::fluids::ocean_script::vector(), x , 以及 z.
◆ copyShadedAlbedoToImage()
| Result< void > eve::fluids::ShallowWaterField::copyShadedAlbedoToImage | ( | image::ImageData & | image, |
| float | restDepth, | ||
| float | velocityScale = 2.f |
||
| ) | const |
Write a shaded water albedo (RGBA8, same size as the grid) for Material upload.
- 参数
-
image Destination RGBA8 resolutionX×resolutionZ.restDepth Reference depth used to exaggerate crests/troughs; typically initialDepth.velocityScale Speed scale for foam / flow tint, in (0, 50].
Deep water is dark cyan; crests lighten; horizontal flow shifts green/magenta; foam (near-white) follows speed. Intended for setAlbedoTexture / setTexture. @ownership Does not retain image.
在文件 ShallowWaterField.cpp 第 487 行定义.
引用了 b, g, h, image, index, p, pixels, r, shape, eve::Result< T >::success(), eve::fluids::ocean_script::vector(), vx, vz, x , 以及 z.
◆ create()
|
static |
Validate settings and allocate a filled lake.
- 参数
-
settings Borrowed immutable configuration.
- 返回
- Owned solver, or InvalidArgument when ranges fail.
在文件 ShallowWaterField.cpp 第 108 行定义.
引用了 eve::fluids::ShallowWaterSettings::bedHeight, cells, eve::fluids::ocean_codec::field(), eve::fluids::ShallowWaterSettings::initialDepth, settings() , 以及 valid.
◆ depthAt()
Bilinear water depth at a world XZ point.
在文件 ShallowWaterField.cpp 第 315 行定义.
引用了 a, b, index, inside, eve::fluids::ocean_script::vector(), x , 以及 z.
◆ depths()
- 返回
- Water-column heights (authoritative CPU mirror).
在文件 ShallowWaterField.h 第 178 行定义.
◆ disturbAt()
| Result< void > eve::fluids::ShallowWaterField::disturbAt | ( | float | worldX, |
| float | worldZ, | ||
| float | radius, | ||
| float | heightDelta, | ||
| float | radialSpeed = 0.f |
||
| ) |
Inject a localized height bump and radial outflow (mouse / splash).
- 参数
-
worldX World X of the disturbance center. worldZ World Z of the disturbance center. radius Influence radius in meters. heightDelta Added water column height. radialSpeed Outward horizontal speed applied under the bump.
在文件 ShallowWaterField.cpp 第 259 行定义.
引用了 dx, dz, h, index, radius, eve::Result< T >::success(), eve::fluids::ocean_script::vector(), w, wx, wz, x , 以及 z.
被这些函数引用 addImpulse().
◆ fillDepth()
Fill every cell with a uniform water depth (momentum cleared).
在文件 ShallowWaterField.cpp 第 232 行定义.
引用了 depth, eve::Result< T >::success() , 以及 eve::fluids::ocean_script::vector().
◆ fillSurface()
Fill to a world-space free-surface elevation, leaving high terrain dry.
- 参数
-
surfaceY Finite elevation in the same coordinates as setBed.
- 返回
- InvalidArgument for invalid elevation or depth exceeding maxDepth; failure is atomic. @ownership Copies reference depths internally; no borrowed input is retained. @thread Owner thread, not concurrent with step or queries; invokes no callbacks. @cost Linear in grid cells, more expensive than a point query; amortize over lake initialization.
在文件 ShallowWaterField.cpp 第 242 行定义.
引用了 eve::Result< T >::success() , 以及 eve::fluids::ocean_script::vector().
◆ momentumX()
- 返回
- X momentum
hu.
在文件 ShallowWaterField.h 第 182 行定义.
◆ momentumZ()
- 返回
- Z momentum
hv.
在文件 ShallowWaterField.h 第 184 行定义.
◆ operator=()
|
delete |
◆ origin()
|
inlinenoexcept |
- 返回
- World origin of cell (0,0).
在文件 ShallowWaterField.h 第 171 行定义.
◆ resolutionX()
|
inlinenoexcept |
- 返回
- Grid resolution along X.
在文件 ShallowWaterField.h 第 163 行定义.
◆ resolutionZ()
|
inlinenoexcept |
- 返回
- Grid resolution along Z.
在文件 ShallowWaterField.h 第 165 行定义.
◆ setBed()
Replace bed heights; call fillSurface afterwards to initialize a level lake.
- 参数
-
beds Borrowed cellCount() heights in row-major Z/X order, copied during this call.
- 返回
- InvalidArgument for wrong size or nonfinite data; failure leaves the field unchanged. @thread Owner thread, not concurrent with step or queries; no callbacks/reentrancy. @cost Linear in grid cells, more expensive than a point query; amortize over terrain setup.
在文件 ShallowWaterField.cpp 第 222 行定义.
引用了 beds(), cellCount(), eve::Result< T >::success(), v, eve::fluids::ocean_script::vector() , 以及 eve::gpgpu::GpuBuffer::writeFloat32s().
◆ setColliders()
| Result< void > eve::fluids::ShallowWaterField::setColliders | ( | std::span< const ShallowWaterCollider > | colliders | ) |
Replace analytic interactors atomically.
- 参数
-
colliders Borrowed samples valid only for the call duration.
在文件 ShallowWaterField.cpp 第 199 行定义.
引用了 eve::fluids::Box, c, eve::fluids::Capsule, colliders(), label, eve::fluids::Sphere, eve::Result< T >::success() , 以及 eve::fluids::ocean_script::vector().
◆ settings()
|
noexcept |
- 返回
- Mutable tuning copy (does not resize the grid).
在文件 ShallowWaterField.cpp 第 180 行定义.
引用了 eve::fluids::ShallowWaterSettings::resolutionX , 以及 s.
被这些函数引用 create().
◆ step()
Advance the free surface by dt seconds (CFL substeps).
在文件 ShallowWaterField.cpp 第 691 行定义.
引用了 cellCount(), dt, gpu, h, eve::Result< T >::success(), u, v , 以及 eve::fluids::ocean_script::vector().
◆ surfaceHeightAt()
Bilinear free-surface height b + h at a world XZ point.
在文件 ShallowWaterField.cpp 第 294 行定义.
引用了 a, b, index, inside, eve::fluids::ocean_script::vector(), x , 以及 z.
◆ usedBackendFallback()
|
inlinenoexcept |
- 返回
- True when GPU was requested but CPU was selected.
在文件 ShallowWaterField.h 第 175 行定义.
◆ usingGpu()
|
inlinenoexcept |
- 返回
- True when the GPU compute path is active.
在文件 ShallowWaterField.h 第 173 行定义.
◆ velocityAt()
Bilinear horizontal velocity at a world XZ point.
在文件 ShallowWaterField.cpp 第 331 行定义.
引用了 a, b, h, index, inside, eve::fluids::ocean_script::vector(), x , 以及 z.
该类的文档由以下文件生成:
- src/modules/fluids/ShallowWaterField.h
- src/modules/fluids/ShallowWaterField.cpp