Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rt fx #18

Merged
merged 21 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed last remaining relevant issue before PR merge
  • Loading branch information
tippesi committed Nov 18, 2022
commit ca9f0f8768d26f40ef118c5ab38b7f614bcebe91
2 changes: 1 addition & 1 deletion data/shader/ao/rtao.csh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void main() {
ao += hit ? 1.0 : 0.0;
}

float result = pow(1.0 - (ao / float(sampleCount)), 1.0);
float result = 1.0 - (ao / float(sampleCount));

imageStore(rtaoImage, pixel, vec4(result, 0.0, 0.0, 0.0));
}
Expand Down
2 changes: 1 addition & 1 deletion data/shader/ao/ssao.csh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void main() {

}

float result = pow(1.0 - (occlusion / float(sampleCount)), strength);
float result = pow(1.0 - (occlusion / float(sampleCount)), 2.0);
result = depth == 1.0 ? 0.0 : result;
imageStore(textureOut, pixel, vec4(result, 0.0, 0.0, 0.0));

Expand Down
3 changes: 2 additions & 1 deletion data/shader/deferred/indirect.csh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ uniform float indirectStrength = 1.0;
uniform bool aoEnabled = true;
uniform bool aoDownsampled2x;
uniform bool reflectionEnabled = true;
uniform float aoStrength = 1.0;

