载入中...
搜索中...
未找到
RenderControl.cpp
浏览该文件的文档.
2
3#include "common/Capability.h"
4#include "common/Diagnostic.h"
7#include "graphics/Graphics.h"
10
11namespace eve::graphics {
12namespace {
13
14const char* kKnownFeatures[] = {"depthTest",
15 "shadow",
16 "gbuffer",
17 "gbufferAlbedo",
18 "forward",
19 "hair",
20 "clustered",
21 "clusteredDeferred",
22 "ao",
23 "gi",
24 "aa",
25 "msaa",
26 "rtgi",
27 "taa",
28 "ssr",
29 "reflectionChain",
30 "rtx",
31 "pathTracing",
32 "pathTemporal",
33 "outline",
34 "contactShadow",
35 "gpuDriven",
36 "visResolve",
37 "frustumCull",
38 "decal",
39 "atmosphere",
40 "volumetricFog",
41 "fogLocalVolumes",
42 "fogTemporal"};
43
44bool isKnownFeature(const std::string &feature) {
45 for (const char *f : kKnownFeatures) {
46 if (feature == f) return true;
47 }
48 return false;
49}
50
51bool requiresGBuffer(const std::string& feature) {
52 return feature == "gbuffer" || feature == "gbufferAlbedo" || feature == "ao" || feature == "gi" ||
53 feature == "outline" || feature == "contactShadow" || feature == "decal" || feature == "gpuDriven" ||
54 feature == "visResolve" || feature == "ssr" || feature == "rtgi" || feature == "reflectionChain" ||
55 feature == "rtx" || feature == "volumetricFog" || feature == "fogLocalVolumes" || feature == "fogTemporal";
56}
57
58} // namespace
59
61 features_["depthTest"] = true;
62 features_["shadow"] = true;
63 features_["gbuffer"] = true;
64 features_["gbufferAlbedo"] = true;
65 features_["forward"] = true;
66 features_["hair"] = true;
67 features_["clustered"] = true;
68 features_["clusteredDeferred"] = false;
69 features_["ao"] = true;
70 features_["gi"] = true;
71 features_["contactShadow"] = false;
72 features_["rtgi"] = false;
73 features_["aa"] = true;
74 features_["taa"] = false;
75 features_["ssr"] = false;
76 features_["reflectionChain"] = false;
77 features_["rtx"] = false; // hardware RT reflections (optional; falls back to SSR)
78 features_["msaa"] = true;
79 features_["outline"] = false;
80 features_["gpuDriven"] = false; // stage 1 opt-in; off until runtime-verified
81 features_["visResolve"] = false; // stage 3 opt-in; visibility-buffer resolve
82 features_["frustumCull"] = false; // opt-in: conservative sphere culling in frame prep
83 features_["atmosphere"] = true;
84 features_["volumetricFog"] = false;
85 features_["fogLocalVolumes"] = false;
86 features_["fogTemporal"] = false;
87 lightingMode_ = LightingMode::ForwardPlus;
88 effectiveLightingMode_ = LightingMode::ForwardPlus;
89 hybridLightingFallback_ = false;
90 dirty_ = true;
91 compiled_ = false;
92}
93
95 gfx_ = gfx;
96 pathProvider_ = eve::cap::query<IRayTracing>();
97 gbuffer_.attach(gfx);
98}
99
100bool RenderControl::supports(const std::string &feature) const { return isKnownFeature(feature); }
101
105 "unknown automatic instancing path",
106 "graphics.RenderControl.autoInstancingPath"));
107 autoInstancingPath_ = path;
108 return Result<void>::success();
109}
110
112 if (samples == 0 || samples > 16)
114 "path tracing samples must be in [1, 16]",
115 "graphics.RenderControl.pathSamples"));
116 if (pathSamples_ != samples) {
117 pathSamples_ = samples;
118 pathSampleIndex_ = 0;
119 }
120 return Result<void>::success();
121}
122
123void RenderControl::syncClusteredDeferredFeature() {
124 features_["clusteredDeferred"] = lightingMode_ == LightingMode::Hybrid;
125}
126
127bool RenderControl::isDeferredLightingAvailable() const { return gfx_ != nullptr && gfx_->supportsDeferredLighting(); }
128
130 if (mode != LightingMode::ForwardPlus && mode != LightingMode::Hybrid) {
132 "graphics.RenderControl.lightingMode"));
133 }
134 if (lightingMode_ == mode) return Result<void>::success();
135 lightingMode_ = mode;
136 syncClusteredDeferredFeature();
137 if (mode == LightingMode::Hybrid) {
138 features_["gbuffer"] = true;
139 features_["gbufferAlbedo"] = true;
140 }
141 dirty_ = true;
142 return Result<void>::success();
143}
144
146 if (name == "forwardPlus" || name == "forward+") return setLightingMode(LightingMode::ForwardPlus);
147 if (name == "hybrid") return setLightingMode(LightingMode::Hybrid);
149 "lighting mode must be \"forwardPlus\" or \"hybrid\"",
150 "graphics.RenderControl.lightingMode"));
151}
152
159
161 if (name == "desktop") return applyLightingPreset(LightingPreset::Desktop);
162 if (name == "mobile") return applyLightingPreset(LightingPreset::Mobile);
163 if (name == "ci") return applyLightingPreset(LightingPreset::Ci);
165 "lighting preset must be \"desktop\", \"mobile\", or \"ci\"",
166 "graphics.RenderControl.lightingPreset"));
167}
168
170 auto presetResult = applyLightingPreset(suggestedLightingPreset());
171 if (!presetResult.ok()) return presetResult;
172 auto envMode = lightingModeFromEnv();
173 if (envMode.ok()) return setLightingMode(envMode.value());
174 return presetResult;
175}
176
177void RenderControl::setFeature(const std::string &feature, bool enabled) {
178 if (!isKnownFeature(feature)) return;
179
180 if (feature == "clusteredDeferred") {
182 setMode.ignore();
183 return;
184 }
185
186 auto it = features_.find(feature);
187 const bool cur = it == features_.end() ? false : it->second;
188 if (cur == enabled) return;
189 features_[feature] = enabled;
190 if (feature == "pathTracing") {
191 pathTracingRequested_ = enabled;
192 pathTracingState_ = PathTracingFrameState::Disabled;
193 pathTracingDiagnostic_.clear();
194 pathSampleIndex_ = 0;
195 }
196 if (feature == "pathTemporal") {
197 pathTemporalRequested_ = enabled;
198 pathSampleIndex_ = 0;
199 }
200 if (gfx_ && (feature == "ssr" || feature == "rtgi" || feature == "reflectionChain" || feature == "rtx")) {
203 }
204 if (gfx_ && (feature == "taa" || feature == "reflectionChain"))
206 if (feature == "gbufferAlbedo" && enabled) features_["gbuffer"] = true;
207 if (feature == "ao" && enabled) features_["gbuffer"] = true;
208 if (feature == "outline" && enabled) features_["gbuffer"] = true;
209 if (feature == "decal" && enabled) features_["gbuffer"] = true;
210 // Stage 2 GPU cull needs the GBuffer depth as its HZB source.
211 if (feature == "gpuDriven" && enabled) features_["gbuffer"] = true;
212 if ((feature == "ssr" || feature == "rtgi" || feature == "reflectionChain" || feature == "rtx") && enabled)
213 features_["gbuffer"] = true;
214 if (feature == "rtx" && enabled) {
215 // Prefer hardware RT when available; keep SSR as the portable path
216 // that RenderSystem3D can still run when IRayTracing is absent.
217 features_["gbuffer"] = true;
218 }
219 if (feature == "reflectionChain" && enabled) {
220 features_["aa"] = true;
221 features_["taa"] = true;
222 features_["msaa"] = false;
223 features_["rtgi"] = true;
224 features_["ssr"] = true;
225 }
226 if (feature == "reflectionChain" && !enabled) {
227 features_["taa"] = false;
228 features_["rtgi"] = false;
229 features_["ssr"] = false;
230 if (gfx_) gfx_->pipelineScreenSpaceReflection()->setEnabled(false);
231 }
232 if ((feature == "taa" || feature == "rtgi" || feature == "ssr") && !enabled)
233 features_["reflectionChain"] = false;
234 if (feature == "taa" && enabled) {
235 features_["aa"] = true;
236 features_["msaa"] = false;
237 }
238 if ((feature == "volumetricFog" || feature == "fogLocalVolumes" ||
239 feature == "fogTemporal") && enabled) {
240 features_["atmosphere"] = true;
241 features_["volumetricFog"] = true;
242 features_["gbuffer"] = true;
243 }
244 if (feature == "volumetricFog" && !enabled) {
245 features_["fogLocalVolumes"] = false;
246 features_["fogTemporal"] = false;
247 }
248 if (feature == "gi" && enabled) {
249 features_["gbuffer"] = true;
250 features_["gbufferAlbedo"] = true;
251 }
252 if (feature == "gbuffer" && !enabled) {
253 features_["gbufferAlbedo"] = false;
254 features_["ao"] = false;
255 features_["gi"] = false;
256 features_["rtgi"] = false;
257 features_["ssr"] = false;
258 features_["rtx"] = false;
259 features_["reflectionChain"] = false;
260 features_["outline"] = false;
261 features_["decal"] = false;
262 // Hybrid needs GBuffer; keep the request but compile() will fall back.
263 dirty_ = true;
264 return;
265 }
266 dirty_ = true;
267}
268
269Result<void> RenderControl::requestFeature(const std::string& feature, bool enabled) {
270 if (!isKnownFeature(feature))
272 DiagnosticCode::Unsupported, "unknown render feature: " + feature, "graphics.RenderControl.feature"));
273 if (enabled && requiresGBuffer(feature) && gfx_ && !gfx_->supportsGBufferPost())
275 "render feature requires an unavailable GBuffer: " + feature,
276 "graphics.RenderControl.feature"));
277 setFeature(feature, enabled);
278 return Result<void>::success();
279}
280
281void RenderControl::enable(const std::string& feature) {
282 auto result = requestFeature(feature, true);
283 result.ignore();
284}
285
286void RenderControl::disable(const std::string& feature) {
287 auto result = requestFeature(feature, false);
288 result.ignore();
289}
290
291bool RenderControl::isEnabled(const std::string &feature) const {
292 if (feature == "clusteredDeferred") return lightingMode_ == LightingMode::Hybrid;
293 if (gfx_ && requiresGBuffer(feature) && !gfx_->supportsGBufferPost()) return false;
294 auto it = features_.find(feature);
295 return it != features_.end() && it->second;
296}
297
298void RenderControl::setReflectionQuality(const std::string &quality) {
299 reflectionQuality_ = quality == "low" || quality == "medium" || quality == "high" ||
300 quality == "ultra"
301 ? quality
302 : "high";
303}
304
306 passes_.clear();
307
308 const bool wantHybrid = lightingMode_ == LightingMode::Hybrid;
309 const bool gbufferAvailable = gfx_ == nullptr || gfx_->supportsGBufferPost();
310 const bool gbufferOn =
311 gbufferAvailable &&
312 (isEnabled("gbuffer") || isEnabled("gbufferAlbedo") || isEnabled("ao") || isEnabled("gi") ||
313 isEnabled("contactShadow") || isEnabled("outline") || isEnabled("decal") || isEnabled("rtgi") ||
314 isEnabled("ssr") || isEnabled("reflectionChain") || isEnabled("rtx") || isEnabled("volumetricFog"));
315 // GPU-driven opaque and visibility resolve belong to ForwardPlus. Preserve
316 // the requested mode while exposing this explicit feature's priority in the
317 // effective pass list instead of silently disabling it during rendering.
318 const bool canHybrid = wantHybrid && isDeferredLightingAvailable() && gbufferOn && !isEnabled("gpuDriven");
319 effectiveLightingMode_ = canHybrid ? LightingMode::Hybrid : LightingMode::ForwardPlus;
320 hybridLightingFallback_ = wantHybrid && !canHybrid;
321
322 // Phase C: deferred lighting samples 1x GBuffer into scene color. MSAA scene
323 // color would need resolve-before-light; force MSAA off while Hybrid is live.
324 if (canHybrid) features_["msaa"] = false;
325
326 if (isEnabled("shadow")) passes_.push_back("shadow");
327 if (gbufferOn || canHybrid) passes_.push_back("gbuffer");
328 if (gbufferAvailable && isEnabled("decal")) passes_.push_back("decal");
329 if (canHybrid) passes_.push_back("deferredLighting");
330 if (isEnabled("forward")) passes_.push_back("forward");
331 if (isEnabled("atmosphere")) passes_.push_back("atmosphere");
332 if (isEnabled("volumetricFog")) {
333 passes_.push_back("fogMedia");
334 passes_.push_back("fogLighting");
335 if (isEnabled("fogTemporal")) passes_.push_back("fogTemporal");
336 passes_.push_back("fogIntegrate");
337 passes_.push_back("fogComposite");
338 }
339 if (isEnabled("hair")) passes_.push_back("hair");
340 dirty_ = false;
341 compiled_ = true;
342}
343
347
348std::string RenderControl::getPassName(int index) const {
349 if (index < 0 || index >= int(passes_.size())) return {};
350 return passes_[size_t(index)];
351}
352
353bool RenderControl::hasPass(const std::string &name) const {
354 for (const auto &p : passes_) {
355 if (p == name) return true;
356 }
357 return false;
358}
359
360} // namespace eve::graphics
glm::vec4 p[6]
Stable, structured diagnostics shared by engine modules.
std::string name
Definition ECS.cpp:154
Poco::JSON::Object::Ptr result
float f
std::string path
Definition PlayHost.cpp:111
uint32_t index
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:571
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
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 supportsGBufferPost() const
Whether gbuffer-based post-process shaders (AO, GI) can be created on this backend....
Definition Graphics.h:260
virtual bool supportsDeferredLighting() const
True when the backend can run Hybrid clustered deferred lighting.
Definition Graphics.h:267
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.
Result< void > setLightingMode(const std::string &name)
Request lighting mode by name: "forwardPlus" / "forward+" / "hybrid".
bool isCompiled() const
True when compiled.
void attach(Graphics *gfx)
Attaches .
RenderControl()
Renders control.
void enable(const std::string &feature)
Compatibility-only feature enablement; use requestFeature to observe failure.
Result< void > applySuggestedLightingPreset()
Apply suggestedLightingPreset(), then optional EVENGINE_LIGHTING_MODE override.
Result< void > setPathTracingSamples(uint32_t samples)
Set the automatic path renderer's independent samples per pixel per frame.
void disable(const std::string &feature)
Compatibility-only feature disablement; use requestFeature to observe failure.
Result< void > requestFeature(const std::string &feature, bool enabled)
Request a feature change with an observable Unsupported result when the backend cannot run it.
bool isDeferredLightingAvailable() const
True when deferredLighting can be inserted for Hybrid. Requires an attached Graphics backend that imp...
Result< void > setAutoInstancingPath(AutoInstancingPath path)
Select automatic opaque instancing without changing lighting or explicit gpuDriven requests.
AutoInstancingPath
Automatic opaque batching route; explicit gpuDriven requests retain priority.
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