Created
June 3, 2023 09:31
-
-
Save JuanDiegoMontoya/048465167999e54eb8dc166bc2bcabf1 to your computer and use it in GitHub Desktop.
Adaptive shadow map sampling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint pixel_index = uint(gl_FragCoord.x) + uint(gl_FragCoord.y) * 4096u; | |
uint seed = pcg_hash(pixel_index); | |
float shadow = Shadow(seed, fragWorldPos, normal, -shadingUniforms.sunDir.xyz); | |
float shadow_accum = shadow; | |
int succ = 0; | |
for (int i = 0; i < 4; i++) | |
{ | |
if (shadow_accum / (i + 1) > 0.0 && shadow_accum / (i + 1) < 2.0 / (shadowUniforms.pcfSamples * (i + 1)) + 0.0001) | |
{ | |
succ++; | |
seed = pcg_hash(seed ^ 12321); | |
shadow = Shadow(seed, fragWorldPos, normal, -shadingUniforms.sunDir.xyz); | |
shadow_accum += shadow; | |
// switch (i) | |
// { | |
// case 0: diffuse = vec3(1, 0, 0); break; | |
// case 1: diffuse = vec3(0, 1, 0); break; | |
// case 2: diffuse = vec3(0, 1, 1); break; | |
// case 3: diffuse = vec3(1, 1, 0); break; | |
// } | |
} | |
} | |
shadow = shadow_accum / (succ + 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment