载入中...
搜索中...
未找到
Light.h
浏览该文件的文档.
1#pragma once
2
3#include "common/ECS.h"
4#include "zeroerr/assert.h"
5
6#include <cstdint>
7#include <string>
8#include <glm/glm.hpp>
9
10namespace eve::graphics {
11
12class Canvas;
13
15struct Light2DGpu {
16 glm::vec4 posRadius{0.f}; // xy = point pos or direction; w = radius (0 => directional)
17 glm::vec4 color{0.f}; // rgb * intensity
18};
19
21 static constexpr int kMaxLights = 8;
22 glm::vec4 ambient{0.15f, 0.15f, 0.18f, 0.f};
23 glm::vec4 meta{0.f}; // x = count, y = viewW, z = viewH
25};
26
31class Light2D : public ecs::Entity {
32public:
33 ENTITY(Light2D, ecs::Entity)
34
35 void release() override {}
36
37 struct Data {
38 std::string type = "point";
39 float x = 0.f;
40 float y = 0.f;
41 float dx = 0.f;
42 float dy = -1.f;
43 float r = 1.f, g = 1.f, b = 1.f;
44 float intensity = 1.f;
45 float radius = 200.f;
46 bool enabled = true;
48 bool volumetric = false;
50 Canvas *canvas = nullptr;
51 Light2D *entity = nullptr;
52 };
53
54 COMPONENT(Data, data)
55
56 static Light2D *createLight(const std::string &type = "point");
57
58 void setType(const std::string &type);
59 std::string getType();
60
61 void setPosition(float x, float y);
62 float getX();
63 float getY();
64
65 void setDirection(float dx, float dy);
66 float getDirX();
67 float getDirY();
68
69 void setColor(float r, float g, float b, float intensity = 1.f);
70 void setRadius(float radius);
71 float getRadius();
72
73 void setEnabled(bool enabled);
74 bool isEnabled();
75
76 void setVolumetric(bool enabled);
77 bool getVolumetric();
78 void setVolumetricIntensity(float intensity);
80
81 void setCanvas(Canvas *canvas);
82};
83
85struct Light3DGpu {
86 glm::vec4 posRadius{0.f}; // xyz = point pos or direction; w = radius (0 => directional)
87 glm::vec4 color{0.f}; // rgb * intensity
88};
89
91 static constexpr int kMaxLights = 8;
92 glm::vec4 ambient{0.12f, 0.12f, 0.14f, 0.f};
94 int count = 0;
95};
96
101class Light3D : public ecs::Entity {
102public:
103 ENTITY(Light3D, ecs::Entity)
104
105 void release() override {}
106
107 struct Data {
108 std::string type = "point";
109 float x = 0.f, y = 0.f, z = 0.f;
110 float dx = 0.4f, dy = 1.f, dz = 0.3f;
111 float r = 1.f, g = 1.f, b = 1.f;
112 float intensity = 1.f;
113 float radius = 8.f;
114 bool enabled = true;
115 bool castShadow = false; // only dir lights; at most one active caster per frame
116 float shadowBias = 0.f; // 0 = auto NDC from cascade texel / Z range
117 float shadowStrength = 1.f;
118 bool volumetric = false;
120 Light3D *entity = nullptr;
121 };
122
123 COMPONENT(Data, data)
124
125 static Light3D *createLight(const std::string &type = "point");
126
127 void setType(const std::string &type);
128 std::string getType();
129
130 void setPosition(float x, float y, float z);
131 float getX();
132 float getY();
133 float getZ();
134
135 void setDirection(float dx, float dy, float dz);
136 float getDirX();
137 float getDirY();
138 float getDirZ();
139
140 void setColor(float r, float g, float b, float intensity = 1.f);
141 void setRadius(float radius);
142 float getRadius();
143
144 void setEnabled(bool enabled);
145 bool isEnabled();
146
147 void setCastShadow(bool cast);
148 bool getCastShadow();
149 void setShadowBias(float bias);
150 float getShadowBias();
151 void setShadowStrength(float strength);
152 float getShadowStrength();
153
154 void setVolumetric(bool enabled);
155 bool getVolumetric();
156 void setVolumetricIntensity(float intensity);
158};
159
160} // namespace eve::graphics
std::string type
int y
Definition Grass.cpp:135
int z
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
uint32_t b
bool enabled
Declarative 2D light. Collected by RenderSystem (max 8 per canvas/frame). type: "point" | "dir" (≤15 ...
Definition Light.h:31
float getVolumetricIntensity()
Definition Light.cpp:59
void setDirection(float dx, float dy)
Definition Light.cpp:31
void setPosition(float x, float y)
Definition Light.cpp:23
void setColor(float r, float g, float b, float intensity=1.f)
Definition Light.cpp:39
void setVolumetric(bool enabled)
Definition Light.cpp:53
void setCanvas(Canvas *canvas)
Definition Light.cpp:61
void release() override
Definition Light.h:35
void setVolumetricIntensity(float intensity)
Definition Light.cpp:56
void setType(const std::string &type)
Definition Light.cpp:13
void setEnabled(bool enabled)
Definition Light.cpp:50
std::string getType()
Definition Light.cpp:21
static Light2D * createLight(const std::string &type="point")
Definition Light.cpp:5
void setRadius(float radius)
Definition Light.cpp:47
Declarative 3D light. Collected by RenderSystem3D (max 8 per frame). type: "point" | "dir" (≤15 chars...
Definition Light.h:101
void setEnabled(bool enabled)
Definition Light.cpp:114
void setCastShadow(bool cast)
Definition Light.cpp:117
void setDirection(float dx, float dy, float dz)
Definition Light.cpp:92
void setShadowBias(float bias)
Definition Light.cpp:120
float getVolumetricIntensity()
Definition Light.cpp:134
void release() override
Definition Light.h:105
float getShadowStrength()
Definition Light.cpp:126
void setShadowStrength(float strength)
Definition Light.cpp:123
void setPosition(float x, float y, float z)
Definition Light.cpp:81
static Light3D * createLight(const std::string &type="point")
Definition Light.cpp:63
void setType(const std::string &type)
Definition Light.cpp:71
void setVolumetricIntensity(float intensity)
Definition Light.cpp:131
void setRadius(float radius)
Definition Light.cpp:111
void setColor(float r, float g, float b, float intensity=1.f)
Definition Light.cpp:103
void setVolumetric(bool enabled)
Definition Light.cpp:128
std::string getType()
Definition Light.cpp:79
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition AnimTrail.h:6
GPU light packing for lit2d (std140-friendly).
Definition Light.h:15
bool volumetric
Contribute as volumetric shaft source when collecting occlusion maps.
Definition Light.h:48
GPU light packing for mesh3d / PBR (std140-friendly).
Definition Light.h:85
static constexpr int kMaxLights
Definition Light.h:21
Light2DGpu lights[kMaxLights]
Definition Light.h:24
static constexpr int kMaxLights
Definition Light.h:91
Light3DGpu lights[kMaxLights]
Definition Light.h:93