Skip to content

Commit 4c998bb

Browse files
committed
add fog
1 parent 89e81b9 commit 4c998bb

File tree

7 files changed

+13
-4
lines changed

7 files changed

+13
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ add_library(ReactorLib STATIC
6969
)
7070

7171
target_compile_definitions(ReactorLib PUBLIC GLM_ENABLE_EXPERIMENTAL)
72-
72+
target_compile_definitions(ReactorLib PUBLIC GLM_FORCE_DEPTH_ZERO_TO_ONE)
7373

7474
target_link_libraries(ReactorLib PUBLIC
7575
Vulkan::Vulkan

shaders/composite.frag

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ layout(set = 0, binding = 1) uniform CompositeParams {
1414
float uSaturation; // Default: 1.0
1515
float uVignetteIntensity; // Default: 0.5
1616
float uVignetteFalloff; // Default 0.5
17+
float uFogDensity;
1718
};
1819

1920
// add camera projection uniforms to the UBO or pass them in another way
@@ -47,7 +48,8 @@ void main() {
4748
float fogEnd = 5.0;
4849
float viewDistance = linearizeDepth(depth);
4950
// Calculate fog amount (0.0 = no fog, 1.0 = full fog)
50-
float fogFactor = smoothstep(fogStart, fogEnd, viewDistance);
51+
//float fogFactor = smoothstep(fogStart, fogEnd, viewDistance);
52+
float fogFactor = uFogDensity;
5153
// ----------------------
5254

5355
// Sample the HDR input image
@@ -70,7 +72,7 @@ void main() {
7072
finalColor = mix(grayscale, finalColor, uSaturation);
7173

7274
// Mix the final scene color with the fog color
73-
//finalColor = mix(finalColor, fogColor, fogFactor);
75+
finalColor = mix(finalColor, fogColor, fogFactor);
7476

7577
outColor = vec4(finalColor, 1.0);
7678
}

src/core/Camera.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "Camera.hpp"
22

3-
#define GLM_ENABLE_EXPERIMENTAL
43
#include <glm/gtc/matrix_transform.hpp>
54
#include <glm/gtc/constants.hpp>
65
#include <glm/gtx/euler_angles.hpp>

src/core/Uniforms.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ struct DirectionalLightUBO
1111
glm::vec4 lightPosition = glm::vec4(-0.5f, 1.0f, -0.5f, 0.0f);
1212
glm::vec4 lightColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f);
1313
float lightIntensity = 1.0f;
14+
// add 12-bytes of padding
15+
float pad[3];
1416
};
1517

1618
struct CompositeUBO {
@@ -19,4 +21,5 @@ struct CompositeUBO {
1921
float uSaturation = 1.0f;
2022
float uVignetteIntensity = 0.5f;
2123
float uVignetteFalloff = 0.5f;
24+
float uFogDensity = 0.001f;
2225
};

src/imgui/Imgui.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ void Imgui::ShowInspector() {
191191
ImGui::SliderFloat("Exposure", &m_exposure, 0.0, 2.0);
192192
ImGui::SliderFloat("Contrast", &m_contrast, 0.0, 2.0);
193193
ImGui::SliderFloat("Saturation", &m_saturation, 0.0, 2.0);
194+
195+
ImGui::SliderFloat("Fog Density", &m_fogDensity, 0.0, 0.5);
194196
ImGui::End();
195197
}
196198

src/imgui/Imgui.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Imgui {
2222
[[nodiscard]] float getExposure() const { return m_exposure; }
2323
[[nodiscard]] float getContrast() const { return m_contrast; }
2424
[[nodiscard]] float getSaturation() const { return m_saturation; }
25+
[[nodiscard]] float getFogDensity() const { return m_fogDensity; }
2526

2627
static vk::DescriptorSet createDescriptorSet(vk::ImageView imageView, vk::Sampler sampler);
2728
void setSceneDescriptorSet(const vk::DescriptorSet descriptorSet) { m_sceneImguiId = descriptorSet; };
@@ -37,6 +38,7 @@ class Imgui {
3738
float m_exposure = 1.0f;
3839
float m_contrast = 1.0f;
3940
float m_saturation = 1.0f;
41+
float m_fogDensity = 0.001f;
4042

4143
void ShowDockspace();
4244
void ShowSceneView();

src/vulkan/VulkanRenderer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ void VulkanRenderer::drawFrame()
263263
compositeData.uExposure = m_imgui->getExposure();
264264
compositeData.uContrast = m_imgui->getContrast();
265265
compositeData.uSaturation = m_imgui->getSaturation();
266+
compositeData.uFogDensity = m_imgui->getFogDensity();
266267
m_uniformManager->update<CompositeUBO>(frameIdx, compositeData);
267268

268269
SceneUBO ubo{};

0 commit comments

Comments
 (0)