载入中...
搜索中...
未找到
Fluids.cpp
浏览该文件的文档.
206 eve::DiagnosticCode::Unsupported, "Fluid GPGPU accelerator unavailable; CPU reference selected",
224eve::Result<void> FluidSimulator::restoreObservation(const eve::physics::SimulationObservation& observation) {
226 eve::physics::detail::validateSimulationObservation(observation, "fluids.simulationBackend.restoreObservation");
244void FluidSimulator::setGravity(float x, float y, float z) { sim_.params().gravity = glm::vec3(x, y, z); }
249void FluidSimulator::setPbfIterations(int passes) { sim_.params().pbfIterations = std::max(0, passes); }
251void FluidSimulator::setParticleRadius(float radius) { sim_.params().particleRadius = std::max(1e-4f, radius); }
427ShallowWaterField* Fluids::newShallowWater(int resolutionX, int resolutionZ, float cellSize, bool preferGpu) {
454 "FluidSim", std::function<FluidSimulator*()>([]() -> FluidSimulator* { return nullptr; }), true);
471 "FluidSurface", std::function<FluidSurfaceRenderer*()>([]() -> FluidSurfaceRenderer* { return nullptr; }),
476 surf.addFunc("renderVolumeInterpolated", [vm = table.getHandle()](FluidSurfaceRenderer* renderer,
481 eve::DiagnosticCode::InvalidArgument, "Missing volume fluid", "fluids.surface.interpolation")));
485 [](FluidSurfaceRenderer* renderer, VolumeFluid* solver) { renderer->renderVolumeColorOnly(*solver); });
486 surf.addFunc("renderGasVolume", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, VolumeFluid* solver,
494 surf.addFunc("renderVolumeWithoutSurface", [vm = table.getHandle()](FluidSurfaceRenderer* renderer,
500 return eve::script::projectResult(vm, renderer->renderVolumeWithoutSurface(*solver, absorption));
503 "renderConfiguredVolume", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, VolumeFluid* solver) {
513 surf.addFunc("copyToTexture", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, graphics::Graphics* graphics,
524 return eve::script::projectResult(vm, renderer->renderVolumeColorToTexture(*solver, graphics, texture));
526 surf.addFunc("compositeDiffuse", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, VolumeFluidDiffuse* pool,
532 return eve::script::projectResult(vm, renderer->compositeDiffuse(*pool, radius, opacity, fadeSeconds));
538 surf.addFunc("compositeSceneRefraction", [vm = table.getHandle()](FluidSurfaceRenderer* renderer,
552 surf.addFunc("configureRefraction", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, float transparency,
557 surf.addFunc("configureRefractionEnabled", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, bool enabled) {
560 surf.addFunc("compositeConfiguredSceneRefraction", [vm = table.getHandle()](FluidSurfaceRenderer* renderer,
568 return eve::script::projectResult(vm, renderer->compositeConfiguredSceneRefraction(std::span<const uint8_t>(
575 surf.addFunc("configureParticleBlend", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, int source,
577 return eve::script::projectResult(vm, renderer->configureParticleBlend(source, destination, depthWrite));
579 surf.addFunc("compositeConfiguredSurfaceBlend", [vm = table.getHandle()](FluidSurfaceRenderer* renderer,
587 return eve::script::projectResult(vm, renderer->compositeConfiguredSurfaceBlend(std::span<const uint8_t>(
592 "configureSurface", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, float thicknessScale,
595 vm, renderer->configureSurface(thicknessScale, thicknessCutoff, depthFalloff, smoothIterations));
597 surf.addFunc("configureSurfaceEnabled", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, bool enabled) {
613 surf.addFunc("configureSurfaceBlurRadius", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, float radius) {
620 vm, renderer->configureMaterial(lighting, smoothness, metalness, ambientMultiplier, reflection, opacity));
622 surf.addFunc("configureReflection", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, bool enabled) {
625 surf.addFunc("configureColors", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, float br, float bg,
629 surf.addFunc("configureAnisotropy", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, bool enabled) {
632 surf.addFunc("configureSurfaceDownsample", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, int factor) {
635 surf.addFunc("configureThicknessDownsample", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, int factor) {
638 surf.addFunc("configureProjection", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, bool orthographic,
640 return eve::script::projectResult(vm, renderer->configureProjection(orthographic, verticalHalfSize));
650 surf.addFunc("copyToImage", [vm = table.getHandle()](FluidSurfaceRenderer* renderer, image::ImageData* image) {
662 "ShallowWater", std::function<ShallowWaterField*()>([]() -> ShallowWaterField* { return nullptr; }), true);
679 [vm = table.getHandle()](ShallowWaterField* field, float x, float z, float radius, float strength) {
682 sw.addFunc("disturbAt", [vm = table.getHandle()](ShallowWaterField* field, float x, float z, float radius,
684 return eve::script::projectResult(vm, field->disturbAt(x, z, radius, heightDelta, radialSpeed));
687 [vm = table.getHandle()](ShallowWaterField* field, unsigned label, float cx, float cy, float cz,
706 sw.addFunc("setColliderSphere", [vm = table.getHandle()](ShallowWaterField* field, unsigned label, float cx,
731 sw.addFunc("depthAt", [](ShallowWaterField* field, float x, float z) { return field->depthAt(x, z); });
732 sw.addFunc("velocityXAt", [](ShallowWaterField* field, float x, float z) { return field->velocityAt(x, z).x; });
733 sw.addFunc("velocityZAt", [](ShallowWaterField* field, float x, float z) { return field->velocityAt(x, z).y; });
738 sw.addFunc("usedBackendFallback", [](ShallowWaterField* field) { return field->usedBackendFallback(); });
740 // Build into owned temporary buffers, then publish once per presented frame; no VM array round trip.
741 sw.addFunc("syncSurfaceMesh", [vm = table.getHandle()](ShallowWaterField* field, graphics::Graphics* graphicsApi,
759 sw.addFunc("buildSurfaceMesh", [vm = table.getHandle()](ShallowWaterField* field, float visualHeightGain) {
784 sw.addFunc("copyFieldToImage", [vm = table.getHandle()](ShallowWaterField* field, image::ImageData* image,
791 return eve::script::projectResult(vm, field->copyFieldToImage(*image, velocityScale, depthContrast));
793 sw.addFunc("copyShadedAlbedoToImage", [vm = table.getHandle()](ShallowWaterField* field, image::ImageData* image,
800 return eve::script::projectResult(vm, field->copyShadedAlbedoToImage(*image, restDepth, velocityScale));
803 [vm = table.getHandle()](ShallowWaterField* field, image::ImageData* image, float normalStrength) {
ScriptMotionSinkStore< ScriptMotionSink< MotionColorTraits > > colors
Definition MotionScriptBindings.cpp:218
The single Squirrel projection for common Result, Status and Value.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Diagnostic warning(DiagnosticCode code, std::string message, std::string path={})
Construct a warning diagnostic.
Definition Diagnostic.cpp:24
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
void setSdf(const MeshSdf &sdf)
Replace the collision surface. Particles keep their state.
Definition FluidSdf.cpp:282
int spawnDrop(const glm::vec3 ¢er, float radius, int count)
Spawn a roughly spherical drop of particles near the surface.
Definition FluidSdf.cpp:293
void step(float dt)
Advance the simulation by dt seconds (params.iterations substeps).
Definition FluidSdf.cpp:321
GPU-backed surface fluid simulator (falls back to the CPU solver).
Definition Fluids.h:45
eve::Result< void > restoreObservation(const eve::physics::SimulationObservation &observation) override
Restores tick/progress metadata after an owner-level restore.
Definition Fluids.cpp:224
void setParticleRadius(float radius)
Set particle radius (support radius is unchanged).
Definition Fluids.cpp:251
void setSdf(const MeshSdf &sdf)
Replace the collision surface (re-uploads the SDF on the GPU path).
Definition Fluids.cpp:90
void readPositions(std::vector< glm::vec3 > &out) const
Copy live particle positions out (CPU mirror; GPU path downloads).
Definition Fluids.cpp:232
eve::physics::SimulationObservation observation() const noexcept override
Returns completed tick/time observables.
Definition Fluids.h:83
FluidSimulator(int maxParticles, const FluidParams ¶ms, bool preferGpu)
Fluid simulator.
Definition Fluids.cpp:65
void setPbfIterations(int passes)
Set PBF density-constraint passes per substep.
Definition Fluids.cpp:249
void setSdfSphere(float cx, float cy, float cz, float radius, int res)
Convenience: bake a sphere SDF around the origin.
Definition Fluids.cpp:257
int spawnDrop(const glm::vec3 ¢er, float radius, int count)
Spawn a drop of particles near the surface.
Definition Fluids.cpp:124
void readDensities(std::vector< float > &out) const
Copy per-particle densities out (CPU mirror).
Definition Fluids.cpp:238
void setCohesion(float cohesion)
Set Akinci-style fluid-fluid cohesion strength.
Definition Fluids.cpp:247
Buffer-level screen-space fluid renderer.
Definition FluidSurfaceRenderer.h:103
void renderFrom(FluidSimulator *sim)
Script-friendly wrapper: render(*sim) with a null check.
Definition FluidSurfaceRenderer.cpp:129
ShallowWaterField * newShallowWater(int resolutionX=64, int resolutionZ=64, float cellSize=0.25f, bool preferGpu=true)
Create a shallow-water free-surface field (CPU reference + optional GPU).
Definition Fluids.cpp:427
FluidSurfaceRenderer * newSurfaceRenderer(int width=160, int height=160)
Create a screen-space fluid renderer.
Definition Fluids.cpp:415
FluidSimulator * newSimulator(int maxParticles=8192)
Create a surface fluid simulator.
Definition Fluids.cpp:406
std::vector< float > distances
Signed distances, dims.x * dims.y * dims.z floats.
Definition FluidSdf.h:37
static MeshSdf makeSphere(const glm::vec3 ¢er, float radius, const glm::ivec3 &dims)
Bake an analytic sphere into the field.
Definition FluidSdf.cpp:137
GPU-first shallow-water (2D Saint-Venant) free-surface solver.
Definition ShallowWaterField.h:100
static Result< std::unique_ptr< ShallowWaterField > > create(const ShallowWaterSettings &settings)
Validate settings and allocate a filled lake.
Definition ShallowWaterField.cpp:108
virtual void bindBuffer(int binding, GpuBuffer *buffer)=0
Bind a storage buffer to set=0 binding. binding in [0, kMaxBindings).
ComputeShader * newShader(const std::string &source)
Compatibility-only raw-owning shader factory (Vulkan: GLSL; WebGPU: WGSL). Vulkan delegates to the ch...
Definition Gpgpu.cpp:324
bool isAvailable() const
True when the active Graphics backend can run compute (device initialized).
Definition Gpgpu.cpp:284
GpuBuffer * newBuffer(int byteSize, const std::string &usage="storage")
Allocate a GPU buffer. usage: "storage" (SSBO) | "staging" (host transfer) | "storage_vertex" (Vulkan...
Definition Gpgpu.cpp:372
Sequence * newSequence()
Create a Kompute-style command Sequence: record buffer transfers and compute dispatches into one comm...
Definition Gpgpu.cpp:384
virtual void writeFloat32s(const float *data, int count, int startIndex=0)=0
Bulk float upload/download (one transfer). startIndex is in floats.
virtual void downloadBytes(void *dst, uint64_t nbytes, uint64_t srcOffset=0) const =0
Downloads bytes.
void recordUpload(GpuBuffer *dst, const void *src, uint64_t nbytes, uint64_t dstOffset=0)
Record upload.
Definition Sequence.cpp:77
void recordDownload(GpuBuffer *src, GpuBuffer *staging, uint64_t nbytes, uint64_t srcOffset=0)
Record download.
Definition Sequence.cpp:82
void recordDispatch(ComputeShader *shader, int groupsX, int groupsY=1, int groupsZ=1)
Record dispatch.
Definition Sequence.cpp:87
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
Definition BuildingSnapshot.cpp:96
const Value & field(const Value &value, const char *name)
Borrow a required child of value; throws on a missing field.
Definition OceanCodecInternal.h:20
const char * kFluidComputeDelta
Accumulate PBF position deltas into the (reused) grad buffer.
Definition FluidGpuKernels.h:165
const char * kFluidApplyDelta
Apply PBF deltas and re-project onto the SDF surface.
Definition FluidGpuKernels.h:228
void exposeVolumeFluidType(ssq::Table &table)
Registers the script-owned volume-fluid class on the VM thread.
Definition VolumeFluidBindings.cpp:4
const char * kFluidDensityLambda
Density, gradient sum and PBF lambda in one pass (mirror computeDensitiesAndGrads + computeLambdas).
Definition FluidGpuKernels.h:87
const char * kFluidIntegrate
Viscosity + cohesion + adhesion + gravity + integration + SDF projection.
Definition FluidGpuKernels.h:331
const char * kFluidBuildGrid
Insert every particle into its grid cell (linked list via atomicExchange).
Definition FluidGpuKernels.h:58
void exposeOceanTypes(ssq::Table &table)
Register owning ocean script types on the VM owner thread; table is borrowed only during registration...
Definition OceanBindings.cpp:9
void exposeVolumeFluidFactory(ssq::Class &cls)
Registers volume-fluid factories on the existing Fluids class.
Definition VolumeFluidFactoryBindings.cpp:7
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
ssq::Table projectStatusResult(HSQUIRRELVM vm, const Status &status)
Project a checked native status that carries no payload.
Definition SquirrelBinding.cpp:524
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
Definition SquirrelBinding.cpp:540
@ InvalidArgument
@ Unsupported
@ Failed
@ Applied
float supportRadius
SPH support radius h (kernel cutoff), typically 4x particleRadius.
Definition FluidMath.h:30
Camera + reconstruction tuning for the SSF pipeline.
Definition FluidSurfaceRenderer.h:61
Authoritative settings for a shallow-water heightfield.
Definition ShallowWaterField.h:58
static SimGrid make(const MeshSdf &sdf, float cellSize)
Build a grid covering the SDF domain plus one cell of padding.
Definition FluidSdf.cpp:250
Observable backend progress shared by CPU and accelerator providers.
Definition SimulationBackend.h:136
Validated solver policy for one simulation step.
Definition SimulationBackend.h:120