From e7d8aaf54a17c1cb9c16b0cc6a076060cfdf9bad Mon Sep 17 00:00:00 2001 From: Alexander Gauggel <agauggel@uni-koblenz.de> Date: Sat, 19 Jun 2021 10:36:06 +0200 Subject: [PATCH] [#81] Add sun color and brightness to UI --- .../voxelization/resources/shaders/shader.frag | 17 +++++++++-------- projects/voxelization/src/main.cpp | 16 ++++++++++------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/projects/voxelization/resources/shaders/shader.frag b/projects/voxelization/resources/shaders/shader.frag index edafc8c0..def0ea0c 100644 --- a/projects/voxelization/resources/shaders/shader.frag +++ b/projects/voxelization/resources/shaders/shader.frag @@ -11,7 +11,9 @@ layout(location = 2) in vec3 passPos; layout(location = 0) out vec3 outColor; layout(set=0, binding=0) uniform sunBuffer { - vec3 L; float padding; + vec3 L; float padding; + vec3 sunColor; + float sunStrength; mat4 lightMatrix; }; layout(set=0, binding=1) uniform texture2D shadowMap; @@ -35,11 +37,10 @@ float shadowTest(vec3 worldPos){ } void main() { - vec3 N = normalize(passNormal); - vec3 sunColor = vec3(1); - vec3 sun = sunColor * clamp(dot(N, L), 0, 1); - sun *= shadowTest(passPos); - vec3 ambient = vec3(0.1); - vec3 albedo = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb; - outColor = albedo * (sun + ambient); + vec3 N = normalize(passNormal); + vec3 sun = sunStrength * sunColor * clamp(dot(N, L), 0, 1); + sun *= shadowTest(passPos); + vec3 ambient = vec3(0.1); + vec3 albedo = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb; + outColor = albedo * (sun + ambient); } \ No newline at end of file diff --git a/projects/voxelization/src/main.cpp b/projects/voxelization/src/main.cpp index ec8153e7..1fecb63e 100644 --- a/projects/voxelization/src/main.cpp +++ b/projects/voxelization/src/main.cpp @@ -13,8 +13,8 @@ int main(int argc, const char** argv) { const char* applicationName = "Voxelization"; - uint32_t windowWidth = 800; - uint32_t windowHeight = 600; + uint32_t windowWidth = 1280; + uint32_t windowHeight = 720; vkcv::Window window = vkcv::Window::create( applicationName, @@ -156,9 +156,11 @@ int main(int argc, const char** argv) { // light info buffer struct LightInfo { - glm::vec3 direction; - float padding; - glm::mat4 lightMatrix; + glm::vec3 direction; + float padding; + glm::vec3 sunColor = glm::vec3(1.f); + float sunStrength = 1.f; + glm::mat4 lightMatrix; }; LightInfo lightInfo; vkcv::Buffer lightBuffer = core.createBuffer<LightInfo>(vkcv::BufferType::UNIFORM, sizeof(glm::vec3)); @@ -449,7 +451,9 @@ int main(int argc, const char** argv) { gui.beginGUI(); ImGui::Begin("Settings"); - ImGui::DragFloat2("Light angles", &lightAngles.x); + ImGui::DragFloat2("Light angles", &lightAngles.x); + ImGui::ColorEdit3("Sun color", &lightInfo.sunColor.x); + ImGui::DragFloat("Sun strength", &lightInfo.sunStrength); ImGui::End(); gui.endGUI(); -- GitLab