Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
GPUDirectionalLight.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Logger.hpp"
6#include "glm/glm.hpp"
7#include "utils/webgpu.hpp"
8#include <entt/core/hashed_string.hpp>
9
12 using Id = entt::hashed_string;
13
17 wgpu::TextureView shadowTextureView;
19
21 {
22 // Why do we negate the forward vector?
23 glm::vec3 lightDirection = -glm::normalize(transform.GetForwardVector() * transform.GetScale());
24 glm::vec3 posOfLight = transform.GetPosition();
25 glm::mat4 lightProjection = light.projection;
26 glm::vec3 target = posOfLight + glm::normalize(lightDirection) * 10.0f;
27 auto up = glm::abs(glm::dot(glm::normalize(lightDirection), glm::vec3(0.0f, 1.0f, 0.0f))) > 0.99f ?
28 glm::vec3(1.0f, 0.0f, 0.0f) :
29 glm::vec3(0.0f, 1.0f, 0.0f);
30 glm::mat4 lightView = glm::lookAt(posOfLight, target, up);
31 glm::mat4 lightSpaceMatrix = lightProjection * lightView;
32
33 viewProjectionMatrix = lightSpaceMatrix;
34 }
35};
36}; // namespace DefaultPipeline::Component
Definition GPUCamera.hpp:9
Definition GPUDirectionalLight.hpp:11
wgpu::TextureView shadowTextureView
Definition GPUDirectionalLight.hpp:17
void Update(const Object::Component::DirectionalLight &light, const Object::Component::Transform &transform)
Definition GPUDirectionalLight.hpp:20
uint32_t shadowTextureIndex
Definition GPUDirectionalLight.hpp:18
entt::hashed_string Id
Definition GPUDirectionalLight.hpp:12
glm::mat4 viewProjectionMatrix
Definition GPUDirectionalLight.hpp:14
Id buffer
Definition GPUDirectionalLight.hpp:15
Id bindGroupData
Definition GPUDirectionalLight.hpp:16
Definition DirectionalLight.hpp:8
glm::mat4 projection
Definition DirectionalLight.hpp:10
Definition Transform.hpp:18
glm::vec3 GetForwardVector() const
Definition Transform.hpp:73
const glm::vec3 & GetPosition() const
Definition Transform.hpp:37
const glm::vec3 & GetScale() const
Definition Transform.hpp:38