Skip to content
Snippets Groups Projects
Commit ae0450b3 authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

[#82] Add UI controls for volumetric lighting

parent eb723db1
No related branches found
No related tags found
1 merge request!70Resolve "Voxel cone tracing"
Pipeline #26025 passed
......@@ -32,6 +32,13 @@ layout(set=0, binding=6) uniform VoxelInfoBuffer{
VoxelInfo voxelInfo;
};
layout(set=0, binding=7) uniform VolumetricSettings {
vec3 scatteringCoefficient;
float volumetricAmbientLight;
vec3 absorptionCoefficient;
};
vec3 cookTorrance(vec3 f0, float r, vec3 N, vec3 V, vec3 L){
vec3 H = normalize(L + V);
......@@ -78,10 +85,7 @@ vec3 volumetricLighting(vec3 colorIn, vec3 V, vec3 pos, float d){
int sampleCount = 48;
float stepSize = d / sampleCount;
vec3 scatteringCoefficient = vec3(0.005);
vec3 absorptionCoefficient = vec3(0.01);
vec3 extinctionCoefficient = scatteringCoefficient + absorptionCoefficient;
vec3 ambientLight = vec3(0.2);
float noiseScale = 0.1;
pos += V * noiseScale * interleavedGradientNoise(gl_FragCoord.xy);
......@@ -92,7 +96,7 @@ vec3 volumetricLighting(vec3 colorIn, vec3 V, vec3 pos, float d){
vec3 light = lightInfo.sunColor * lightInfo.sunStrength;
float shadow = shadowTest(samplePoint, lightInfo, shadowMap, shadowMapSampler, vec2(0));
light *= shadow;
light += ambientLight;
light += volumetricAmbientLight;
color += phase * light * scatteringCoefficient * stepSize;
color *= exp(-stepSize * extinctionCoefficient);
......
......@@ -444,12 +444,21 @@ int main(int argc, const char** argv) {
vkcv::Buffer<glm::vec3> cameraPosBuffer = core.createBuffer<glm::vec3>(vkcv::BufferType::UNIFORM, 1);
struct VolumetricSettings {
glm::vec3 scatteringCoefficient;
float ambientLight;
glm::vec3 absorptionCoefficient;
};
vkcv::Buffer<VolumetricSettings> volumetricSettingsBuffer
= core.createBuffer<VolumetricSettings>(vkcv::BufferType::UNIFORM ,1);
// write forward pass descriptor set
vkcv::DescriptorWrites forwardDescriptorWrites;
forwardDescriptorWrites.uniformBufferWrites = {
vkcv::UniformBufferDescriptorWrite(0, shadowMapping.getLightInfoBuffer()),
vkcv::UniformBufferDescriptorWrite(3, cameraPosBuffer.getHandle()),
vkcv::UniformBufferDescriptorWrite(6, voxelization.getVoxelInfoBufferHandle()) };
vkcv::UniformBufferDescriptorWrite(6, voxelization.getVoxelInfoBufferHandle()),
vkcv::UniformBufferDescriptorWrite(7, volumetricSettingsBuffer.getHandle())};
forwardDescriptorWrites.sampledImageWrites = {
vkcv::SampledImageDescriptorWrite(1, shadowMapping.getShadowMap()),
vkcv::SampledImageDescriptorWrite(4, voxelization.getVoxelImageHandle()) };
......@@ -470,6 +479,12 @@ int main(int argc, const char** argv) {
bool msaaCustomResolve = true;
glm::vec3 scatteringColor = glm::vec3(1);
float scatteringDensity = 0.001;
glm::vec3 absorptionColor = glm::vec3(1);
float absorptionDensity = 0.001;
float volumetricAmbient = 0.2;
auto start = std::chrono::system_clock::now();
const auto appStartTime = start;
while (window.isWindowOpen()) {
......@@ -567,6 +582,12 @@ int main(int argc, const char** argv) {
mainPassMatrices.push_back({ viewProjectionCamera * m, m });
}
VolumetricSettings volumeSettings;
volumeSettings.scatteringCoefficient = scatteringColor * scatteringDensity;
volumeSettings.absorptionCoefficient = absorptionColor * absorptionDensity;
volumeSettings.ambientLight = volumetricAmbient;
volumetricSettingsBuffer.fill({ volumeSettings });
const vkcv::PushConstantData pushConstantData((void*)mainPassMatrices.data(), 2 * sizeof(glm::mat4));
const std::vector<vkcv::ImageHandle> renderTargets = { colorBuffer, depthBuffer };
......@@ -655,6 +676,12 @@ int main(int argc, const char** argv) {
voxelizationExtent = std::max(voxelizationExtent, 1.f);
voxelVisualisationMip = std::max(voxelVisualisationMip, 0);
ImGui::ColorEdit3("Scattering color", &scatteringColor.x);
ImGui::DragFloat("Scattering density", &scatteringDensity, 0.0001);
ImGui::ColorEdit3("Absorption color", &absorptionColor.x);
ImGui::DragFloat("Absorption density", &absorptionDensity, 0.0001);
ImGui::DragFloat("Volumetric ambient", &volumetricAmbient, 0.002);
if (ImGui::Button("Reload forward pass")) {
vkcv::ShaderProgram newForwardProgram;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment