Improve directional shadow integration GT framing

This commit is contained in:
2026-04-05 00:41:52 +08:00
parent 2ddbe24b82
commit 061e74d98f
2 changed files with 39 additions and 30 deletions

File diff suppressed because one or more lines are too long

View File

@@ -93,36 +93,45 @@ Mesh* CreateGroundMesh() {
params.guid = ResourceGUID::Generate(params.path);
mesh->Initialize(params);
StaticMeshVertex vertices[4] = {};
vertices[0].position = Vector3(-4.5f, 0.0f, 1.5f);
vertices[0].normal = Vector3::Up();
vertices[0].uv0 = Vector2(0.0f, 1.0f);
vertices[1].position = Vector3(-4.5f, 0.0f, 9.5f);
vertices[1].normal = Vector3::Up();
vertices[1].uv0 = Vector2(0.0f, 0.0f);
vertices[2].position = Vector3(4.5f, 0.0f, 1.5f);
vertices[2].normal = Vector3::Up();
vertices[2].uv0 = Vector2(1.0f, 1.0f);
vertices[3].position = Vector3(4.5f, 0.0f, 9.5f);
vertices[3].normal = Vector3::Up();
vertices[3].uv0 = Vector2(1.0f, 0.0f);
std::vector<StaticMeshVertex> vertices;
std::vector<uint32_t> indices;
vertices.reserve(8);
indices.reserve(12);
AppendQuadFace(
vertices, indices,
Vector3(-8.0f, 0.0f, 0.5f),
Vector3(-8.0f, 0.0f, 12.0f),
Vector3(8.0f, 0.0f, 0.5f),
Vector3(8.0f, 0.0f, 12.0f),
Vector3::Up());
AppendQuadFace(
vertices, indices,
Vector3(-8.0f, 0.0f, 12.0f),
Vector3(8.0f, 0.0f, 12.0f),
Vector3(-8.0f, 6.0f, 12.0f),
Vector3(8.0f, 6.0f, 12.0f),
Vector3::Back());
const uint32_t indices[6] = { 0, 1, 2, 2, 1, 3 };
mesh->SetVertexData(
vertices,
sizeof(vertices),
4,
vertices.data(),
vertices.size() * sizeof(StaticMeshVertex),
static_cast<uint32_t>(vertices.size()),
sizeof(StaticMeshVertex),
VertexAttribute::Position | VertexAttribute::Normal | VertexAttribute::UV0);
mesh->SetIndexData(indices, sizeof(indices), 6, true);
const Bounds bounds(Vector3(0.0f, 0.0f, 5.5f), Vector3(9.0f, 0.1f, 8.0f));
mesh->SetIndexData(
indices.data(),
indices.size() * sizeof(uint32_t),
static_cast<uint32_t>(indices.size()),
true);
const Bounds bounds(Vector3(0.0f, 3.0f, 6.25f), Vector3(16.0f, 6.0f, 11.5f));
mesh->SetBounds(bounds);
MeshSection section = {};
section.baseVertex = 0;
section.vertexCount = 4;
section.vertexCount = static_cast<uint32_t>(vertices.size());
section.startIndex = 0;
section.indexCount = 6;
section.indexCount = static_cast<uint32_t>(indices.size());
section.materialID = 0;
section.bounds = bounds;
mesh->AddSection(section);
@@ -279,11 +288,11 @@ void DirectionalShadowSceneTest::SetUp() {
mGroundMaterial = CreateForwardLitMaterial(
"DirectionalShadowGround",
"Tests/Rendering/DirectionalShadowGround.material",
Vector4(0.82f, 0.83f, 0.86f, 1.0f));
Vector4(0.92f, 0.93f, 0.96f, 1.0f));
mCasterMaterial = CreateForwardLitMaterial(
"DirectionalShadowCaster",
"Tests/Rendering/DirectionalShadowCaster.material",
Vector4(0.82f, 0.34f, 0.24f, 1.0f));
Vector4(0.72f, 0.22f, 0.16f, 1.0f));
BuildScene();
@@ -363,18 +372,18 @@ void DirectionalShadowSceneTest::BuildScene() {
camera->SetNearClipPlane(0.1f);
camera->SetFarClipPlane(100.0f);
camera->SetClearColor(XCEngine::Math::Color(0.03f, 0.03f, 0.05f, 1.0f));
cameraObject->GetTransform()->SetLocalPosition(Vector3(0.0f, 2.2f, -1.8f));
cameraObject->GetTransform()->SetLocalPosition(Vector3(0.0f, 2.6f, -4.6f));
cameraObject->GetTransform()->SetLocalRotation(
Quaternion::LookRotation(Vector3(0.0f, -0.22f, 1.0f).Normalized()));
Quaternion::LookRotation(Vector3(0.0f, -0.10f, 1.0f).Normalized()));
GameObject* lightObject = mScene->CreateGameObject("MainDirectionalLight");
auto* light = lightObject->AddComponent<LightComponent>();
light->SetLightType(LightType::Directional);
light->SetColor(XCEngine::Math::Color(1.0f, 1.0f, 0.97f, 1.0f));
light->SetIntensity(1.8f);
light->SetIntensity(2.1f);
light->SetCastsShadows(true);
lightObject->GetTransform()->SetLocalRotation(
Quaternion::LookRotation(Vector3(-0.32f, -0.78f, -0.54f).Normalized()));
Quaternion::LookRotation(Vector3(0.55f, -0.35f, 0.76f).Normalized()));
GameObject* groundObject = mScene->CreateGameObject("Ground");
auto* groundMeshFilter = groundObject->AddComponent<MeshFilterComponent>();
@@ -385,8 +394,8 @@ void DirectionalShadowSceneTest::BuildScene() {
groundMeshRenderer->SetReceiveShadows(true);
GameObject* casterObject = mScene->CreateGameObject("CasterCube");
casterObject->GetTransform()->SetLocalPosition(Vector3(0.0f, 0.8f, 4.5f));
casterObject->GetTransform()->SetLocalScale(Vector3(1.2f, 1.6f, 1.2f));
casterObject->GetTransform()->SetLocalPosition(Vector3(-3.2f, 1.4f, 7.4f));
casterObject->GetTransform()->SetLocalScale(Vector3(1.4f, 2.8f, 1.4f));
auto* casterMeshFilter = casterObject->AddComponent<MeshFilterComponent>();
auto* casterMeshRenderer = casterObject->AddComponent<MeshRendererComponent>();
casterMeshFilter->SetMesh(ResourceHandle<Mesh>(mCubeMesh));