// (localSize / 2 + 2)^2
shared float depths[36];
Expand Down Expand Up @@ -155,7 +156,7 @@ void main() {
// This normally only accounts for diffuse occlusion, we need seperate terms
// for diffuse and specular.
float occlusionFactor = aoEnabled ? aoDownsampled2x ? UpsampleAo2x(depth) : texture(aoTexture, texCoord).r : 1.0;
indirect *= occlusionFactor;
indirect *= pow(occlusionFactor, aoStrength);

vec3 direct = imageLoad(image, pixel).rgb;
imageStore(image, pixel, vec4(direct + indirect, 0.0));
Expand Down
2 changes: 1 addition & 1 deletion data/shader/reflection/atrous.csh
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void main() {
centerNormal, sampleNormal,
centerLinearDepth, sampleLinearDepth,
centerRoughness, sampleRoughness,
stdDeviation * 10, 2.0,
stdDeviation * 5.0, 2.0,
1.0, 0.05);

float weight = kernelWeight * edgeStoppingWeight;
Expand Down
18 changes: 6 additions & 12 deletions data/shader/reflection/temporal.csh
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ void main() {
uint materialIdx = texelFetch(materialIdxTexture, pixel, 0).r;
Material material = UnpackMaterial(materialIdx);

float roughness = texelFetch(roughnessMetallicAoTexture, pixel, 0).r;
material.roughness *= material.roughnessMap ? roughness : 1.0;
float roughness = material.roughness;
roughness *= material.roughnessMap ? texelFetch(roughnessMetallicAoTexture, pixel, 0).r : 1.0;

float factor = clamp(16.0 * log(material.roughness + 1.0), 0.001, 0.95);
factor = (uv.x < 0.0 || uv.y < 0.0 || uv.x > 1.0
Expand All @@ -275,25 +275,22 @@ void main() {
float confidence = 1.0;

uint historyMaterialIdx = texelFetch(materialIdxTexture, offsetPixel, 0).r;
//confidence *= historyMaterialIdx != materialIdx ? 0.1 : 1.0;
confidence *= historyMaterialIdx != materialIdx ? 0.1 : 1.0;

vec3 historyNormal = 2.0 * texelFetch(normalTexture, offsetPixel, 0).rgb - 1.0;
//confidence *= pow(abs(dot(historyNormal, normal)), 2.0);
confidence *= pow(abs(dot(historyNormal, normal)), 2.0);

float historyDepth = texelFetch(depthTexture, offsetPixel, 0).r;
float historyLinearDepth = ConvertDepthToViewSpaceDepth(historyDepth);
//confidence *= min(1.0 , exp(-abs(linearDepth - historyLinearDepth)));

confidence = exp(-abs(1.0 - max(0.0, dot(normal, historyNormal))))
* exp(-abs(historyLinearDepth - linearDepth));
confidence *= min(1.0 , exp(-abs(linearDepth - historyLinearDepth) / linearDepth));

maxConfidence = max(maxConfidence, confidence);
}

factor *= maxConfidence;

float historyLength = historyMoments.b;
if (factor <= 0.1) {
if (factor < 0.1 * roughness) {
historyLength = 0.0;
currentMoments.g = 1.0;
currentMoments.r = 0.0;
Expand All @@ -309,9 +306,6 @@ void main() {
float variance = max(0.0, momentsResolve.g - momentsResolve.r * momentsResolve.r);
variance *= varianceBoost;

// No spatial filtering for mirror reflections
variance = material.roughness < 0.001 ? 0.0 : variance;

imageStore(momentsImage, pixel, vec4(momentsResolve, historyLength + 1.0, 0.0));
imageStore(resolveImage, pixel, vec4(vec3(resolve), variance));

Expand Down
2 changes: 1 addition & 1 deletion data/sponza/sponza.mtl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ newmtl column_a
map_bump textures\sponza_column_a_bump.png

newmtl floor
Ns 70.0000
Ns 300.0000
Ni 1.5000
d 1.0000
Tr 0.0000
Expand Down
9 changes: 6 additions & 3 deletions demo/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ void App::Render(float deltaTime) {
ImGui::Text(("Camera location: " + vecToString(camera.location)).c_str());
ImGui::Text(("Scene dimensions: " + vecToString(sceneAABB.min) + " to " + vecToString(sceneAABB.max)).c_str());
ImGui::Text(("Scene triangle count: " + std::to_string(triangleCount)).c_str());
ImGui::Checkbox("Move camera", &moveCamera);
ImGui::Checkbox("Rotate camera", &rotateCamera);

{
const char* items[] = { "Cornell box", "Sponza", "San Miguel",
Expand Down Expand Up @@ -372,7 +370,7 @@ void App::Render(float deltaTime) {
This is only possible when cascaded shadow maps are not used.");
}
ImGui::Checkbox("Enable GI in reflection", &reflection->gi);
ImGui::SliderInt("Sample count", &reflection->sampleCount, 1, 32);
// ImGui::SliderInt("Sample count", &reflection->sampleCount, 1, 32);
ImGui::SliderFloat("Radiance Limit##Reflection", &reflection->radianceLimit, 0.0f, 10.0f);
ImGui::SliderFloat("Bias##Reflection", &reflection->bias, 0.0f, 1.0f);
}
Expand All @@ -381,6 +379,10 @@ void App::Render(float deltaTime) {
ImGui::SliderFloat("Speed##Camera", &cameraSpeed, 0.0f, 20.0f);
ImGui::SliderFloat("FOV##Camera", &camera.fieldOfView, 0.0f, 90.0f);
keyboardHandler.speed = cameraSpeed;
ImGui::Separator();
ImGui::Text("Camera debugging");
ImGui::Checkbox("Move camera", &moveCamera);
ImGui::Checkbox("Rotate camera", &rotateCamera);
}
if (ImGui::CollapsingHeader("Fog")) {
ImGui::Checkbox("Enable##Fog", &fog->enable);
Expand Down Expand Up @@ -617,6 +619,7 @@ bool App::LoadScene() {
sky = Atlas::Texture::Cubemap("environment.hdr", 2048);

// Other scene related settings apart from the mesh
directionalLight.direction = glm::vec3(0.0f, -1.0f, 0.33f);
directionalLight.intensity = 100.0f;
directionalLight.GetVolumetric()->intensity = 0.28f;
scene.irradianceVolume->SetRayCount(128, 32);
Expand Down
7 changes: 6 additions & 1 deletion src/RenderTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ namespace Atlas {
* @param width The width of the render target
* @param height The height of the render target
*/
RenderTarget(int32_t width, int32_t height);
explicit RenderTarget(int32_t width, int32_t height);

/**
* The render target doesn't support copy due to framebuffers
*/
RenderTarget& operator=(const RenderTarget& that) = delete;

/**
* Resizes the render target.
Expand Down
2 changes: 1 addition & 1 deletion src/lighting/AO.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Atlas {
int32_t sampleCount = 16;

float radius = 3.0f;
float strength = 2.0f;
float strength = 1.0f;

bool enable = true;
bool rt = false;
Expand Down
12 changes: 6 additions & 6 deletions src/renderer/AORenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Atlas {

AORenderer::AORenderer() {

const int32_t filterSize = 2;
const int32_t filterSize = 4;
blurFilter.CalculateGaussianFilter(float(filterSize) / 3.0f, filterSize);

auto noiseImage = Loader::ImageLoader::LoadImage<uint8_t>("noise.png");
Expand Down Expand Up @@ -126,9 +126,9 @@ namespace Atlas {
glDispatchCompute(groupCount.x, groupCount.y, 1);
}

Profiler::EndAndBeginQuery("Temporal filter");
if (ao->rt) {
Profiler::EndAndBeginQuery("Temporal filter");

{
ivec2 groupCount = ivec2(res.x / 8, res.y / 8);
groupCount.x += ((groupCount.x * 8 == res.x) ? 0 : 1);
groupCount.y += ((groupCount.y * 8 == res.y) ? 0 : 1);
Expand Down Expand Up @@ -157,9 +157,9 @@ namespace Atlas {
target->historyAoTexture = target->aoTexture;
target->historyAoMomentsTexture = target->aoMomentsTexture;

Profiler::EndAndBeginQuery("Blur");

{
Profiler::EndAndBeginQuery("Blur");

const int32_t groupSize = 256;

depthTexture->Bind(GL_TEXTURE1);
Expand All @@ -174,7 +174,7 @@ namespace Atlas {
kernelWeights = std::vector<float>(kernelWeights.begin() + mean, kernelWeights.end());
kernelOffsets = std::vector<float>(kernelOffsets.begin() + mean, kernelOffsets.end());

for (int32_t i = 0; i < 10; i++) {
for (int32_t i = 0; i < 5; i++) {
ivec2 groupCount = ivec2(res.x / groupSize, res.y);
groupCount.x += ((res.x % groupSize == 0) ? 0 : 1);

Expand Down
5 changes: 3 additions & 2 deletions src/renderer/IndirectLightRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ namespace Atlas {
shader.GetUniform("volumeMax")->SetValue(vec3(0.0f));
}

auto ssao = scene->ao;
auto ao = scene->ao;
auto reflection = scene->reflection;

target->aoTexture.Bind(GL_TEXTURE6);
target->GetDownsampledTextures(target->GetAOResolution())->depthTexture->Bind(GL_TEXTURE14);
target->reflectionTexture.Bind(GL_TEXTURE16);
shader.GetUniform("aoEnabled")->SetValue(ssao && ssao->enable);
shader.GetUniform("aoEnabled")->SetValue(ao && ao->enable);
shader.GetUniform("aoDownsampled2x")->SetValue(target->GetAOResolution() == RenderResolution::HALF_RES);
shader.GetUniform("reflectionEnabled")->SetValue(reflection && reflection->enable);
shader.GetUniform("aoStrength")->SetValue(ao && ao->enable ? ao->strength : 1.0f);

shader.GetUniform("ivMatrix")->SetValue(camera->invViewMatrix);
shader.GetUniform("ipMatrix")->SetValue(camera->invProjectionMatrix);
Expand Down
2 changes: 1 addition & 1 deletion src/volume/BVH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace Atlas {
Log::Message("Max triangles: " + std::to_string(BVHBuilder::maxTriangles));
Log::Message("Num spatial splits: " + std::to_string(BVHBuilder::spatialSplitCount));
Log::Message("Surface area: " + std::to_string(BVHBuilder::totalSurfaceArea));
Log::Message("Finished BVH build\n");
Log::Message("Finished BVH build");

}

Expand Down