载入中...
搜索中...
未找到
Volumetric.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Result.h"
7
8#include <string>
9#include <memory>
10#include <vector>
11#include <glm/mat4x4.hpp>
12#include <glm/vec3.hpp>
13
14namespace eve::graphics {
15
16class Canvas;
17class FogVolume;
18class Drawable;
19class Graphics;
20class Light2D;
21class Light3D;
22class Mesh;
23class Shader;
24class Texture;
25
39public:
41 explicit Volumetric(Graphics *gfx);
44
45 Volumetric(const Volumetric &) = delete;
46 Volumetric &operator=(const Volumetric &) = delete;
47
49 void setQuality(const std::string &quality);
51 std::string getQuality() const { return quality_; }
52
54 void setMode(const std::string &mode);
56 std::string getMode() const { return mode_; }
57
59 void setLightScreenUV(float u, float v);
61 float getLightScreenU() const;
63 float getLightScreenV() const;
64
66 void setLightScreenPos(float x, float y, float width, float height);
67
69 void setLightDirection(float dx, float dy, float dz);
70
75 void setCamera(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ,
76 float upX, float upY, float upZ, float fovYDeg, float aspect, float nearZ,
77 float farZ);
78
80 void setInvViewProj(const glm::mat4 &invViewProj);
81
83 void setShaftColor(float r, float g, float b);
85 void setFogColor(float r, float g, float b);
87 void setIntensity(float intensity);
89 void setTime(float seconds);
91 void setDensity(float density);
92
97 void setAnisotropy(float g);
99 float getAnisotropy() const;
100
102 void setFogHeight(float worldY);
104 void setFogHeightFalloff(float falloff);
106 void setFogStart(float startDistance);
108 void setFogEnd(float endDistance);
110 void setFogNoise(float amount);
111
113 void setCloudLayer(float bottom, float top);
115 void setCloudCoverage(float coverage);
117 void setCloudDensity(float density);
119 void setCloudScale(float worldScale);
121 void setCloudWind(float x, float z);
123 void setCloudLightColor(float r, float g, float b);
124
126 bool hasParam(const std::string &name) const;
128 void setFloat(const std::string &name, float value);
130 float getFloat(const std::string &name) const;
131
133 int getSampleCount() const;
135 float getDownscale() const { return downscale_; }
136
141 void beginOcclusionMap(Graphics *gfx, float lightPixelX, float lightPixelY,
142 float lightRadiusPixels = 24.f);
143
145 void drawOccluder(Graphics *gfx, Drawable *drawable, const glm::mat4 &matrix);
146
148 void drawOccluderSolid(Graphics *gfx, float x, float y, float w, float h);
150 void drawOccluderTexture(Graphics *gfx, Texture *texture, float x, float y, float w, float h);
151
156 void scatter(Graphics *gfx, Texture *occlusion);
157
159 void scatterTo(Graphics *gfx, Texture *occlusion, Canvas *dest);
160
165 void applyFromScene(Graphics *gfx, Texture *scene);
167 void applyFromSceneTo(Graphics *gfx, Texture *scene, Canvas *dest);
168
174 void rayMarch(Graphics *gfx, Texture *linearDepth);
176 void rayMarchTo(Graphics *gfx, Texture *linearDepth, Canvas *dest);
177
183 void applyFog(Graphics *gfx, Texture *linearDepth);
185 void applyFogTo(Graphics *gfx, Texture *linearDepth, Canvas *dest);
186
197 [[nodiscard]] Result<void> projectDirectionalCookie(Graphics *gfx, Texture *depth,
198 Texture *cookie, float worldSize,
199 float intensity = 1.f);
200
202 void renderClouds(Graphics *gfx, Texture *linearDepth);
204 void renderCloudsTo(Graphics *gfx, Texture *linearDepth, Canvas *dest);
205
210 void configureFroxelGrid(int width, int height, int depth, float nearDistance,
211 float farDistance);
213 AtmosphereVolume *getAtmosphereVolume() const { return atmosphereVolume_.get(); }
215 const glm::mat4 &getInvViewProj() const { return invViewProj_; }
217 void clearFroxelGrid();
219 void injectFroxelHeightFog(float extinction, float albedoR, float albedoG, float albedoB,
220 float baseHeight, float heightFalloff, float minWorldY,
221 float maxWorldY);
223 void injectFroxelLocalVolume(FogVolume *volume);
225 void integrateFroxel(float lightR, float lightG, float lightB, float phaseScale = 1.f);
226
234 [[nodiscard]] Result<int> collectSceneLights3D(std::vector<VolumetricLight> &out,
235 int maxCount = 32);
236
246 [[nodiscard]] Result<void> driveFromLight3D(Light3D *light, float viewportW, float viewportH);
247
252 [[nodiscard]] Result<void> driveFromPrimarySceneLight3D(float viewportW, float viewportH);
253
260 [[nodiscard]] Result<void> integrateFroxelFromSceneLights(float ambientR, float ambientG,
261 float ambientB,
262 const glm::vec3 &worldMin,
263 const glm::vec3 &worldMax,
264 int maxLights = 16);
265
272 [[nodiscard]] Result<int> beginOcclusionMapFromSceneLights2D(Graphics *gfx,
273 Canvas *canvasFilter = nullptr,
274 float defaultRadiusPixels = 24.f);
275
284 [[nodiscard]] Result<int> scatterFromSceneLights2D(Graphics *gfx, Texture *occlusion,
285 Canvas *canvasFilter = nullptr);
286
291 [[nodiscard]] Result<void> injectEmissiveLightProxy(float x, float y, float z, float r, float g,
292 float b, float radius, float intensity);
293
295 void uploadFroxel(Graphics *gfx);
297 void applyFroxel(Graphics *gfx, Texture *linearDepth);
299 void applyFroxelTo(Graphics *gfx, Texture *linearDepth, Canvas *dest);
300
305 Texture *newLinearDepthTexture(Graphics *gfx, int width, int height,
307 float (*depth01)(int x, int y, void *userdata), void *userdata);
308
314 int resolutionFor(int fullSize) const;
315
320 void drawOccluders2D(Graphics *gfx);
321
323 Shader *getShader() const { return shader_; }
325 Shader *getRayMarchShader() const { return rayShader_; }
327 Shader *getFogShader() const { return fogShader_; }
329 Shader *getCloudShader() const { return cloudShader_; }
331 Shader *getFroxelShader() const { return froxelShader_; }
333 Texture *getFroxelAtlas() const { return froxelAtlas_; }
334
335private:
336 void applyQualityDefaults();
337 void uploadCommon(bool compositeFromScene);
338 void uploadRayMarchCommon();
339 void uploadFogCommon();
340 void uploadCloudCommon();
341 void drawFullscreen(Graphics *gfx, Texture *source, Shader *shader);
342 void uploadRayMarchShadowAnisotropy();
343 void clearPendingEmissiveProxies();
344
345 Graphics *gfx_ = nullptr; // not owned
346 Shader *shader_ = nullptr; // owned by Graphics (screenspace)
347 Shader *rayShader_ = nullptr; // owned by Graphics (ray march)
348 Shader *fogShader_ = nullptr; // owned by Graphics (volumetric fog)
349 Shader *directionalCookieShader_ = nullptr; // owned by Graphics
350 Shader *cloudShader_ = nullptr; // owned by Graphics (volumetric clouds)
351 Shader *froxelShader_ = nullptr; // owned by Graphics (froxel atlas composite)
352 std::unique_ptr<AtmosphereVolume> atmosphereVolume_;
353 Texture *froxelAtlas_ = nullptr; // owned by Graphics
354 int froxelAtlasCols_ = 1;
355 int froxelAtlasRows_ = 1;
356 std::string quality_ = "medium";
357 std::string mode_ = "screenspace";
358 float downscale_ = 2.f;
359 glm::mat4 invViewProj_{1.f};
360 float nearZ_ = 0.1f;
361 float farZ_ = 100.f;
362 glm::vec3 lightDir_{0.4f, 1.f, 0.3f};
363 float anisotropy_ = 0.6f;
364 float fogHeight_ = 0.f;
365 float fogHeightFalloff_ = 0.15f;
366 float fogStart_ = 2.f;
367 float fogEnd_ = 40.f;
368 float fogNoise_ = 0.35f;
369 float cloudBottom_ = 8.f;
370 float cloudTop_ = 16.f;
371 float cloudCoverage_ = 0.55f;
372 float cloudDensity_ = 1.f;
373 float cloudScale_ = 18.f;
374 glm::vec3 cloudWind_{1.5f, 0.f, 0.4f};
375 glm::vec3 cloudLightColor_{1.f, 0.92f, 0.78f};
376 std::vector<VolumetricLight> pendingEmissiveProxies_;
377};
378
379} // namespace eve::graphics
double value
SQInteger top
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
double volume
#define EVENGINE_API_BACKENDS
Definition Export.h:108
tensor::Graph g
Definition GpuGraph.cpp:7
float u
Definition Grass.cpp:233
double r
float v
int h
std::uint32_t height
std::uint32_t width
std::string name
MeleePoint3 b
Definition MeleeHit.cpp:41
float radius
std::weak_ptr< PrimitiveScene > scene
Shader * shader
float ambientG
float ambientR
float ambientB
Move-only, checked operation results for the common layer.
float dz
Light3D::Data * light
float dy
float dx
Vec extinction
float targetX
const UnitySourceAsset & source
std::uint32_t depth
float bottom
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Camera-frustum volume used by the volumetric fog passes and CPU references.
Canvas public API.
Definition Canvas.h:17
Drawable base (textures, meshes, canvases).
Definition Drawable.h:17
Analytic local participating-media volume injected into atmospheric fog.
Definition FogVolume.h:12
Declarative 3D light. Collected by RenderSystem3D (max 8 per frame). type: "point" | "dir" | "spot" (...
Definition Light.h:191
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
Volumetric light + fog.
Definition Volumetric.h:38
Volumetric & operator=(const Volumetric &)=delete
Shader * getCloudShader() const
Returns the cloud shader.
Definition Volumetric.h:329
Volumetric(const Volumetric &)=delete
float getDownscale() const
Returns the downscale.
Definition Volumetric.h:135
Shader * getShader() const
Returns the shader.
Definition Volumetric.h:323
std::string getMode() const
Returns the mode.
Definition Volumetric.h:56
std::string getQuality() const
Returns the quality.
Definition Volumetric.h:51
const glm::mat4 & getInvViewProj() const
Inverse view-projection last written by setCamera / setInvViewProj.
Definition Volumetric.h:215
Shader * getFroxelShader() const
Returns the froxel shader.
Definition Volumetric.h:331
AtmosphereVolume * getAtmosphereVolume() const
Access the froxel media grid for native density/light injection.
Definition Volumetric.h:213
Shader * getRayMarchShader() const
Returns the ray march shader.
Definition Volumetric.h:325
Texture * getFroxelAtlas() const
Returns the froxel atlas.
Definition Volumetric.h:333
Shader * getFogShader() const
Returns the fog shader.
Definition Volumetric.h:327
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
glm::mat4 invViewProj