载入中...
搜索中...
未找到
ScreenSpaceReflection.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <string>
6
7#include <glm/mat4x4.hpp>
8#include <glm/vec3.hpp>
9
10namespace eve::graphics {
11
12class Canvas;
13class Graphics;
14class Shader;
15class Texture;
16
31public:
33 explicit ScreenSpaceReflection(Graphics *gfx);
36
39
41 void setCamera(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ,
42 float upX, float upY, float upZ, float fovYDeg, float aspect, float nearZ,
43 float farZ);
45 void setInvViewProj(const glm::mat4 &invViewProj);
47 void setTemporalMotionTexture(Texture *motionDepth) { temporalMotionDepth_ = motionDepth; }
49 void setDepthPyramid(Texture *atlas, int levels) {
50 depthPyramid_ = atlas;
51 depthPyramidLevels_ = levels;
52 }
54 void invalidateHistory() { historyValid_ = false; }
55
57 void setEnabled(bool enabled);
59 bool getEnabled() const { return enabled_; }
60
62 void setQuality(const std::string &quality);
64 std::string getQuality() const { return quality_; }
65
67 void setMaxDistance(float meters);
69 void setStepLength(float meters);
71 void setMaxSteps(int steps);
73 void setThickness(float meters);
75 void setStrength(float strength);
77 void setMaxRoughness(float roughness);
79 void setResolutionScale(float scale);
81 float getStrength() const { return strength_; }
83 float getMaxRoughness() const { return maxRoughness_; }
85 float getResolutionScale() const { return resolutionScale_; }
86
88 bool hasParam(const std::string &name) const;
90 void setFloat(const std::string &name, float value);
92 float getFloat(const std::string &name) const;
93
95 void applyFromSceneTo(Graphics *gfx, Texture *sceneColor, Texture *hwDepth,
96 Texture *worldNormal, Canvas *dest) {
98 applyFromSceneTo(gfx, sceneColor, hwDepth, worldNormal, nullptr, dest);
99 }
101 void applyFromSceneTo(Graphics *gfx, Texture *sceneColor, Texture *hwDepth,
102 Texture *worldNormal, Texture *albedo, Canvas *dest);
104 void applyFromScene(Graphics *gfx, Texture *sceneColor, Texture *hwDepth,
105 Texture *worldNormal, Texture *albedo = nullptr);
106
108 Canvas *getReflectionCanvas();
110 Texture *getReflectionTexture();
112 bool hasValidHistory() const { return historyValid_ && historyRead_ != nullptr; }
115 return quality_ == "ultra" ? 3 : quality_ == "high" ? 2 : quality_ == "medium" ? 1 : 0;
116 }
117
119 Shader *getShader() const { return ssr_; }
120
121private:
122 void uploadUniforms(int width, int height);
123 void ensureHistory(int width, int height);
124 void resolveTemporal(Graphics *gfx, Texture *current, Texture *motionDepth);
125
126 Graphics *gfx_ = nullptr;
127 Shader *ssr_ = nullptr;
128 Shader *temporal_ = nullptr;
129 Canvas *reflection_ = nullptr;
130 Canvas *historyA_ = nullptr;
131 Canvas *historyB_ = nullptr;
132 Canvas *historyRead_ = nullptr;
133 Canvas *historyWrite_ = nullptr;
134 Canvas *spatialA_ = nullptr;
135 Canvas *spatialB_ = nullptr;
136 Texture *temporalMotionDepth_ = nullptr;
137 Texture *depthPyramid_ = nullptr;
138 int depthPyramidLevels_ = 0;
139 glm::mat4 invViewProj_{1.f};
140 glm::mat4 previousViewProj_{1.f};
141 glm::vec3 previousEye_{0.f};
142 glm::vec3 previousForward_{0.f, 0.f, -1.f};
143 float previousFovY_ = 0.f;
144 float previousAspect_ = 1.f;
145 bool historyValid_ = false;
146 bool viewProjValid_ = false;
147 bool cameraValid_ = false;
148 int historyWidth_ = 0;
149 int historyHeight_ = 0;
150 float nearZ_ = 0.1f;
151 float farZ_ = 100.f;
152 bool enabled_ = true;
153 std::string quality_ = "medium";
154 float maxDist_ = 60.f;
155 float stepLen_ = 0.4f;
156 float maxSteps_ = 96.f;
157 float thickness_ = 0.5f;
158 float strength_ = 0.9f;
159 float bias_ = 0.0005f;
160 float maxRoughness_ = 0.8f;
161 float resolutionScale_ = 1.f;
162 float temporalCurrentWeight_ = 0.16f;
163 float spatialFilterStrength_ = 0.5f;
164};
165
166} // namespace eve::graphics
double value
graphics::Texture * albedo
#define EVENGINE_API_BACKENDS
Definition Export.h:108
std::uint32_t height
std::uint32_t width
std::array< float, 3 > scale
std::string name
float roughness
int steps
double current
float targetX
Canvas public API.
Definition Canvas.h:17
Screen-space reflections (SSR) as a fullscreen post pass. @lifetime All Graphics and texture argument...
float getMaxRoughness() const
Returns the max roughness.
std::string getQuality() const
Return the active SSR quality preset.
void invalidateHistory()
Discard temporal reflection history after a render-chain discontinuity.
void applyFromSceneTo(Graphics *gfx, Texture *sceneColor, Texture *hwDepth, Texture *worldNormal, Canvas *dest)
Write the SSR result into the currently bound canvas / dest.
float getStrength() const
Returns the strength.
bool hasValidHistory() const
True once a temporally resolved reflection frame is safe to sample.
float getResolutionScale() const
Returns the resolution scale.
ScreenSpaceReflection(const ScreenSpaceReflection &)=delete
bool getEnabled() const
Returns the enabled.
int getSpatialPassCount() const
Number of explicit A-trous prefilter passes for the active quality.
Shader * getShader() const
Returns the shader.
void setDepthPyramid(Texture *atlas, int levels)
Set the shared horizontally packed RG min/max depth hierarchy.
ScreenSpaceReflection & operator=(const ScreenSpaceReflection &)=delete
void setTemporalMotionTexture(Texture *motionDepth)
Set packed linear-depth and motion texture used by temporal SSR resolve.
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
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
bool enabled
glm::mat4 invViewProj