载入中...
搜索中...
未找到
FluidSurfaceRenderer.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
18#include <glm/glm.hpp>
19#include "common/Result.h"
20
21#include <cstdint>
22#include <memory>
23#include <span>
24#include <string>
25#include <vector>
26
27namespace eve::gpgpu {
28class ComputeShader;
29class Gpgpu;
30class GpuBuffer;
31class Sequence;
32} // namespace eve::gpgpu
33
34namespace eve::graphics {
35class Graphics;
36class Texture;
37} // namespace eve::graphics
38
39namespace eve::fluids {
40
41class FluidSimulator;
42class VolumeFluid;
43class VolumeFluidDiffuse;
44
46enum class FluidBlendFactor : int {
47 Zero = 0,
48 One = 1,
50 SourceColor = 3,
52 SourceAlpha = 5,
58};
59
62 glm::vec3 eye{0.f, 0.f, -2.6f};
63 glm::vec3 target{0.f};
64 glm::vec3 up{0.f, 1.f, 0.f};
65 float fovYDeg = 55.f;
66 bool orthographic = false;
67 float orthographicSize = 1.f;
68 float aspect = 1.f;
69 float nearZ = 0.05f;
70 float farZ = 20.f;
71 int width = 160;
72 int height = 160;
73 float particleRadius = 0.05f;
75 float depthFalloff = 0.03f;
76 float thicknessScale = 1.f;
78 int mode = 0;
79};
80
85 bool particleZWrite = false;
86 float thicknessCutoff = 1.2f;
88 bool generateSurface = true;
89 float blurRadius = .02f;
91 bool lighting = true;
92 float smoothness = .8f, metalness = 0.f, ambientMultiplier = 1.f;
93 bool generateReflection = true;
94 float reflection = .2f;
95 bool generateRefraction = true;
96 float transparency = 1.f, absorption = 5.f, refraction = .01f;
98 bool generateFoam = true;
100};
101
104public:
110 FluidSurfaceRenderer(const FluidSurfaceParams& params, bool preferGpu);
113
116
118 void render(const std::vector<glm::vec3>& positions, float particleRadius);
119
121 void render(const FluidSimulator& sim);
123 void renderVolume(const VolumeFluid& sim);
131 [[nodiscard]] Result<void> renderVolumeInterpolated(const VolumeFluid& sim, float alpha);
139 void renderVolumeColorOnly(const VolumeFluid& sim);
150 [[nodiscard]] Result<void> renderGasVolume(const VolumeFluid& sim, float absorption = 5.f);
162 [[nodiscard]] Result<void> renderVolumeWithoutSurface(const VolumeFluid& sim, float absorption = 5.f);
170 [[nodiscard]] Result<void> renderConfiguredVolume(const VolumeFluid& sim);
176 [[nodiscard]] Result<void> prepare();
186 [[nodiscard]] Result<void> copyToTexture(graphics::Graphics* graphics, graphics::Texture* texture);
196 [[nodiscard]] Result<void> renderVolumeColorToTexture(const VolumeFluid& sim, graphics::Graphics* graphics,
197 graphics::Texture* texture);
210 [[nodiscard]] Result<void> compositeDiffuse(const VolumeFluidDiffuse& pool, float radius, float opacity,
211 float fadeSeconds);
219 [[nodiscard]] Result<void> configureFoam(bool enabled, int downsample = 1);
220
231 [[nodiscard]] Result<void> occludeWithSceneDepth(std::span<const float> sceneDepth, float depthBias = 0.001f);
232
242 [[nodiscard]] Result<void> compositeSceneRefraction(std::span<const uint8_t> sceneColor, float distortion = 8.f,
243 float absorption = 3.f);
251 [[nodiscard]] Result<void> configureRefraction(float transparency, float absorption, float coefficient,
252 int downsample);
258 [[nodiscard]] Result<void> configureRefractionEnabled(bool enabled);
264 [[nodiscard]] Result<void> compositeConfiguredSceneRefraction(std::span<const uint8_t> sceneColor);
265
276 [[nodiscard]] Result<void> configureSurfaceBlend(int source, int destination);
286 [[nodiscard]] Result<void> compositeConfiguredSurfaceBlend(std::span<const uint8_t> sceneColor);
298 [[nodiscard]] Result<void> configureParticleBlend(int source, int destination, bool depthWrite);
299
307 [[nodiscard]] Result<void> configureSurface(float thicknessScale, float thicknessCutoff, float depthFalloff,
308 int smoothIterations);
314 [[nodiscard]] Result<void> configureSurfaceEnabled(bool enabled);
320 [[nodiscard]] Result<void> configureRendererSettings(const FluidRendererSettings& settings);
322 [[nodiscard]] FluidRendererSettings rendererSettings() const noexcept;
329 [[nodiscard]] Result<void> configureSurfaceBlurRadius(float radius);
339 [[nodiscard]] Result<void> configureMaterial(bool lighting, float smoothness, float metalness,
340 float ambientMultiplier, float reflection, float opacity);
347 [[nodiscard]] Result<void> configureReflection(bool enabled);
353 [[nodiscard]] Result<void> configureColors(const glm::vec3& baseColor, const glm::vec3& reflectionColor);
361 [[nodiscard]] Result<void> configureAnisotropy(bool enabled);
369 [[nodiscard]] Result<void> configureSurfaceDownsample(int factor);
381 [[nodiscard]] Result<void> configureThicknessDownsample(int factor);
388 [[nodiscard]] Result<void> configureProjection(bool orthographic, float verticalHalfSize = 1.f);
389
395 void renderFrom(FluidSimulator* sim);
396
398 int getWidth() const { return params_.width; }
400 int getHeight() const { return params_.height; }
401
403 const std::vector<float>& depth() const { return depth_; }
404
406 const std::vector<glm::vec3>& normals() const { return normals_; }
407
409 const std::vector<float>& thickness() const { return thickness_; }
410
412 const std::vector<uint8_t>& color() const { return color_; }
413
416 bool usingGpu() const { return reducedRenderer_ ? reducedRenderer_->usingGpu() : gpuOk_; }
417
419 void setMode(int mode) {
420 params_.mode = mode;
422 resetReducedRenderers();
423 }
424
426 void setCamera(const glm::vec3& eye, const glm::vec3& target, const glm::vec3& up, float fovYDeg);
427
429 void writePpm(const std::string& path) const;
430
431private:
432 void renderInternal(const std::vector<glm::vec3>& positions, float particleRadius);
433 void renderVolumeInternal(const VolumeFluid& sim, bool colorOnly, float alpha);
434 [[nodiscard]] Result<void> renderVolumeCloud(const VolumeFluid& sim, float absorption, bool gasOnly);
435 void renderCpu();
436 bool ensureGpu();
437 bool ensureMulticolorGpu();
438 bool ensureAnisotropyGpu();
439 void releaseGpu() noexcept;
440 void uploadParticles();
441 void buildAnisotropicSplats();
442 void setCommonConstants(gpgpu::ComputeShader* shader, float falloff);
443 void applyConfiguredShading();
444 void refreshCustomShadingFlag();
445 void ensureReducedRenderer();
446 void expandReducedOutputs(bool colorOnly);
447 void ensureThicknessRenderer();
448 void replaceThicknessFromReduced();
449 void resetReducedRenderers();
450 static glm::vec4 blendFluidColor(FluidBlendFactor factor, const glm::vec4& source, const glm::vec4& destination);
451
452 FluidSurfaceParams params_;
453 bool preferGpu_ = false;
455 bool gpuAttempted_ = false;
456 bool gpuOk_ = false;
457
458 std::vector<glm::vec3> positions_;
460 std::vector<glm::vec4> volumeColors_;
462 glm::vec4 uniformVolumeColor_{0.f};
463 bool uniformVolumeGpuShade_ = false;
464 bool multicolorVolumeGpuShade_ = false;
465 bool multicolorGpuReady_ = false;
467 bool auxiliaryCurrent_ = false;
469 bool residentColorCurrent_ = false;
471 bool skipHostColorReadback_ = false;
472 bool customShading_ = false;
473 bool anisotropyEnabled_ = false;
474 bool anisotropicFrame_ = false;
475 int surfaceDownsample_ = 1;
476 int thicknessDownsample_ = 1;
477 std::unique_ptr<FluidSurfaceRenderer> reducedRenderer_;
478 std::unique_ptr<FluidSurfaceRenderer> thicknessRenderer_;
479 float thicknessCutoff_ = 0.f;
480 bool surfaceEnabled_ = true;
482 float surfaceBlurRadius_ = -1.f;
483 bool lighting_ = true;
484 float smoothness_ = .8f;
485 float metalness_ = 0.f;
486 float ambientMultiplier_ = .55f;
487 float reflection_ = .75f;
488 bool reflectionEnabled_ = true;
489 float opacity_ = .35f;
490 glm::vec3 baseColor_{.05f, .32f, .72f};
491 glm::vec3 reflectionColor_{.55f, .72f, 1.f};
492 float refractionTransparency_ = 1.f;
493 bool refractionEnabled_ = true;
494 float refractionAbsorption_ = 5.f;
495 float refractionCoefficient_ = .01f;
496 int refractionDownsample_ = 1;
497 FluidBlendFactor surfaceBlendSource_ = FluidBlendFactor::SourceAlpha;
498 FluidBlendFactor surfaceBlendDestination_ = FluidBlendFactor::OneMinusSourceAlpha;
499 FluidBlendFactor particleBlendSource_ = FluidBlendFactor::DestinationColor;
500 FluidBlendFactor particleBlendDestination_ = FluidBlendFactor::Zero;
501 bool particleDepthWrite_ = false;
502 bool particleBlendConfigured_ = false;
504 std::vector<uint8_t> refractionScratch_;
505 std::vector<glm::vec4> volumeTint_;
506 std::vector<float> volumeTintWeights_;
508 std::vector<glm::vec4> gasTintScratch_;
509 std::vector<float> gasDensityScratch_;
510 struct GasSplat {
511 float cx = 0.f, cy = 0.f, r = 0.f, z = 0.f;
512 int x0 = 0, x1 = -1, y0 = 0, y1 = -1;
513 };
514 std::vector<GasSplat> gasSplats_;
516 std::vector<float> gpuParticles_;
518 std::vector<float> anisotropicSplats_;
519 std::vector<glm::vec3> particleRadii_;
520 std::vector<glm::vec4> particleOrientations_;
521 std::vector<glm::vec4> gpuNormals_;
522 std::vector<float> depth_;
524 std::vector<float> depthScratch_;
525 std::vector<float> thickness_;
526 std::vector<glm::vec3> normals_;
527 std::vector<uint8_t> color_;
529 std::vector<glm::vec4> diffuseParticles_;
530 bool foamEnabled_ = true;
531 int foamDownsample_ = 1;
533 std::vector<float> foamCoverageScratch_;
534 struct DiffuseSplat {
535 float x = 0.f, y = 0.f, r = 0.f, z = 0.f, alpha = 0.f;
536 int x0 = 0, x1 = -1, y0 = 0, y1 = -1;
537 };
539 std::vector<DiffuseSplat> diffuseSplats_;
540
541 eve::gpgpu::Gpgpu* gpgpu_ = nullptr;
542 eve::gpgpu::ComputeShader* shClear_ = nullptr;
543 eve::gpgpu::ComputeShader* shSplat_ = nullptr;
544 eve::gpgpu::ComputeShader* shAnisotropicSplat_ = nullptr;
545 eve::gpgpu::ComputeShader* shSmooth_ = nullptr;
546 eve::gpgpu::ComputeShader* shNormal_ = nullptr;
547 eve::gpgpu::ComputeShader* shShade_ = nullptr;
548 eve::gpgpu::ComputeShader* shColorClear_ = nullptr;
549 eve::gpgpu::ComputeShader* shColorSplat_ = nullptr;
550 eve::gpgpu::GpuBuffer* bufParts_ = nullptr;
551 eve::gpgpu::GpuBuffer* bufAnisotropicParts_ = nullptr;
552 eve::gpgpu::GpuBuffer* bufDepthA_ = nullptr;
553 eve::gpgpu::GpuBuffer* bufDepthB_ = nullptr;
554 eve::gpgpu::GpuBuffer* bufThick_ = nullptr;
555 eve::gpgpu::GpuBuffer* bufNormal_ = nullptr;
556 eve::gpgpu::GpuBuffer* bufColor_ = nullptr;
557 eve::gpgpu::GpuBuffer* bufParticleColors_ = nullptr;
558 eve::gpgpu::GpuBuffer* bufColorAccum_ = nullptr;
559 eve::gpgpu::GpuBuffer* stDepth_ = nullptr;
560 eve::gpgpu::GpuBuffer* stThick_ = nullptr;
561 eve::gpgpu::GpuBuffer* stNormal_ = nullptr;
562 eve::gpgpu::GpuBuffer* stColor_ = nullptr;
563 eve::gpgpu::Sequence* seq_ = nullptr;
564};
565
566} // namespace eve::fluids
LogicalId target
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
float cx
Definition CardTypes.cpp:33
float cy
Definition CardTypes.cpp:34
#define EVENGINE_API_DOMAINS
Definition Export.h:110
double r
std::vector< float > positions
HexVec3 up
float f
float radius
std::string path
Definition PlayHost.cpp:110
glm::vec3 eye
Shader * shader
Lighting3DPack lighting
Move-only, checked operation results for the common layer.
TerrainThermalSettings settings
float opacity
const UnitySourceAsset & source
Move-only operation result carrying either a value or Status.
Definition Result.h:155
GPU-backed surface fluid simulator (falls back to the CPU solver).
Definition Fluids.h:44
Buffer-level screen-space fluid renderer.
void setMode(int mode)
Switch shading: 0 water, 1 mud.
const std::vector< uint8_t > & color() const
RGBA8 shaded output.
const std::vector< float > & thickness() const
Accumulated thickness per pixel.
int getHeight() const
Returns the height.
const std::vector< glm::vec3 > & normals() const
View-space normals (0 where no fluid).
FluidSurfaceRenderer(const FluidSurfaceRenderer &)=delete
FluidSurfaceRenderer & operator=(const FluidSurfaceRenderer &)=delete
const std::vector< float > & depth() const
Linear view depth per pixel (FLT_MAX where no fluid).
Bounded, one-way fluid-advected secondary particle pool. @ownership Owns particles and capacity; no f...
CPU position-based free-volume fluid with a bounded spatial grid. @ownership Owns all particle state;...
Backend-agnostic compute program. Bind storage buffers then dispatch via Gpgpu::dispatch....
GPGPU module — compute shaders + storage buffers via the active Graphics backend. Uses the graphics q...
Definition Gpgpu.h:23
Backend-agnostic GPU buffer for compute (storage) or CPU staging transfers. Squirrel-owned; derived c...
Definition GpuBuffer.h:18
EVENGINE_API_WORLD public API.
Definition Sequence.h:41
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
std::vector< ParamSpec > params
GLSL compute kernels for the GPU surface-flow solver.
Definition FluidTarget.h:12
FluidBlendFactor
Unity/Fluid3D blend factors used by fluid render settings.
Fluids module — interactive surface fluid simulation.
Definition Fluids.h:34
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
bool enabled
Complete owning mirror of Fluid3DRendererSettings with package defaults.
Camera + reconstruction tuning for the SSF pipeline.
gpgpu::Gpgpu * gpgpu