载入中...
搜索中...
未找到
FluidSurfaceBlend.cpp
浏览该文件的文档.
2
3#include <algorithm>
4
5namespace eve::fluids {
6
7glm::vec4 FluidSurfaceRenderer::blendFluidColor(FluidBlendFactor factor, const glm::vec4& source,
8 const glm::vec4& destination) {
9 switch (factor) {
10 case FluidBlendFactor::Zero: return glm::vec4(0.f);
11 case FluidBlendFactor::One: return glm::vec4(1.f);
12 case FluidBlendFactor::DestinationColor: return destination;
14 case FluidBlendFactor::OneMinusDestinationColor: return glm::vec4(1.f) - destination;
15 case FluidBlendFactor::SourceAlpha: return glm::vec4(source.a);
16 case FluidBlendFactor::OneMinusSourceColor: return glm::vec4(1.f) - source;
17 case FluidBlendFactor::DestinationAlpha: return glm::vec4(destination.a);
18 case FluidBlendFactor::OneMinusDestinationAlpha: return glm::vec4(1.f - destination.a);
20 const float saturated = std::min(source.a, 1.f - destination.a);
21 return glm::vec4(saturated, saturated, saturated, 1.f);
22 }
23 case FluidBlendFactor::OneMinusSourceAlpha: return glm::vec4(1.f - source.a);
24 }
25 return glm::vec4(0.f);
26}
27
30 destination < int(FluidBlendFactor::Zero) || destination > int(FluidBlendFactor::OneMinusSourceAlpha))
32 DiagnosticCode::InvalidArgument, "Fluid surface blend factors must be Unity BlendMode values in [0,10]",
33 "fluids.surface.blend"));
34 surfaceBlendSource_ = static_cast<FluidBlendFactor>(source);
35 surfaceBlendDestination_ = static_cast<FluidBlendFactor>(destination);
36 return Result<void>::success();
37}
38
40 const size_t expected = size_t(params_.width) * size_t(params_.height) * 4u;
41 if (!auxiliaryCurrent_ || residentColorCurrent_)
43 "Current fluid frame has no host-visible surface color",
44 "fluids.surface.blend"));
45 if (sceneColor.size() != expected)
47 "Surface blend requires a matching RGBA8 scene image",
48 "fluids.surface.blend"));
49
50 for (size_t offset = 0; offset < expected; offset += 4u) {
51 glm::vec4 source, destination;
52 for (size_t channel = 0; channel < 4u; ++channel) {
53 const auto component = static_cast<glm::vec4::length_type>(channel);
54 source[component] = float(color_[offset + channel]) / 255.f;
55 destination[component] = float(sceneColor[offset + channel]) / 255.f;
56 }
57 const glm::vec4 blended =
58 glm::clamp(source * blendFluidColor(surfaceBlendSource_, source, destination) +
59 destination * blendFluidColor(surfaceBlendDestination_, source, destination),
60 glm::vec4(0.f), glm::vec4(1.f));
61 for (size_t channel = 0; channel < 4u; ++channel)
62 color_[offset + channel] =
63 uint8_t(blended[static_cast<glm::vec4::length_type>(channel)] * 255.f + .5f);
64 }
65 residentColorCurrent_ = false;
66 return Result<void>::success();
67}
68
71 destination < int(FluidBlendFactor::Zero) || destination > int(FluidBlendFactor::OneMinusSourceAlpha))
73 DiagnosticCode::InvalidArgument, "Fluid particle blend factors must be Unity BlendMode values in [0,10]",
74 "fluids.surface.particleBlend"));
75 particleBlendSource_ = static_cast<FluidBlendFactor>(source);
76 particleBlendDestination_ = static_cast<FluidBlendFactor>(destination);
77 particleDepthWrite_ = depthWrite;
78 particleBlendConfigured_ = true;
79 return Result<void>::success();
80}
81
82} // namespace eve::fluids
size_t offset
const UnitySourceAsset & source
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Result< void > configureSurfaceBlend(int source, int destination)
Atomically configures Fluid3D's final surface source and destination blend factors.
Result< void > compositeConfiguredSurfaceBlend(std::span< const uint8_t > sceneColor)
Composites the current surface over a matching RGBA8 scene using the configured Fluid3D factors.
Result< void > configureParticleBlend(int source, int destination, bool depthWrite)
Configures Fluid3D's particle-color target blending and depth writes atomically.
GLSL compute kernels for the GPU surface-flow solver.
Definition FluidTarget.h:12
FluidBlendFactor
Unity/Fluid3D blend factors used by fluid render settings.