载入中...
搜索中...
未找到
RenderControl.cpp
浏览该文件的文档.
2
3#include "common/Diagnostic.h"
6#include "graphics/Graphics.h"
8
9namespace eve::graphics {
10namespace {
11
12const char* kKnownFeatures[] = {"depthTest",
13 "shadow",
14 "gbuffer",
15 "gbufferAlbedo",
16 "forward",
17 "hair",
18 "clustered",
19 "clusteredDeferred",
20 "ao",
21 "gi",
22 "aa",
23 "msaa",
24 "rtgi",
25 "taa",
26 "ssr",
27 "reflectionChain",
28 "rtx",
29 "outline",
30 "gpuDriven",
31 "visResolve",
32 "frustumCull",
33 "decal",
34 "atmosphere",
35 "volumetricFog",
36 "fogLocalVolumes",
37 "fogTemporal"};
38
39bool isKnownFeature(const std::string &feature) {
40 for (const char *f : kKnownFeatures) {
41 if (feature == f) return true;
42 }
43 return false;
44}
45
46} // namespace
47
49 features_["depthTest"] = true;
50 features_["shadow"] = true;
51 features_["gbuffer"] = true;
52 features_["gbufferAlbedo"] = true;
53 features_["forward"] = true;
54 features_["hair"] = true;
55 features_["clustered"] = true;
56 features_["clusteredDeferred"] = false;
57 features_["ao"] = true;
58 features_["gi"] = true;
59 features_["rtgi"] = false;
60 features_["aa"] = true;
61 features_["taa"] = false;
62 features_["ssr"] = false;
63 features_["reflectionChain"] = false;
64 features_["rtx"] = false; // hardware RT reflections (optional; falls back to SSR)
65 features_["msaa"] = true;
66 features_["outline"] = false;
67 features_["gpuDriven"] = false; // stage 1 opt-in; off until runtime-verified
68 features_["visResolve"] = false; // stage 3 opt-in; visibility-buffer resolve
69 features_["frustumCull"] = false; // opt-in: conservative sphere culling in frame prep
70 features_["atmosphere"] = true;
71 features_["volumetricFog"] = false;
72 features_["fogLocalVolumes"] = false;
73 features_["fogTemporal"] = false;
74 lightingMode_ = LightingMode::ForwardPlus;
75 effectiveLightingMode_ = LightingMode::ForwardPlus;
76 hybridLightingFallback_ = false;
77 dirty_ = true;
78 compiled_ = false;
79}
80
82 gfx_ = gfx;
83 gbuffer_.attach(gfx);
84}
85
86bool RenderControl::supports(const std::string &feature) const { return isKnownFeature(feature); }
87
88void RenderControl::syncClusteredDeferredFeature() {
89 features_["clusteredDeferred"] = lightingMode_ == LightingMode::Hybrid;
90}
91
92bool RenderControl::isDeferredLightingAvailable() const { return gfx_ != nullptr && gfx_->supportsDeferredLighting(); }
93
95 if (mode != LightingMode::ForwardPlus && mode != LightingMode::Hybrid) {
97 "graphics.RenderControl.lightingMode"));
98 }
99 if (lightingMode_ == mode) return Result<void>::success();
100 lightingMode_ = mode;
101 syncClusteredDeferredFeature();
102 if (mode == LightingMode::Hybrid) {
103 features_["gbuffer"] = true;
104 features_["gbufferAlbedo"] = true;
105 }
106 dirty_ = true;
107 return Result<void>::success();
108}
109
111 if (name == "forwardPlus" || name == "forward+") return setLightingMode(LightingMode::ForwardPlus);
112 if (name == "hybrid") return setLightingMode(LightingMode::Hybrid);
114 "lighting mode must be \"forwardPlus\" or \"hybrid\"",
115 "graphics.RenderControl.lightingMode"));
116}
117
124
126 if (name == "desktop") return applyLightingPreset(LightingPreset::Desktop);
127 if (name == "mobile") return applyLightingPreset(LightingPreset::Mobile);
128 if (name == "ci") return applyLightingPreset(LightingPreset::Ci);
130 "lighting preset must be \"desktop\", \"mobile\", or \"ci\"",
131 "graphics.RenderControl.lightingPreset"));
132}
133
135 auto presetResult = applyLightingPreset(suggestedLightingPreset());
136 if (!presetResult.ok()) return presetResult;
137 auto envMode = lightingModeFromEnv();
138 if (envMode.ok()) return setLightingMode(envMode.value());
139 return presetResult;
140}
141
142void RenderControl::setFeature(const std::string &feature, bool enabled) {
143 if (!isKnownFeature(feature)) return;
144
145 if (feature == "clusteredDeferred") {
147 setMode.ignore();
148 return;
149 }
150
151 auto it = features_.find(feature);
152 const bool cur = it == features_.end() ? false : it->second;
153 if (cur == enabled) return;
154 features_[feature] = enabled;
155 if (gfx_ && (feature == "ssr" || feature == "rtgi" || feature == "reflectionChain" || feature == "rtx")) {
158 }
159 if (gfx_ && (feature == "taa" || feature == "reflectionChain"))
161 if (feature == "gbufferAlbedo" && enabled) features_["gbuffer"] = true;
162 if (feature == "ao" && enabled) features_["gbuffer"] = true;
163 if (feature == "outline" && enabled) features_["gbuffer"] = true;
164 if (feature == "decal" && enabled) features_["gbuffer"] = true;
165 // Stage 2 GPU cull needs the GBuffer depth as its HZB source.
166 if (feature == "gpuDriven" && enabled) features_["gbuffer"] = true;
167 if ((feature == "ssr" || feature == "rtgi" || feature == "reflectionChain" || feature == "rtx") && enabled)
168 features_["gbuffer"] = true;
169 if (feature == "rtx" && enabled) {
170 // Prefer hardware RT when available; keep SSR as the portable path
171 // that RenderSystem3D can still run when IRayTracing is absent.
172 features_["gbuffer"] = true;
173 }
174 if (feature == "reflectionChain" && enabled) {
175 features_["aa"] = true;
176 features_["taa"] = true;
177 features_["msaa"] = false;
178 features_["rtgi"] = true;
179 features_["ssr"] = true;
180 }
181 if (feature == "reflectionChain" && !enabled) {
182 features_["taa"] = false;
183 features_["rtgi"] = false;
184 features_["ssr"] = false;
185 if (gfx_) gfx_->pipelineScreenSpaceReflection()->setEnabled(false);
186 }
187 if ((feature == "taa" || feature == "rtgi" || feature == "ssr") && !enabled)
188 features_["reflectionChain"] = false;
189 if (feature == "taa" && enabled) {
190 features_["aa"] = true;
191 features_["msaa"] = false;
192 }
193 if ((feature == "volumetricFog" || feature == "fogLocalVolumes" ||
194 feature == "fogTemporal") && enabled) {
195 features_["atmosphere"] = true;
196 features_["volumetricFog"] = true;
197 features_["gbuffer"] = true;
198 }
199 if (feature == "volumetricFog" && !enabled) {
200 features_["fogLocalVolumes"] = false;
201 features_["fogTemporal"] = false;
202 }
203 if (feature == "gi" && enabled) {
204 features_["gbuffer"] = true;
205 features_["gbufferAlbedo"] = true;
206 }
207 if (feature == "gbuffer" && !enabled) {
208 features_["gbufferAlbedo"] = false;
209 features_["ao"] = false;
210 features_["gi"] = false;
211 features_["rtgi"] = false;
212 features_["ssr"] = false;
213 features_["rtx"] = false;
214 features_["reflectionChain"] = false;
215 features_["outline"] = false;
216 features_["decal"] = false;
217 // Hybrid needs GBuffer; keep the request but compile() will fall back.
218 dirty_ = true;
219 return;
220 }
221 dirty_ = true;
222}
223
224void RenderControl::enable(const std::string &feature) { setFeature(feature, true); }
225
226void RenderControl::disable(const std::string &feature) { setFeature(feature, false); }
227
228bool RenderControl::isEnabled(const std::string &feature) const {
229 if (feature == "clusteredDeferred") return lightingMode_ == LightingMode::Hybrid;
230 auto it = features_.find(feature);
231 return it != features_.end() && it->second;
232}
233
234void RenderControl::setReflectionQuality(const std::string &quality) {
235 reflectionQuality_ = quality == "low" || quality == "medium" || quality == "high" ||
236 quality == "ultra"
237 ? quality
238 : "high";
239}
240
242 passes_.clear();
243
244 const bool wantHybrid = lightingMode_ == LightingMode::Hybrid;
245 const bool gbufferOn = isEnabled("gbuffer") || isEnabled("gbufferAlbedo") || isEnabled("ao") || isEnabled("gi");
246 const bool canHybrid = wantHybrid && isDeferredLightingAvailable() && gbufferOn;
247 effectiveLightingMode_ = canHybrid ? LightingMode::Hybrid : LightingMode::ForwardPlus;
248 hybridLightingFallback_ = wantHybrid && !canHybrid;
249
250 // Phase C: deferred lighting samples 1x GBuffer into scene color. MSAA scene
251 // color would need resolve-before-light; force MSAA off while Hybrid is live.
252 if (canHybrid) features_["msaa"] = false;
253
254 if (isEnabled("shadow")) passes_.push_back("shadow");
255 if (gbufferOn || canHybrid) passes_.push_back("gbuffer");
256 if (isEnabled("decal")) passes_.push_back("decal");
257 if (canHybrid) passes_.push_back("deferredLighting");
258 if (isEnabled("forward")) passes_.push_back("forward");
259 if (isEnabled("atmosphere")) passes_.push_back("atmosphere");
260 if (isEnabled("volumetricFog")) {
261 passes_.push_back("fogMedia");
262 passes_.push_back("fogLighting");
263 if (isEnabled("fogTemporal")) passes_.push_back("fogTemporal");
264 passes_.push_back("fogIntegrate");
265 passes_.push_back("fogComposite");
266 }
267 if (isEnabled("hair")) passes_.push_back("hair");
268 dirty_ = false;
269 compiled_ = true;
270}
271
275
276std::string RenderControl::getPassName(int index) const {
277 if (index < 0 || index >= int(passes_.size())) return {};
278 return passes_[size_t(index)];
279}
280
281bool RenderControl::hasPass(const std::string &name) const {
282 for (const auto &p : passes_) {
283 if (p == name) return true;
284 }
285 return false;
286}
287
288} // namespace eve::graphics
glm::vec4 p[6]
Stable, structured diagnostics shared by engine modules.
std::string name
float f
uint32_t index
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
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:537
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
void invalidateTemporalHistory()
Discard TAA history after a render-chain discontinuity.
void attach(Graphics *gfx)
Attaches .
Definition GBuffer.h:39
void invalidateHistory()
Discard temporal GI history after a render-chain discontinuity.
ScreenSpaceReflection * pipelineScreenSpaceReflection()
Pipeline screen space reflection.
GlobalIllumination * pipelineGlobalIllumination()
Pipeline global illumination.
AntiAliasing * pipelineAntiAliasing()
Pipeline anti aliasing.
virtual bool supportsDeferredLighting() const
True when the backend can run Hybrid clustered deferred lighting.
Definition Graphics.h:245
void ensureCompiled()
Ensure compiled; no-op when already clean.
Result< void > setLightingMode(LightingMode mode)
Request the opaque lighting strategy (transparent stays Forward+).
void compile()
Rebuild the executable pass list from current feature flags.
bool isCompiled() const
True when compiled.
void attach(Graphics *gfx)
Attaches .
RenderControl()
Renders control.
void enable(const std::string &feature)
Enables .
Result< void > applySuggestedLightingPreset()
Apply suggestedLightingPreset(), then optional EVENGINE_LIGHTING_MODE override.
void disable(const std::string &feature)
Disables .
bool isDeferredLightingAvailable() const
True when deferredLighting can be inserted for Hybrid. Requires an attached Graphics backend that imp...
Result< void > applyLightingPreset(LightingPreset preset)
Apply a platform lighting preset (sets LightingMode; does not lock against later setLightingMode).
bool isEnabled(const std::string &feature) const
True when enabled.
bool hasPass(const std::string &name) const
True when pass.
std::string getPassName(int index) const
Return the compiled pass name at index, or an empty string.
void setReflectionQuality(const std::string &quality)
Set the shared TAA/RTGI/SSR quality preset used by the automatic reflection chain.
bool supports(const std::string &feature) const
Supports.
void invalidateHistory()
Discard temporal reflection history after a render-chain discontinuity.
void setEnabled(bool enabled)
Enable/disable the pass. When disabled it emits transparent (0 hit).
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
Result< LightingMode > lightingModeFromEnv()
Optional explicit mode from EVENGINE_LIGHTING_MODE=forwardPlus|hybrid.
LightingPreset suggestedLightingPreset()
Suggest a lighting preset from OS, GPU type/name, and env.
LightingMode
3D lighting strategy for opaque geometry.
LightingPreset
Platform lighting quality preset (does not replace an explicit setLightingMode).
bool enabled