载入中...
搜索中...
未找到
ShadowScheme.h
浏览该文件的文档.
1#pragma once
2
3#include "common/Export.h"
4#include "common/Result.h"
5#include "graphics/Light.h"
6#include "graphics/Shadow.h"
7
8#include <cstdint>
9#include <string>
10#include <string_view>
11#include <vector>
12#include <glm/glm.hpp>
13
14namespace eve::graphics {
15
22[[nodiscard]] EVENGINE_API_BACKENDS Result<ShadowMethod> parseShadowMethod(std::string_view name);
23
26
33[[nodiscard]] EVENGINE_API_BACKENDS Result<ShadowMethod> resolveShadowMethod(std::string_view lightType,
34 ShadowMethod requested);
35
41 glm::vec3 eye{0.f};
43 glm::mat4 viewProj{1.f};
44 bool valid = false;
45};
46
68 bool enableDirectionalCsm = true;
69 bool enableSpotPerspective = true;
70 bool enablePointCube = false; // GPU atlas path lands later; keep off by default
72 int directionalMapSize = ShadowConfig::kMapSize;
74 int localMapSize = 1024;
79 float directionalMaxDistance = ShadowConfig::kMaxDistance;
81 int maxSpotShadowCasters = ShadowConfig::kLocalSlots;
82 int maxPointShadowCasters = 0;
83 float defaultSpotBias = 0.002f;
84 float defaultPointBias = 0.003f;
85
87 bool enableLocalPaging = true;
92 int maxLocalUpdatesPerFrame = ShadowConfig::kLocalSlots;
94 float hysteresisBonus = 0.35f;
96 float minPageScore = 1e-4f;
97
105 bool enableAdaptiveCascadeResolution = true;
110 float adaptiveScreenWeight = 0.65f;
112 float adaptiveDistanceWeight = 1.f;
117 float adaptiveSizeHysteresis = 0.2f;
118
120 [[nodiscard]] static ShadowSchemeSettings& current();
121
126 [[nodiscard]] int resolvedAtlasMapSize() const;
127
132 [[nodiscard]] float resolvedDirectionalMaxDistance() const;
133};
134
143
155 int atlasSize, const float (&splitEnds)[ShadowConfig::kCascades + 1],
156 const float (&screenCoverage)[ShadowConfig::kCascades], const ShadowSchemeSettings& settings);
157
162[[nodiscard]] EVENGINE_API_BACKENDS float estimateCascadeScreenCoverage(const glm::vec3& eye, const glm::vec3& target,
163 const glm::vec3& up, float fovYRad,
164 float aspect, float nearZ, float farZ);
165
167inline constexpr int kMinShadowMapSize = 256;
169inline constexpr int kMaxShadowMapSize = 4096;
170
176[[nodiscard]] EVENGINE_API_BACKENDS int clampShadowMapSize(int size);
177
182[[nodiscard]] EVENGINE_API_BACKENDS int shadowMapSizeForResolutionTier(int resolutionTier);
183
189[[nodiscard]] EVENGINE_API_BACKENDS Result<void> setShadowSchemeMapSizes(int directionalMapSize, int localMapSize = -1);
190
196
204 int layer = -1; // index into the shadow depth array
205 int lightIndex = -1; // index in the packed Light3D list (0..7)
206 glm::mat4 lightVP{1.f};
207 float bias = 0.002f;
208 float strength = 1.f;
209 float score = 0.f;
211 bool needsUpdate = true;
212};
213
221[[nodiscard]] EVENGINE_API_BACKENDS glm::mat4 buildSpotShadowVP(const glm::vec3& position,
222 const glm::vec3& direction, float range,
223 float outerAngleDeg);
224
232 int faceIndex, float range);
233
242 const ShadowPagingView& view,
244 bool hadSlot);
245
257EVENGINE_API_BACKENDS void selectShadowCasters(const std::vector<Light3D::Data*>& lights,
258 const std::vector<bool>& isPointFlags,
260 const ShadowPagingView& view,
261 Light3D::Data*& directionalCaster,
262 std::vector<LocalShadowSlot>& localSlots);
263
266
267} // namespace eve::graphics
LogicalId target
std::string name
Definition ECS.cpp:154
std::uint16_t method
#define EVENGINE_API_BACKENDS
Definition Export.h:108
std::vector< eve::ProcgenProbeDesc > lights
HexVec3 up
Range range
std::array< float, 3 > position
OceanWakeSettings settings
OceanSprayView view
glm::vec3 eye
Move-only, checked operation results for the common layer.
RoadLaneDirection direction
double current
Light3D::Data * light
Definition Shadow.cpp:147
float size
Definition TreeMesh.cpp:158
Move-only operation result carrying either a value or Status.
Definition Result.h:176
卡牌游戏 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 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
constexpr int kMaxShadowMapSize
Largest supported shadow-map edge length.
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
constexpr int kMinShadowMapSize
Smallest supported shadow-map edge length.
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
ShadowMethod
How a Light3D produces real-time shadows. Auto resolves per light type (dir→CSM, spot→perspective,...
Definition Shadow.h:14
Result< ShadowMethod > parseShadowMethod(std::string_view name)
Parse a script/editor method name into ShadowMethod.
Definition Shadow.cpp:387
Per-cascade effective map sizes chosen for one CSM build. @ownership Value type; copied into ShadowUp...
int sizes[ShadowConfig::kCascades]
Data public API.
Definition Light.h:199
One allocated local (spot/point-face) shadow slot for the frame. @ownership Ephemeral CPU descriptor;...
bool needsUpdate
When false, skip the shadow pass and keep the cached depth layer.
static constexpr int kMapSize
Definition Shadow.h:28
static constexpr int kCascades
Definition Shadow.h:24
Camera context used to score local shadow candidates for atlas paging. @ownership Ephemeral; valid on...
glm::mat4 viewProj
Camera view-projection (Vulkan RH, ZO) for soft frustum scoring.
Process-wide defaults for creating shadows per light family.