Skip to content

Commit a2a00d6

Browse files
committed
SSSS optimization, vsync
1 parent cf478cb commit a2a00d6

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

main.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ int main()
216216
// Creating Second Window
217217
bool enableGui = true;
218218
bool autoRotation = false;
219+
bool verticalSync = true;
219220
gui.AddCallback([&]() {
220221
const float width = 320.0f;
221222
const float height = 475.0f;
@@ -236,6 +237,11 @@ int main()
236237
LightRendering::PrintDepthMap();
237238
}
238239

240+
if (ImGui::Checkbox("V-Sync", &verticalSync))
241+
{
242+
glfwSwapInterval(verticalSync); // Disables V-Sync
243+
}
244+
239245
if (ImGui::Checkbox("SSSS Enabled", (bool *)humanHead.GetShaderAttribute<int>("ssssEnabled")))
240246
{
241247
*humanHead2.GetShaderAttribute<int>("ssssEnabled") = *humanHead.GetShaderAttribute<int>("ssssEnabled");
@@ -341,6 +347,10 @@ int main()
341347
glfwSetInputMode(window->window, GLFW_CURSOR,
342348
cameraLock ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
343349
}
350+
if (cameraLock)
351+
{
352+
353+
}
344354

345355
// Font change
346356
if (window->key(GLFW_KEY_F) == InputKey::JustPressed)

resources/Shaders/PBR/SeparableSSS.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,15 @@ float3 SSSSTransmittance(
344344
int samples = 17;
345345
int offset = (samples - 1) / 2;
346346
vec2 texelSize = 1.0 / textureSize(shadowMap, 0);
347+
float d2 = shadowPosition.z * lightFarPlane;
347348
for (int x = -offset; x <= offset; ++x)
348349
{
349350
for (int y = -offset; y <= offset; ++y)
350351
{
351352
float d1 = SSSSSample(shadowMap, shadowPosition.xy + vec2(x, y) * texelSize).r; // 'd1' has a range of 0..1
352-
float d2 = shadowPosition.z; // 'd2' has a range of 0..'lightFarPlane'
353353
d1 *= lightFarPlane; // So we scale 'd1' accordingly:
354-
d2 *= lightFarPlane;
354+
if (d1 == d2) continue;
355355
float d = scale * abs(d1 - d2);
356-
//if (abs(d1 - d2) > 1.0) return vec3(0.0);
357356

358357
/**
359358
* Armed with the thickness, we can now calculate the color by means of the

resources/Shaders/PBR/pbr.frag.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ float ShadowCalculation(vec4 fragPosLightSpace, sampler2D shadowMap, vec3 lightP
185185
for(int y = -offset; y <= offset; ++y)
186186
{
187187
float pcfDepth = texture(shadowMap, projCoords.xy + vec2(x, y) * texelSize).r;
188-
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
188+
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
189189
}
190190
}
191191
shadow /= samples * samples;

0 commit comments

Comments
 (0)