feat: 多光源——点光源类型(距离衰减,位置来自 Transform)
- LightComponent 加 Type(Directional/Point)+ radius;点光位置取 实体 Transform(固有组件首次实际受益) - LightData shader 契约扩为 4×vec4(color/direction/position/params, 每灯 64B,未用字段置零);UBO 688→816B - 光照循环按类型分支:方向光无衰减;点光 L 指向光源 + 平方距离衰减, 衰减半径外跳过;CSM 阴影只来自第 0 盏方向光 - main.cpp:SunTemple 场景加暖橙火坑光 + 冷蓝填充光(点光); KeyLight/FillLight 改 designated initializer
This commit is contained in:
+27
-5
@@ -77,20 +77,41 @@ protected:
|
||||
e.AddComponent<MeshRendererComponent>(MeshRendererComponent{temple});
|
||||
}
|
||||
|
||||
// 灯光实体(第一个灯 = 阴影光源)
|
||||
// 灯光实体(第一个方向光 = 阴影光源)
|
||||
m_KeyLight = scene.CreateEntity("KeyLight");
|
||||
m_KeyLight.AddComponent<LightComponent>(
|
||||
LightComponent{
|
||||
glm::vec3(-0.5f, -0.6f, -0.35f),
|
||||
glm::vec4(1.0f, 0.95f, 0.9f, 1.0f)
|
||||
.type = LightComponent::Type::Directional,
|
||||
.direction = glm::vec3(-0.5f, -0.6f, -0.35f),
|
||||
.color = glm::vec4(1.0f, 0.95f, 0.9f, 1.0f)
|
||||
});
|
||||
|
||||
scene.CreateEntity("FillLight")
|
||||
.AddComponent<LightComponent>(
|
||||
LightComponent{
|
||||
glm::vec3(0.5f, -0.5f, 0.3f),
|
||||
glm::vec4(0.3f, 0.5f, 1.0f, 0.8f)
|
||||
.type = LightComponent::Type::Directional,
|
||||
.direction = glm::vec3(0.5f, -0.5f, 0.3f),
|
||||
.color = glm::vec4(0.3f, 0.5f, 1.0f, 0.8f)
|
||||
});
|
||||
|
||||
// 点光源(位置 = 实体 Transform,出生即有;无阴影,距离衰减)
|
||||
auto fire = scene.CreateEntity("FirePitLight");
|
||||
fire.GetComponent<TransformComponent>().SetPosition(glm::vec3(2.0f, 1.5f, 1.0f));
|
||||
fire.AddComponent<LightComponent>(
|
||||
LightComponent{
|
||||
.type = LightComponent::Type::Point,
|
||||
.color = glm::vec4(1.0f, 0.6f, 0.3f, 2.0f), // 暖橙
|
||||
.radius = 8.0f,
|
||||
});
|
||||
|
||||
auto cool = scene.CreateEntity("CoolFillLight");
|
||||
cool.GetComponent<TransformComponent>().SetPosition(glm::vec3(-2.5f, 2.0f, -2.0f));
|
||||
cool.AddComponent<LightComponent>(
|
||||
LightComponent{
|
||||
.type = LightComponent::Type::Point,
|
||||
.color = glm::vec4(0.3f, 0.5f, 1.0f, 1.2f), // 冷蓝
|
||||
.radius = 10.0f,
|
||||
});
|
||||
}
|
||||
|
||||
void OnUpdate(f32 deltaTime) override
|
||||
@@ -258,6 +279,7 @@ protected:
|
||||
|
||||
void OnWindowClose(const Event& event) override
|
||||
{
|
||||
SetImGuiEnabled(true);
|
||||
m_ShowQuitConfirm = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user