载入中...
搜索中...
未找到
Volumetric.h
浏览该文件的文档.
1#pragma once
2
3#include <string>
4#include <glm/mat4x4.hpp>
5#include <glm/vec3.hpp>
6
7namespace eve::graphics {
8
9class Canvas;
10class Drawable;
11class Graphics;
12class Mesh;
13class Shader;
14class Texture;
15
28public:
29 explicit Volumetric(Graphics *gfx);
31
32 Volumetric(const Volumetric &) = delete;
33 Volumetric &operator=(const Volumetric &) = delete;
34
36 void setQuality(const std::string &quality);
37 std::string getQuality() const { return quality_; }
38
40 void setMode(const std::string &mode);
41 std::string getMode() const { return mode_; }
42
44 void setLightScreenUV(float u, float v);
45 float getLightScreenU() const;
46 float getLightScreenV() const;
47
49 void setLightScreenPos(float x, float y, float width, float height);
50
52 void setLightDirection(float dx, float dy, float dz);
53
58 void setCamera(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ,
59 float upX, float upY, float upZ, float fovYDeg, float aspect, float nearZ,
60 float farZ);
61
63 void setInvViewProj(const glm::mat4 &invViewProj);
64
65 void setShaftColor(float r, float g, float b);
66 void setFogColor(float r, float g, float b);
67 void setIntensity(float intensity);
68 void setTime(float seconds);
69 void setDensity(float density);
70
72 void setFogHeight(float worldY);
73 void setFogHeightFalloff(float falloff);
75 void setFogStart(float startDistance);
76 void setFogEnd(float endDistance);
77 void setFogNoise(float amount);
78
79 bool hasParam(const std::string &name) const;
80 void setFloat(const std::string &name, float value);
81 float getFloat(const std::string &name) const;
82
83 int getSampleCount() const;
84 float getDownscale() const { return downscale_; }
85
90 void beginOcclusionMap(Graphics *gfx, float lightPixelX, float lightPixelY,
91 float lightRadiusPixels = 24.f);
92
94 void drawOccluder(Graphics *gfx, Drawable *drawable, const glm::mat4 &matrix);
95
97 void drawOccluderSolid(Graphics *gfx, float x, float y, float w, float h);
98 void drawOccluderTexture(Graphics *gfx, Texture *texture, float x, float y, float w, float h);
99
104 void scatter(Graphics *gfx, Texture *occlusion);
105
107 void scatterTo(Graphics *gfx, Texture *occlusion, Canvas *dest);
108
113 void applyFromScene(Graphics *gfx, Texture *scene);
114 void applyFromSceneTo(Graphics *gfx, Texture *scene, Canvas *dest);
115
121 void rayMarch(Graphics *gfx, Texture *linearDepth);
122 void rayMarchTo(Graphics *gfx, Texture *linearDepth, Canvas *dest);
123
129 void applyFog(Graphics *gfx, Texture *linearDepth);
130 void applyFogTo(Graphics *gfx, Texture *linearDepth, Canvas *dest);
131
137 float (*depth01)(int x, int y, void *userdata), void *userdata);
138
144 int resolutionFor(int fullSize) const;
145
150 void drawOccluders2D(Graphics *gfx);
151
152 Shader *getShader() const { return shader_; }
153 Shader *getRayMarchShader() const { return rayShader_; }
154 Shader *getFogShader() const { return fogShader_; }
155
156private:
157 void applyQualityDefaults();
158 void uploadCommon(bool compositeFromScene);
159 void uploadRayMarchCommon();
160 void uploadFogCommon();
161 void drawFullscreen(Graphics *gfx, Texture *source, Shader *shader);
162
163 Graphics *gfx_ = nullptr; // not owned
164 Shader *shader_ = nullptr; // owned by Graphics (screenspace)
165 Shader *rayShader_ = nullptr; // owned by Graphics (ray march)
166 Shader *fogShader_ = nullptr; // owned by Graphics (volumetric fog)
167 std::string quality_ = "medium";
168 std::string mode_ = "screenspace";
169 float downscale_ = 2.f;
170 glm::mat4 invViewProj_{1.f};
171 float nearZ_ = 0.1f;
172 float farZ_ = 100.f;
173 glm::vec3 lightDir_{0.4f, 1.f, 0.3f};
174 float fogHeight_ = 0.f;
175 float fogHeightFalloff_ = 0.15f;
176 float fogStart_ = 2.f;
177 float fogEnd_ = 40.f;
178 float fogNoise_ = 0.35f;
179};
180
181} // namespace eve::graphics
std::string value
int y
Definition Grass.cpp:135
float height
Definition Grass.cpp:235
float u
Definition Grass.cpp:234
int x
Definition Grass.cpp:135
int h
int w
uint32_t b
int width
Shader * shader
const char * name
Definition RockMesh.cpp:21
int v
Drawable base (textures, meshes, canvases).
Definition Drawable.h:17
Custom GPU program.
Definition Shader.h:30
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:17
Volumetric light + fog.
Definition Volumetric.h:27
void scatter(Graphics *gfx, Texture *occlusion)
Scatter-only: occlusion → shafts with alpha (draw over a prior scene). Writes to the currently bound ...
void scatterTo(Graphics *gfx, Texture *occlusion, Canvas *dest)
Same as scatter but into an explicit destination.
Volumetric & operator=(const Volumetric &)=delete
float getFloat(const std::string &name) const
void setFogNoise(float amount)
void drawOccluder(Graphics *gfx, Drawable *drawable, const glm::mat4 &matrix)
Drawable occlusion (respects Drawable::getCastOcclusion).
void setMode(const std::string &mode)
"screenspace" | "raymarch" | "fog" — selects which shader params quality tweaks.
void setLightScreenPos(float x, float y, float width, float height)
Pixel-space helper (converts with width/height).
void setFogEnd(float endDistance)
void beginOcclusionMap(Graphics *gfx, float lightPixelX, float lightPixelY, float lightRadiusPixels=24.f)
Clear the current canvas to black and draw a bright light disc (start of an occlusion map)....
void applyFromScene(Graphics *gfx, Texture *scene)
Single-pass: treat source as the scene (bright regions ≈ light), add shafts + dust/fog onto it....
Volumetric(const Volumetric &)=delete
void drawOccluders2D(Graphics *gfx)
Draw all visible Renderable2D with castOcclusion into the current canvas as black silhouettes (shadow...
void rayMarchTo(Graphics *gfx, Texture *linearDepth, Canvas *dest)
void setFogHeightFalloff(float falloff)
float getDownscale() const
Definition Volumetric.h:84
void setLightScreenUV(float u, float v)
Light position in UV (0..1), origin top-left to match 2D UVs.
void rayMarch(Graphics *gfx, Texture *linearDepth)
Ray march participating media using a linear-depth texture (R channel, 0=near .. 1=far)....
Shader * getShader() const
Definition Volumetric.h:152
void setCamera(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ, float fovYDeg, float aspect, float nearZ, float farZ)
Camera for ray march reconstruction (RH + ZO). Builds inv(viewProj) and near/far used by rayMarch*.
std::string getMode() const
Definition Volumetric.h:41
void setInvViewProj(const glm::mat4 &invViewProj)
Raw inverse view-projection (column-major, matching glm).
void setIntensity(float intensity)
bool hasParam(const std::string &name) const
std::string getQuality() const
Definition Volumetric.h:37
float getLightScreenU() const
void setLightDirection(float dx, float dy, float dz)
World-space direction toward the lit surface (ray march / phase).
void setTime(float seconds)
void setFloat(const std::string &name, float value)
void setShaftColor(float r, float g, float b)
void setQuality(const std::string &quality)
"low" | "medium" | "high" (unknown → medium).
Texture * newLinearDepthTexture(Graphics *gfx, int width, int height, float(*depth01)(int x, int y, void *userdata), void *userdata)
Build an RGBA8 texture with linear depth in R (G=B=R, A=255). depth01(x,y) should return values in [0...
void setFogHeight(float worldY)
Height fog: denser near world Y = fogHeight; falloff is 1/meters scale.
void applyFromSceneTo(Graphics *gfx, Texture *scene, Canvas *dest)
float getLightScreenV() const
void applyFogTo(Graphics *gfx, Texture *linearDepth, Canvas *dest)
void setDensity(float density)
void drawOccluderTexture(Graphics *gfx, Texture *texture, float x, float y, float w, float h)
void setFogStart(float startDistance)
View-distance ramp where fog appears (world units along the ray).
void applyFog(Graphics *gfx, Texture *linearDepth)
Volumetric height/distance fog from a linear-depth texture. Writes fog RGB with alpha = 1-transmittan...
Shader * getRayMarchShader() const
Definition Volumetric.h:153
void drawOccluderSolid(Graphics *gfx, float x, float y, float w, float h)
Convenience 2D black silhouette (solid or textured alpha).
int resolutionFor(int fullSize) const
Downscale helper: returns floor(dim / downscale), at least 1. Callers create occlusion / scatter canv...
Shader * getFogShader() const
Definition Volumetric.h:154
void setFogColor(float r, float g, float b)
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition AnimTrail.h:6