载入中...
搜索中...
未找到
Shadow.cpp
浏览该文件的文档.
15glm::mat4 cascadeVP(const glm::vec3& lightDir, const glm::vec3& eye, const glm::vec3& target, const glm::vec3& up,
76 const glm::mat4 lightProj = orthoVulkanRH_ZO(centerLS.x - radius, centerLS.x + radius, centerLS.y - radius,
83ShadowUpload buildDirectionalCSM(const glm::vec3& lightDirTowardSurface, const glm::vec3& eye, const glm::vec3& target,
106 screenCoverage[i] = estimateCascadeScreenCoverage(eye, target, up, fovYRad, aspect, splits[i], splits[i + 1]);
179bool lightParamsMatchCache(const Light3D::Data& d, const LocalPageCacheEntry& e, float resolvedBias) {
181 return e.occupied && e.light == &d && std::abs(e.x - d.x) < kEps && std::abs(e.y - d.y) < kEps &&
184 std::abs(e.spotAngleDeg - d.spotAngleDeg) < kEps && std::abs(e.shadowStrength - d.shadowStrength) < kEps &&
188void storeCacheEntry(LocalPageCacheEntry& e, Light3D::Data* d, const glm::mat4& vp, float bias) {
249 if (!std::isfinite(directionalMaxDistance) || directionalMaxDistance <= 0.f) return ShadowConfig::kMaxDistance;
256 DiagnosticCode::InvalidArgument, "directional shadow map size must be positive", "graphics.shadow"));
264 DiagnosticCode::InvalidArgument, "local shadow map size must be positive when set", "graphics.shadow"));
286float estimateCascadeScreenCoverage(const glm::vec3& eye, const glm::vec3& target, const glm::vec3& up, float fovYRad,
306 const glm::mat4 projLong = perspectiveVulkanRH_ZO(fovYRad, aspect, n, std::max(f, n + 1.f) * 4.f);
342 const float screenTerm = settings.adaptiveScreenWeight * std::clamp(screenCoverage[i], 0.f, 1.f);
355 const float edge = float(atlas) * std::sqrt(std::clamp(share * float(ShadowConfig::kCascades), 0.05f, 1.f));
391 if (equalsIgnoreCase(name, "csm") || equalsIgnoreCase(name, "cascaded") || equalsIgnoreCase(name, "directional"))
395 if (equalsIgnoreCase(name, "cube") || equalsIgnoreCase(name, "cubemap") || equalsIgnoreCase(name, "point"))
398 Diagnostic::error(DiagnosticCode::InvalidArgument, "Unknown shadow method", "graphics.shadow"));
427 DiagnosticCode::Unsupported, "Directional lights only support csm shadows", "graphics.shadow"));
431 DiagnosticCode::Unsupported, "Spot lights only support perspective shadows", "graphics.shadow"));
440glm::mat4 buildSpotShadowVP(const glm::vec3& position, const glm::vec3& direction, float range, float outerAngleDeg) {
452Result<glm::mat4> buildPointShadowFaceVP(const glm::vec3& position, int faceIndex, float range) {
455 Diagnostic::error(DiagnosticCode::InvalidArgument, "Point shadow face must be 0..5", "graphics.shadow"));
458 {1.f, 0.f, 0.f}, {-1.f, 0.f, 0.f}, {0.f, 1.f, 0.f}, {0.f, -1.f, 0.f}, {0.f, 0.f, 1.f}, {0.f, 0.f, -1.f},
487 if (std::abs(ndcX) < 1.f + pad && std::abs(ndcY) < 1.f + pad && ndcZ > -pad && ndcZ < 1.f + pad) {
500void selectShadowCasters(const std::vector<Light3D::Data*>& lights, const std::vector<bool>& isPointFlags,
550 const int maxSpots = std::max(0, std::min(settings.maxSpotShadowCasters, ShadowConfig::kLocalSlots));
620 buildSpotShadowVP(glm::vec3(d->x, d->y, d->z), dir, std::max(d->radius, 0.1f), d->spotAngleDeg);
651 const int updateBudget = std::max(0, std::min(settings.maxLocalUpdatesPerFrame, ShadowConfig::kLocalSlots));
Stable, structured diagnostics shared by engine modules.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
void selectShadowCasters(const std::vector< Light3D::Data * > &lights, const std::vector< bool > &isPointFlags, const ShadowSchemeSettings &settings, const ShadowPagingView &view, Light3D::Data *&directionalCaster, std::vector< LocalShadowSlot > &localSlots)
Select directional CSM caster + paged local spot slots for one frame.
Definition Shadow.cpp:500
glm::mat4 perspectiveVulkanRH_ZO(float fovyRad, float aspect, float zNear, float zFar)
Right-handed, zero-to-one depth perspective for Vulkan swapchains.
Definition ClipSpace.h:22
ShadowUpload buildDirectionalCSM(const glm::vec3 &lightDirTowardSurface, const glm::vec3 &eye, const glm::vec3 &target, const glm::vec3 &up, float fovYRad, float aspect, float nearZ, float farZ, float bias, float strength)
Build 3 cascade light view-proj matrices for a directional light.
Definition Shadow.cpp:83
glm::mat4 buildSpotShadowVP(const glm::vec3 &position, const glm::vec3 &direction, float range, float outerAngleDeg)
Build a perspective light VP for a spot caster (Vulkan RH, ZO depth).
Definition Shadow.cpp:440
AdaptiveCascadeAllocation allocateAdaptiveCascadeResolutions(int atlasSize, const float(&splitEnds)[ShadowConfig::kCascades+1], const float(&screenCoverage)[ShadowConfig::kCascades], const ShadowSchemeSettings &settings)
Distribute atlas resolution across cascades by distance + screen coverage.
Definition Shadow.cpp:321
float scoreSpotShadowCandidate(const Light3D::Data &light, const ShadowPagingView &view, const ShadowSchemeSettings &settings, bool hadSlot)
Score a spot caster for local-shadow paging (higher = more important).
Definition Shadow.cpp:470
int shadowMapSizeForResolutionTier(int resolutionTier)
Map PhotoMode m_shadowResolution (0..3) to an atlas edge length.
Definition Shadow.cpp:233
void resetShadowLocalPageCache()
Clear sticky local-page cache (tests / scheme resets).
Definition Shadow.cpp:381
Result< ShadowMethod > resolveShadowMethod(std::string_view lightType, ShadowMethod requested)
Resolve Auto / validate an explicit method for a concrete light type.
Definition Shadow.cpp:412
float estimateCascadeScreenCoverage(const glm::vec3 &eye, const glm::vec3 &target, const glm::vec3 &up, float fovYRad, float aspect, float nearZ, float farZ)
Estimate how much of the screen a cascade frustum slice covers.
Definition Shadow.cpp:286
const char * shadowMethodName(ShadowMethod method)
Canonical lowercase name for a ShadowMethod (auto, none, csm, …).
Definition Shadow.cpp:401
Result< glm::mat4 > buildPointShadowFaceVP(const glm::vec3 &position, int faceIndex, float range)
Build one cube-face light VP for a point caster.
Definition Shadow.cpp:452
int clampShadowMapSize(int size)
Clamp/round a requested map size to an allowed power-of-two.
Definition Shadow.cpp:218
Result< void > setShadowSchemeMapSizes(int directionalMapSize, int localMapSize)
Apply directional (and optional local) map sizes with validation. @cost Cheap CPU clamp; GPU recreate...
Definition Shadow.cpp:253
Result< void > setShadowSchemeDirectionalMaxDistance(float meters)
Apply CSM max distance with validation.
Definition Shadow.cpp:269
glm::mat4 orthoVulkanRH_ZO(float left, float right, float bottom, float top, float zNear, float zFar)
Ortho vulkan rh zo.
Definition ClipSpace.h:30
ShadowMethod
How a Light3D produces real-time shadows. Auto resolves per light type (dir→CSM, spot→perspective,...
Definition Shadow.h:14
@ CubePoint
@ PerspectiveSpot
@ CascadedDirectional
Result< ShadowMethod > parseShadowMethod(std::string_view name)
Parse a script/editor method name into ShadowMethod.
Definition Shadow.cpp:387
@ InvalidArgument
@ Unsupported
Per-cascade effective map sizes chosen for one CSM build. @ownership Value type; copied into ShadowUp...
Definition ShadowScheme.h:139
int sizes[ShadowConfig::kCascades]
Definition ShadowScheme.h:140
int shadowLocalSlot
Frame-transient local shadow atlas slot (0..kLocalSlots-1), or -1. Written by selectShadowCasters; pa...
Definition Light.h:223
One allocated local (spot/point-face) shadow slot for the frame. @ownership Ephemeral CPU descriptor;...
Definition ShadowScheme.h:201
bool needsUpdate
When false, skip the shadow pass and keep the cached depth layer.
Definition ShadowScheme.h:211
static constexpr int kLocalSlots
Extra depth-array layers for spot (perspective) local shadows.
Definition Shadow.h:26
Camera context used to score local shadow candidates for atlas paging. @ownership Ephemeral; valid on...
Definition ShadowScheme.h:40
Process-wide defaults for creating shadows per light family.
Definition ShadowScheme.h:67
int localMapSize
Preferred local-spot atlas edge length; shares the directional array today.
Definition ShadowScheme.h:74
int resolvedAtlasMapSize() const
Atlas edge length actually allocated for GPU shadow maps.
Definition Shadow.cpp:242
float resolvedDirectionalMaxDistance() const
CSM far clamp used by buildDirectionalCSM.
Definition Shadow.cpp:248
float directionalMaxDistance
Practical CSM far distance (camera-forward meters). Camera far is clamped to this so large scenes kee...
Definition ShadowScheme.h:79
int directionalMapSize
Preferred directional CSM atlas edge length (texels); clamped to {256..4096}².
Definition ShadowScheme.h:72
static ShadowSchemeSettings & current()
Borrow the process-wide settings object.
Definition Shadow.cpp:216