载入中...
搜索中...
未找到
Water.h
浏览该文件的文档.
1#pragma once
2
3#include "graphics/Shader.h"
5
6#include <cstdint>
7#include <string>
8#include <vector>
9
10#include <glm/glm.hpp>
11
12namespace eve::graphics {
13
15enum class WaterMeshType : std::uint8_t { Plane = 0, Circle = 1 };
16
19 float sizeX = 200.0F;
20 float sizeY = 30.0F;
21 float sizeZ = 200.0F;
22 float densityX = 50.0F;
23 float densityY = 50.0F;
24 float height = 0.0F;
26};
27
30
31class Graphics;
32class Mesh;
33class Texture;
34
36struct WaterGradientColorStop { float time = 0.0F; glm::vec3 color{0.0F}; };
38struct WaterGradientAlphaStop { float time = 0.0F; float alpha = 1.0F; };
39
42 std::vector<WaterGradientColorStop> colorStops;
43 std::vector<WaterGradientAlphaStop> alphaStops;
45 [[nodiscard]] Result<void> addColorStop(float time, float red, float green, float blue);
47 [[nodiscard]] Result<void> addAlphaStop(float time, float alpha);
49 void clear();
50};
51
69public:
71 explicit Water(Graphics *gfx);
73 ~Water();
74
75 Water(const Water &) = delete;
76 Water &operator=(const Water &) = delete;
77
79 void createPlane(float sizeX, float sizeZ, int segX, int segZ);
80
87 [[nodiscard]] Result<int> createProceduralMesh(const WaterMeshSettings& settings);
88
90 void update(float dt);
92 void setTime(float seconds);
94 float getTime() const { return time_; }
95
96 // --- Animation / material knobs ---
98 void setWaveSpeed(float speed);
100 float getWaveSpeed() const { return config_.waveSpeed; }
101
103 void setWaveAmplitude(float amp);
105 float getWaveAmplitude() const { return config_.waveAmplitude; }
106
108 void setRippleAmplitude(float amp);
110 float getRippleAmplitude() const { return config_.rippleAmplitude; }
111
113 void setEdgeFalloff(float edge);
115 float getEdgeFalloff() const { return config_.foamWidth; }
116
118 void setRippleCount(int count);
120 int getRippleCount() const { return config_.rippleCount; }
121
123 void setRippleInterval(float seconds);
125 float getRippleInterval() const { return config_.rippleInterval; }
126
128 void setWaveScale(float scale);
130 float getWaveScale() const { return config_.waveScale; }
131
133 [[nodiscard]] Result<void> setWaveDirectionAngle(float degrees);
135 float getWaveDirectionAngle() const { return waveDirectionAngle_; }
136
144 [[nodiscard]] Result<int> setDepthGradient(const WaterDepthGradient& gradient, int resolution);
146 Texture* getDepthGradientTexture() const { return depthGradientTexture_; }
148 void clearDepthGradient() { depthGradientTexture_ = nullptr; }
149
151 void setWaterColor(float r, float g, float b);
153 void setReflectionTint(float r, float g, float b);
155 void setReflectionIntensity(float intensity);
157 float getReflectionIntensity() const { return config_.reflectionIntensity; }
158
160 void setSunIntensity(float intensity);
162 float getSunIntensity() const { return config_.sunIntensity; }
163
171 void setScreenSpaceReflection(bool enabled, float strength = 0.85f);
173 bool getScreenSpaceReflection() const { return config_.screenSpaceReflection; }
175 float getScreenSpaceReflectionStrength() const { return config_.screenSpaceReflectionStrength; }
176
183 [[nodiscard]] Result<void> applyConfigJson(const std::string& json);
185 [[nodiscard]] Result<std::string> configJson() const;
187 WaterStyleConfig config() const { return config_; }
188
190 void setViewport(float width, float height);
192 float getViewportWidth() const { return viewportW_; }
194 float getViewportHeight() const { return viewportH_; }
195
197 void bindParams();
198
200 void draw();
201
210 void drawWithPlanarReflection(Texture* planarReflection, float strength = 1.0F);
211
213 void setReflectionCaptureEnabled(bool enabled) { reflectionCaptureEnabled_ = enabled; }
215 bool getReflectionCaptureEnabled() const { return reflectionCaptureEnabled_; }
217 void setReflectionCaptureMask(uint32_t mask) { reflectionCaptureMask_ = mask; }
219 uint32_t getReflectionCaptureMask() const { return reflectionCaptureMask_; }
220
222 Shader *getShader() const { return shader_; }
224 Mesh *getMesh() const { return mesh_; }
225
227 static int paramCount();
229 static std::string paramName(int index);
230
231private:
232 void drawWithReflection(Texture* reflection, float strength);
233 void drawReflectionCapture();
234
235 Graphics *gfx_ = nullptr;
236 Shader *shader_ = nullptr;
237 Mesh *mesh_ = nullptr;
238
239 float time_ = 0.f;
240 float waveDirectionAngle_ = 0.0F;
241 Texture* depthGradientTexture_ = nullptr;
242 WaterStyleConfig config_;
243 float viewportW_ = 0.f;
244 float viewportH_ = 0.f;
245 uint64_t captureDrawerToken_ = 0;
246 uint32_t reflectionCaptureMask_ = 0xffffffffu;
247 bool reflectionCaptureEnabled_ = true;
248};
249
251Shader *newWaterShader(Graphics *gfx);
252
253} // namespace eve::graphics
int mask
float degrees
Definition CardTypes.cpp:35
#define EVENGINE_API_BACKENDS
Definition Export.h:108
tensor::Graph g
Definition GpuGraph.cpp:7
double r
std::uint32_t height
std::uint32_t width
std::array< float, 3 > scale
MeleePoint3 b
Definition MeleeHit.cpp:41
MeshVfxBatchedDraw draw
const RoadEdge * edge
std::uint32_t count
TerrainThermalSettings settings
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:155
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:25
Custom GPU program.
Definition Shader.h:39
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
Dynamic water surface with sky reflection and animated ripples.
Definition Water.h:68
Mesh * getMesh() const
Returns the mesh.
Definition Water.h:224
float getViewportHeight() const
Returns the viewport height.
Definition Water.h:194
float getSunIntensity() const
Returns the sun intensity.
Definition Water.h:162
Texture * getDepthGradientTexture() const
Return the Graphics-owned current depth-ramp texture, or null when disabled.
Definition Water.h:146
float getTime() const
Returns the time.
Definition Water.h:94
float getWaveDirectionAngle() const
Return the normalized wave direction angle in [0,360).
Definition Water.h:135
Water(const Water &)=delete
uint32_t getReflectionCaptureMask() const
Return the reflection-capture visibility layer mask.
Definition Water.h:219
float getWaveAmplitude() const
Returns the wave amplitude.
Definition Water.h:105
float getRippleAmplitude() const
Returns the ripple amplitude.
Definition Water.h:110
float getReflectionIntensity() const
Returns the reflection intensity.
Definition Water.h:157
int getRippleCount() const
Returns the ripple count.
Definition Water.h:120
float getWaveSpeed() const
Returns the wave speed.
Definition Water.h:100
void setReflectionCaptureMask(uint32_t mask)
Set the reflection-capture visibility layer mask.
Definition Water.h:217
float getEdgeFalloff() const
Returns the edge falloff.
Definition Water.h:115
float getRippleInterval() const
Returns the ripple interval.
Definition Water.h:125
float getViewportWidth() const
Returns the viewport width.
Definition Water.h:192
void setReflectionCaptureEnabled(bool enabled)
Enable or disable inclusion in reflection-probe captures.
Definition Water.h:213
float getScreenSpaceReflectionStrength() const
Returns the screen space reflection strength.
Definition Water.h:175
Water & operator=(const Water &)=delete
bool getScreenSpaceReflection() const
Returns the screen space reflection.
Definition Water.h:173
void clearDepthGradient()
Disable depth-ramp sampling without destroying the Graphics-owned texture.
Definition Water.h:148
Shader * getShader() const
Returns the shader.
Definition Water.h:222
WaterStyleConfig config() const
Return the immutable current configuration snapshot by value.
Definition Water.h:187
float getWaveScale() const
Returns the wave scale.
Definition Water.h:130
bool getReflectionCaptureEnabled() const
Return whether this water surface is included in reflection-probe captures.
Definition Water.h:215
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
Result< int > calculateWaterMeshTriangles(const WaterMeshSettings &settings)
Calculate Pcg PWS_WaterSystem's triangle count without allocating a mesh.
Definition Water.cpp:117
Shader * newWaterShader(Graphics *gfx)
Create the embedded water fragment shader (owned by Graphics).
Definition Water.cpp:129
WaterMeshType
Pcg procedural water mesh shape. Custom meshes remain caller-supplied Mesh resources.
Definition Water.h:15
bool enabled
Caller-owned color and alpha keys used to bake a water depth-ramp texture.
Definition Water.h:41
std::vector< WaterGradientAlphaStop > alphaStops
Definition Water.h:43
std::vector< WaterGradientColorStop > colorStops
Definition Water.h:42
One linear alpha stop in a Pcg-compatible water depth gradient.
Definition Water.h:38
One linear RGB stop in a Pcg-compatible water depth gradient.
Definition Water.h:36
Authored dimensions and density for Pcg-compatible procedural water geometry.
Definition Water.h:18
Versioned, backend-neutral configuration for the built-in stylized water surface.