载入中...
搜索中...
未找到
VolumeFluidSurface.cpp
浏览该文件的文档.
14void FluidSurfaceRenderer::renderVolume(const VolumeFluid& sim) { renderVolumeInternal(sim, false, 1.f); }
16void FluidSurfaceRenderer::renderVolumeColorOnly(const VolumeFluid& sim) { renderVolumeInternal(sim, true, 1.f); }
18Result<void> FluidSurfaceRenderer::renderVolumeInterpolated(const VolumeFluid& sim, float alpha) {
21 DiagnosticCode::InvalidArgument, "Invalid surface interpolation alpha", "fluids.surface.interpolation"));
26Result<void> FluidSurfaceRenderer::configureRefraction(float transparency, float absorption, float coefficient,
28 if (!std::isfinite(transparency) || transparency < 0.f || transparency > 1.f || !std::isfinite(absorption) ||
46Result<void> FluidSurfaceRenderer::compositeConfiguredSceneRefraction(std::span<const uint8_t> sceneColor) {
59 const int targetWidth = std::max(1, (width + refractionDownsample_ - 1) / refractionDownsample_);
60 const int targetHeight = std::max(1, (height + refractionDownsample_ - 1) / refractionDownsample_);
62 const auto sample = [](std::span<const uint8_t> source, int sourceWidth, int sourceHeight, float x, float y,
72 return std::lerp(std::lerp(at(x0, y0), at(x1, y0), tx), std::lerp(at(x0, y1), at(x1, y1), tx), ty);
81 std::clamp(std::lround(sample(sceneColor, width, height, sourceX, sourceY, channel)), 0l, 255l));
93 const float u = (float(x) + .5f) / float(width) + normals_[i].x * thickness_[i] * refractionCoefficient_;
94 const float v = (float(y) + .5f) / float(height) - normals_[i].y * thickness_[i] * refractionCoefficient_;
99 const float absorbed = std::exp(-refractionAbsorption_ * (1.f - liquid) * std::max(thickness_[i], 0.f));
101 const float fluid = std::lerp(float(color_[rgba + size_t(channel)]), refracted, refractionTransparency_);
111void FluidSurfaceRenderer::renderVolumeInternal(const VolumeFluid& sim, bool colorOnly, float alpha) {
163 params_.orthographic ? params_.orthographicSize : std::tan(glm::radians(params_.fovYDeg) * 0.5f);
182 lighting_ ? std::clamp(ambientMultiplier_ + (1.f - std::min(ambientMultiplier_, 1.f)) * diff, 0.f, 6.f)
185 const float spec = lighting_ ? std::pow(std::max(n.z, 0.f), exponent) * smoothness_ * .56f : 0.f;
191 for (int c = 0; c < 3; ++c) color_[i * 4u + size_t(c)] = uint8_t(255.f * std::clamp(shaded[c], 0.f, 1.f));
192 color_[i * 4u + 3u] = uint8_t(255.f * std::clamp(thickness_[i] * opacity_, 0.f, 1.f) * uniformColor.a);
207 const int x0 = std::max(0, int(std::floor(cx - r))), x1 = std::min(width - 1, int(std::ceil(cx + r)));
208 const int y0 = std::max(0, int(std::floor(cy - r))), y1 = std::min(height - 1, int(std::ceil(cy + r)));
218 if (particleDepthWrite_ && volumeTintWeights_[at] > 0.f && fragmentDepth >= volumeTintWeights_[at])
236 if (volumeTintWeights_[i] <= 0.f || color_[i * 4u + 3u] == 0 || thickness_[i] * 10.f < thicknessCutoff_) {
247 lighting_ ? std::clamp(ambientMultiplier_ + (1.f - std::min(ambientMultiplier_, 1.f)) * diff, 0.f, 6.f)
250 const float spec = lighting_ ? std::pow(std::max(n.z, 0.f), exponent) * smoothness_ * .56f : 0.f;
254 const glm::vec3 shaded = glm::vec3(base) * light + reflected * fresnel * reflectionStrength + glm::vec3(spec);
255 for (int c = 0; c < 3; ++c) color_[i * 4u + size_t(c)] = uint8_t(255.f * std::clamp(shaded[c], 0.f, 1.f));
264Result<void> FluidSurfaceRenderer::renderVolumeWithoutSurface(const VolumeFluid& sim, float absorption) {
274Result<void> FluidSurfaceRenderer::renderVolumeCloud(const VolumeFluid& sim, float absorption, bool gasOnly) {
285 size_t(std::count_if(particles.begin(), particles.end(), [](const VolumeFluidParticle& particle) {
311 params_.orthographic ? params_.orthographicSize : std::tan(glm::radians(params_.fovYDeg) * .5f);
365 auto blur = [&](bool horizontal, const std::vector<float>& srcDensity, const std::vector<glm::vec4>& srcTint,
#define EV_PROFILE_MODULE(module, name)
Profile the enclosing scope, tagged with a module for grouping.
Definition Profile.h:158
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 Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Result< void > renderGasVolume(const VolumeFluid &sim, float absorption=5.f)
Renders gas particles as a blurred, translucent thickness volume.
Definition VolumeFluidSurface.cpp:260
const std::vector< uint8_t > & color() const
RGBA8 shaded output.
Definition FluidSurfaceRenderer.h:412
Result< void > configureRefraction(float transparency, float absorption, float coefficient, int downsample)
Configure Fluid3D-compatible scene refraction controls atomically.
Definition VolumeFluidSurface.cpp:26
Result< void > compositeConfiguredSceneRefraction(std::span< const uint8_t > sceneColor)
Apply the configured Fluid3D-compatible refraction to a matching opaque RGBA8 scene.
Definition VolumeFluidSurface.cpp:46
void renderVolume(const VolumeFluid &sim)
Reconstructs a volume-fluid snapshot and shades its diffusing particle colors.
Definition VolumeFluidSurface.cpp:14
Result< void > renderVolumeInterpolated(const VolumeFluid &sim, float alpha)
Reconstructs from fixed-step interpolated volume positions using the existing SSF pipeline.
Definition VolumeFluidSurface.cpp:18
Result< void > renderVolumeWithoutSurface(const VolumeFluid &sim, float absorption=5.f)
Renders every material phase as a blurred color/thickness volume without reconstructing a surface.
Definition VolumeFluidSurface.cpp:264
Result< void > configureRefractionEnabled(bool enabled)
Enables or disables Fluid3D's configured refraction stage without losing its controls.
Definition VolumeFluidSurface.cpp:41
void renderVolumeColorOnly(const VolumeFluid &sim)
Reconstructs only the RGBA output for display, skipping auxiliary GPU readback when color is uniform.
Definition VolumeFluidSurface.cpp:16
Result< void > renderConfiguredVolume(const VolumeFluid &sim)
Renders through Fluid3D's configured generateSurface policy.
Definition VolumeFluidSurface.cpp:268
CPU position-based free-volume fluid with a bounded spatial grid. @ownership Owns all particle state;...
Definition VolumeFluid.h:517
@ InvalidArgument
@ PreconditionViolation
float thicknessScale
Definition FluidSurfaceRenderer.h:76
float orthographicSize
Definition FluidSurfaceRenderer.h:67
Owning particle value with world position and velocity in SI units.
Definition VolumeFluid.h:96