Make the lighting directional again

This commit is contained in:
bailehuni 2024-03-27 15:01:05 +00:00
parent cda6a99e5c
commit dfd892b146
5 changed files with 15 additions and 10 deletions

View File

@ -48,7 +48,7 @@ void main() {
float light_distance = length(fragLightPosTangentSpace - fragPosTangentSpace); float light_distance = length(fragLightPosTangentSpace - fragPosTangentSpace);
float attenuation = 1.0 / (1.0 + 0.09 * light_distance + float attenuation = 1.0 / (1.0 + 0.09 * light_distance +
0.032 * (light_distance * light_distance)); 0.032 * (light_distance * light_distance));
light_colour *= 5.0 * attenuation; //light_colour *= 5.0 * attenuation;
const vec3 emission = vec3(0.0, 0.0, 0.0); const vec3 emission = vec3(0.0, 0.0, 0.0);
@ -56,7 +56,7 @@ void main() {
const vec3 N = GetNormal(); const vec3 N = GetNormal();
const vec3 V = normalize(fragViewPosTangentSpace - fragPosTangentSpace); const vec3 V = normalize(fragViewPosTangentSpace - fragPosTangentSpace);
const vec3 L = normalize(fragLightPosTangentSpace - fragPosTangentSpace); const vec3 L = normalize(fragLightPosTangentSpace /* - fragPosTangentSpace */ );
//const vec3 L = normalize(vec3(5.0, 0.0, 3.0)); //const vec3 L = normalize(vec3(5.0, 0.0, 3.0));
const vec3 H = normalize(V + L); const vec3 H = normalize(V + L);

View File

@ -39,8 +39,8 @@ void main() {
fragUV = inUV; fragUV = inUV;
fragPosTangentSpace = worldToTangentSpace * vec3(worldPosition); fragPosTangentSpace = worldToTangentSpace * vec3(worldPosition);
fragViewPosTangentSpace = worldToTangentSpace * vec3(inverse(frameSetUniformBuffer.view) * vec4(0.0, 0.0, 0.0, 1.0)); fragViewPosTangentSpace = worldToTangentSpace * vec3(inverse(frameSetUniformBuffer.view) * vec4(0.0, 0.0, 0.0, 1.0));
//fragLightPosTangentSpace = worldToTangentSpace * vec3(-0.4278,0.7923,0.43502); fragLightPosTangentSpace = worldToTangentSpace * vec3(-0.4278,0.7923,0.43502); // directional light
fragLightPosTangentSpace = worldToTangentSpace * vec3(10.0, 0.0, 10.0); //fragLightPosTangentSpace = worldToTangentSpace * vec3(10.0, 0.0, 10.0);
fragNormWorldSpace = N; fragNormWorldSpace = N;
fragViewPosWorldSpace = vec3(inverse(frameSetUniformBuffer.view) * vec4(0.0, 0.0, 0.0, 1.0)); fragViewPosWorldSpace = vec3(inverse(frameSetUniformBuffer.view) * vec4(0.0, 0.0, 0.0, 1.0));

View File

@ -72,7 +72,7 @@ static constexpr uint32_t FRAMES_IN_FLIGHT = 2; // This improved FPS by 5x
static constexpr size_t PUSH_CONSTANT_MAX_SIZE = 128; // bytes static constexpr size_t PUSH_CONSTANT_MAX_SIZE = 128; // bytes
static constexpr VkIndexType INDEX_TYPE = VK_INDEX_TYPE_UINT32; static constexpr VkIndexType INDEX_TYPE = VK_INDEX_TYPE_UINT32;
static constexpr int kShadowmapSize = 1024; static constexpr int kShadowmapSize = 2048;
// structures and enums // structures and enums

View File

@ -32,12 +32,12 @@ Renderer::Renderer(Application& app, gfx::GraphicsSettings settings) : Applicati
} }
global_uniform.layout = device_->CreateDescriptorSetLayout(globalSetBindings); global_uniform.layout = device_->CreateDescriptorSetLayout(globalSetBindings);
global_uniform.set = device_->AllocateDescriptorSet(global_uniform.layout); global_uniform.set = device_->AllocateDescriptorSet(global_uniform.layout);
// const glm::vec3 light_location = glm::vec3{-0.4278, 0.7923, 0.43502} * 10.0f; const glm::vec3 light_location = glm::vec3{-0.4278, 0.7923, 0.43502} * 40.0f;
const glm::vec3 light_location = glm::vec3{10.0f, 0.0f, 10.0f}; //const glm::vec3 light_location = glm::vec3{10.0f, 0.0f, 10.0f};
// const glm::mat4 light_proj = glm::orthoRH_ZO(-10.0f, 10.0f, -10.0f, 10.0f, 1.0f, 50.0f); const glm::mat4 light_proj = glm::orthoRH_ZO(-24.0f, 24.0f, -15.0f, 15.0f, 10.0f, 65.0f);
const glm::mat4 light_proj = glm::perspectiveFovRH_ZO(glm::radians(90.0f), 1.0f, 1.0f, 5.0f, 50.0f); //const glm::mat4 light_proj = glm::perspectiveFovRH_ZO(glm::radians(90.0f), 1.0f, 1.0f, 5.0f, 50.0f);
const glm::mat4 light_view = glm::lookAtRH(light_location, glm::vec3{0.0f, 0.0f, 0.0f}, glm::vec3{0.0f, 0.0f, 1.0f}); const glm::mat4 light_view = glm::lookAtRH(light_location, glm::vec3{0.0f, 0.0f, 0.0f}, glm::vec3{0.0f, 0.0f, 1.0f});
global_uniform.uniform_buffer_data.data.proj = glm::mat4{1.0f}; global_uniform.uniform_buffer_data.data.proj = light_proj;
global_uniform.uniform_buffer_data.data.lightSpaceMatrix = light_proj * light_view; global_uniform.uniform_buffer_data.data.lightSpaceMatrix = light_proj * light_view;
global_uniform.uniform_buffer = device_->CreateUniformBuffer(sizeof(global_uniform.uniform_buffer_data), &global_uniform.uniform_buffer_data); global_uniform.uniform_buffer = device_->CreateUniformBuffer(sizeof(global_uniform.uniform_buffer_data), &global_uniform.uniform_buffer_data);
device_->UpdateDescriptorUniformBuffer(global_uniform.set, 0, global_uniform.uniform_buffer, 0, sizeof(global_uniform.uniform_buffer_data)); device_->UpdateDescriptorUniformBuffer(global_uniform.set, 0, global_uniform.uniform_buffer, 0, sizeof(global_uniform.uniform_buffer_data));

View File

@ -77,6 +77,11 @@ void PlayGame(GameSettings settings)
/* create camera */ /* create camera */
engine::Entity camera = main_scene->CreateEntity("camera"); engine::Entity camera = main_scene->CreateEntity("camera");
auto camren = main_scene->AddComponent<engine::MeshRenderableComponent>(camera);
camren->visible = true;
camren->mesh = GenSphereMesh(app.renderer()->GetDevice(), 0.2f, 10);
camren->material = app.GetResource<engine::Material>("builtin.default");
/* as of right now, the entity with tag 'camera' is used to build the view /* as of right now, the entity with tag 'camera' is used to build the view
* matrix */ * matrix */