载入中...
搜索中...
未找到
Light.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/ECS.h"
6
7#include <algorithm>
8#include <array>
9#include <cmath>
10#include <cstdint>
11#include <string>
12#include <string_view>
13#include <glm/glm.hpp>
14
15namespace eve::graphics {
16
17class Canvas;
18
27inline void lightSpotCosines(float angleDeg, float softness, float &cosOuter, float &cosInner) {
28 constexpr float kPi = 3.14159265358979323846f;
29 const float outerDeg = std::clamp(angleDeg, 0.1f, 89.f);
30 const float soft = std::clamp(softness, 0.f, 1.f);
31 const float outerRad = outerDeg * (kPi / 180.f);
32 const float innerRad = outerRad * (1.f - soft);
33 cosOuter = std::cos(outerRad);
34 cosInner = std::cos(innerRad);
35 if (cosInner < cosOuter + 1e-4f) cosInner = cosOuter + 1e-4f;
36}
37
39inline void light2dSpotCosines(float angleDeg, float softness, float &cosOuter, float &cosInner) {
40 lightSpotCosines(angleDeg, softness, cosOuter, cosInner);
41}
42
44struct Light2DGpu {
45 glm::vec4 posRadius{0.f}; // xy = point/spot pos or dir; w = radius (0 => directional)
46 glm::vec4 color{0.f}; // rgb * intensity
48 glm::vec4 spot{0.f, 0.f, -2.f, -2.f};
49};
50
53 static constexpr int kMaxLights = 8;
54 glm::vec4 ambient{0.15f, 0.15f, 0.18f, 0.f};
55 glm::vec4 meta{0.f}; // x = count, y = viewW, z = viewH
57};
58
63class EVENGINE_API_BACKENDS Light2D : public ecs::Entity {
64public:
66 ENTITY(Light2D, ecs::Entity)
67
68
69 void release() override {}
70
72 struct Data {
73 std::string type = "point";
74 float x = 0.f;
75 float y = 0.f;
76 float dx = 0.f;
77 float dy = -1.f;
78 float r = 1.f, g = 1.f, b = 1.f;
79 float intensity = 1.f;
80 float radius = 200.f;
82 float spotAngleDeg = 30.f;
84 float spotSoftness = 0.35f;
85 bool enabled = true;
87 bool volumetric = false;
88 float volumetricIntensity = 1.f;
93 bool volumetricOnly = false;
94 Canvas *canvas = nullptr;
95 Light2D *entity = nullptr;
96 };
97
98 COMPONENT(Data, data)
99
100 static Light2D *createLight(const std::string &type = "point");
101
113 static Light2D *createEmissiveProxy(float x, float y, float r, float g, float b,
114 float intensity = 1.f, float radius = 200.f);
115
116 void setType(const std::string &type);
117 std::string getType();
118
119 void setPosition(float x, float y);
120 float getX();
121 float getY();
122
123 void setDirection(float dx, float dy);
124 float getDirX();
125 float getDirY();
126
127 void setColor(float r, float g, float b, float intensity = 1.f);
128 void setRadius(float radius);
129 float getRadius();
130
135 void setSpotAngle(float degrees);
137 float getSpotAngle();
142 void setSpotSoftness(float softness);
144 float getSpotSoftness();
145
146 void setEnabled(bool enabled);
147 bool isEnabled();
148
149 void setVolumetric(bool enabled);
150 bool getVolumetric();
151 void setVolumetricIntensity(float intensity);
152 float getVolumetricIntensity();
153 void setVolumetricOnly(bool enabled);
154 bool getVolumetricOnly();
155
156 void setCanvas(Canvas *canvas);
157};
158
161 glm::vec4 posRadius{0.f}; // xyz = point/spot pos or dir; w = radius (0 => directional)
162 glm::vec4 color{0.f}; // rgb * intensity; a = spotBias when spot else 1
167 glm::vec4 spot{0.f, 0.f, 0.f, -1.f};
168};
169
172 static constexpr int kMaxLights = 8;
173 glm::vec4 ambient{0.12f, 0.12f, 0.14f, 0.f};
175 int count = 0;
176 std::array<glm::vec4, 9> diffuseProbeSh{}; // xyz = RGB coefficient
178 static constexpr int kMaxDiffuseVolumeProbes = 8;
179 std::array<glm::vec4, kMaxDiffuseVolumeProbes> diffuseVolumePosition{};
180 std::array<glm::vec4, kMaxDiffuseVolumeProbes> diffuseVolumeExtent{};
181 std::array<glm::vec4, kMaxDiffuseVolumeProbes * 9> diffuseVolumeSh{};
184};
185
190class EVENGINE_API_BACKENDS Light3D : public ecs::Entity {
191public:
193 ENTITY(Light3D, ecs::Entity)
194
195
196 void release() override {}
197
199 struct Data {
200 std::string type = "point";
201 float x = 0.f, y = 0.f, z = 0.f;
202 float dx = 0.4f, dy = 1.f, dz = 0.3f;
203 float r = 1.f, g = 1.f, b = 1.f;
204 float intensity = 1.f;
205 float radius = 8.f;
207 float spotAngleDeg = 30.f;
209 float spotSoftness = 0.35f;
210 bool enabled = true;
211 bool castShadow = false;
217 std::uint8_t shadowMethod = 0;
223 int shadowLocalSlot = -1;
224 float shadowBias = 0.f; // 0 = auto NDC from cascade texel / Z range
225 float shadowStrength = 1.f;
226 bool volumetric = false;
227 float volumetricIntensity = 1.f;
232 bool volumetricOnly = false;
233 Light3D *entity = nullptr;
234 };
235
236 COMPONENT(Data, data)
237
238 static Light3D *createLight(const std::string &type = "point");
239
246 static Light3D *createEmissiveProxy(float x, float y, float z, float r, float g, float b,
247 float intensity = 1.f, float radius = 8.f);
248
249 void setType(const std::string &type);
250 std::string getType();
251
252 void setPosition(float x, float y, float z);
253 float getX();
254 float getY();
255 float getZ();
256
257 void setDirection(float dx, float dy, float dz);
258 float getDirX();
259 float getDirY();
260 float getDirZ();
261
262 void setColor(float r, float g, float b, float intensity = 1.f);
263 void setRadius(float radius);
264 float getRadius();
265
270 void setSpotAngle(float degrees);
272 float getSpotAngle();
277 void setSpotSoftness(float softness);
279 float getSpotSoftness();
280
281 void setEnabled(bool enabled);
282 bool isEnabled();
283
284 void setCastShadow(bool cast);
285 bool getCastShadow();
290 void setShadowMethod(const std::string &method);
292 std::string getShadowMethod();
293 void setShadowBias(float bias);
294 float getShadowBias();
295 void setShadowStrength(float strength);
296 float getShadowStrength();
297
298 void setVolumetric(bool enabled);
299 bool getVolumetric();
300 void setVolumetricIntensity(float intensity);
301 float getVolumetricIntensity();
302 void setVolumetricOnly(bool enabled);
303 bool getVolumetricOnly();
304};
305
306} // namespace eve::graphics
double z
double y
double x
float degrees
Definition CardTypes.cpp:38
std::uint16_t method
#define EVENGINE_API_BACKENDS
Definition Export.h:108
float strength
tensor::Graph g
Definition GpuGraph.cpp:7
float soft[4]
double r
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
glm::dvec3 dx
glm::dvec3 dz
const EntityFact * entity
float shadowStrength
Definition Shadow.cpp:154
float spotAngleDeg
Definition Shadow.cpp:153
float dy
Definition Shadow.cpp:151
float bias
Definition Shadow.cpp:149
Canvas public API.
Definition Canvas.h:17
Declarative 2D light. Collected by RenderSystem (max 8 per canvas/frame). type: "point" | "dir" | "sp...
Definition Light.h:63
Declarative 3D light. Collected by RenderSystem3D (max 8 per frame). type: "point" | "dir" | "spot" (...
Definition Light.h:190
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
void light2dSpotCosines(float angleDeg, float softness, float &cosOuter, float &cosInner)
Backward-compatible alias for lightSpotCosines.
Definition Light.h:39
void lightSpotCosines(float angleDeg, float softness, float &cosOuter, float &cosInner)
Convert spot angle/softness into GPU cosines (outer < inner). Shared by Light2D and Light3D flashligh...
Definition Light.h:27
bool enabled
GPU light packing for lit2d (std140-friendly).
Definition Light.h:44
glm::vec4 spot
Spot cone: xy = beam dir; z/w = cos(outer/inner half-angle). z <= -1.5 => off.
Definition Light.h:48
Data public API.
Definition Light.h:72
GPU light packing for mesh3d / PBR (std140-friendly).
Definition Light.h:160
glm::vec4 spot
Spot cone: xyz = world beam direction; w = spotScale (1/(cosInner-cosOuter)). w <= 0 means the light ...
Definition Light.h:167
Data public API.
Definition Light.h:199
Lighting2DUBO public API.
Definition Light.h:52
static constexpr int kMaxLights
Definition Light.h:53
Light2DGpu lights[kMaxLights]
Definition Light.h:56
Lighting3DPack public API.
Definition Light.h:171
std::array< glm::vec4, kMaxDiffuseVolumeProbes > diffuseVolumePosition
Definition Light.h:179
std::array< glm::vec4, kMaxDiffuseVolumeProbes > diffuseVolumeExtent
Definition Light.h:180
std::array< glm::vec4, kMaxDiffuseVolumeProbes *9 > diffuseVolumeSh
Definition Light.h:181
static constexpr int kMaxLights
Definition Light.h:172
static constexpr int kMaxDiffuseVolumeProbes
Definition Light.h:178
Light3DGpu lights[kMaxLights]
Definition Light.h:174
std::array< glm::vec4, 9 > diffuseProbeSh
Definition Light.h:176