载入中...
搜索中...
未找到
PcgGraphicsPhotoMode.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cmath>
4
5#include "common/Capability.h"
7#include "graphics/Graphics.h"
11
12namespace eve::graphics {
14 if (authority_) cap::removeListener<IPhotoModeFieldSink>(this);
15}
16
18 graphics_ = graphics;
19 control_ = control;
20 camera_ = camera;
21 project();
22}
23
25 if (enabled == authority_) return;
26 if (enabled)
27 cap::addListener<IPhotoModeFieldSink>(this);
28 else
29 cap::removeListener<IPhotoModeFieldSink>(this);
30 authority_ = enabled;
31}
32
34 const PhotoModeAssignment& assignment) const noexcept {
35 return assignment.domain == PhotoModeDomain::Graphics ||
36 (assignment.domain == PhotoModeDomain::Lighting &&
37 assignment.field == "m_globalShadowDistanceMultiplier")
40}
41
43 auto fail = [&](const char* message) {
45 {}, "graphics.pcgPhotoMode"));
46 };
47 auto next = state_;
48 const auto* value = std::get_if<float>(&assignment.value);
49 const auto* mode = std::get_if<int64_t>(&assignment.value);
50 if (assignment.field == "m_lodBias") {
51 if (!value || !std::isfinite(*value) || *value <= 0) return fail("LOD bias must be positive and finite");
52 next.lodBias = *value;
53 } else if (assignment.field == "m_antiAliasing") {
54 if (!mode || *mode < 0 || *mode > 3) return fail("anti-aliasing mode must be in [0,3]");
55 next.antiAliasing = *mode;
56 } else if (assignment.field == "m_shadowDistance") {
57 if (!value || !std::isfinite(*value) || *value < 0)
58 return fail("shadow distance must be finite and non-negative");
59 next.shadowDistance = *value;
60 } else if (assignment.field == "m_shadowResolution") {
61 if (!mode || *mode < 0 || *mode > 3) return fail("shadow resolution must be in [0,3]");
62 next.shadowResolution = *mode;
63 } else if (assignment.field == "m_shadowCascades") {
64 if (!mode || *mode < 0 || *mode > 4) return fail("shadow cascades must be in [0,4]");
65 next.shadowCascades = *mode;
66 } else if (assignment.field == "m_globalShadowDistanceMultiplier") {
67 if (!value || !std::isfinite(*value) || *value < 0 || *value > 5)
68 return fail("global shadow distance multiplier must be in [0,5]");
69 next.globalShadowDistanceMultiplier = *value;
70 } else {
71 return fail("unsupported graphics photo-mode field");
72 }
73 state_ = next;
74 project();
75 return Result<void>::success();
76}
77
78void PcgGraphicsPhotoModeAuthority::project() {
79 const float shadowDistance = state_.shadowDistance * state_.globalShadowDistanceMultiplier;
80 if (camera_) {
81 camera_->data()->lodBias = state_.lodBias;
82 for (int layer = 0; layer < 32; ++layer) camera_->setShadowLayerCullDistance(layer, shadowDistance);
83 }
84 // Drive the shared shadow atlas + CSM far clamp from PhotoMode quality knobs.
85 // Cascade *count* stays compile-time (ShadowConfig::kCascades); resolution and
86 // coverage are the runtime levers that affect GPU resources and texel density.
87 auto& scheme = ShadowSchemeSettings::current();
88 scheme.directionalMapSize = shadowMapSizeForResolutionTier(int(state_.shadowResolution));
89 scheme.localMapSize = clampShadowMapSize(std::max(256, scheme.directionalMapSize / 2));
90 // Cap CSM coverage so a huge PhotoMode cull distance does not dilute texels
91 // across kilometers; caster cull still uses the uncapped shadowDistance.
92 scheme.directionalMaxDistance = std::clamp(shadowDistance, 8.f, 256.f);
93 if (!graphics_ || !control_) return;
94 auto* antiAliasing = graphics_->pipelineAntiAliasing();
95 const int mode = int(state_.antiAliasing);
96 if (mode == 0) {
97 control_->disable("aa");
98 control_->disable("taa");
99 } else {
100 control_->enable("aa");
101 control_->enable(mode == 3 ? "taa" : "aa");
102 if (mode != 3) control_->disable("taa");
103 antiAliasing->setMode(mode == 2 ? "smaa" : mode == 3 ? "taa" : "fxaa");
104 }
105 control_->compile();
106}
107} // namespace eve::graphics
std::string message
float camera[2]
TileLayer * layer
Object::Ptr value
Graphics * graphics
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
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
EVENGINE_API_BACKENDS public API.
void setShadowLayerCullDistance(int layer, float distance)
Set the shadow-caster cull distance for one render layer; zero disables it.
AntiAliasing * pipelineAntiAliasing()
Pipeline anti aliasing.
PhotoModeFieldAcceptance acceptsPhotoModeField(const PhotoModeAssignment &) const noexcept override
Accepts photo mode field.
Result< void > applyPhotoModeField(const PhotoModeAssignment &) override
Applies photo mode field.
void setAuthority(bool enabled)
Register or revoke the unique graphics photo-mode authority.
void setTargets(Graphics *graphics, RenderControl *control, Camera3D *camera)
Bind borrowed owner-thread render targets; none are retained past this authority's lifetime.
~PcgGraphicsPhotoModeAuthority() override
Pcg graphics photo mode authority.
Declarative, compilable 3D render control.
void compile()
Rebuild the executable pass list from current feature flags.
void enable(const std::string &feature)
Compatibility-only feature enablement; use requestFeature to observe failure.
void disable(const std::string &feature)
Compatibility-only feature disablement; use requestFeature to observe failure.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
int shadowMapSizeForResolutionTier(int resolutionTier)
Map PhotoMode m_shadowResolution (0..3) to an atlas edge length.
Definition Shadow.cpp:233
int clampShadowMapSize(int size)
Clamp/round a requested map size to an allowed power-of-two.
Definition Shadow.cpp:218
PhotoModeFieldAcceptance
Capability implemented by the composition root that routes assignments to domain owners.
bool enabled
One reversible field assignment in a photo-mode transaction.
static ShadowSchemeSettings & current()
Borrow the process-wide settings object.
Definition Shadow.cpp:216