improve shadows

This commit is contained in:
MihailRis
2025-05-21 21:41:01 +03:00
parent 44f7051a94
commit ed5efd9c3a
5 changed files with 68 additions and 65 deletions
+14 -17
View File
@@ -16,24 +16,21 @@ vec4 effect() {
vec3 bitangent = cross(normal, tangent);
mat3 tbn = mat3(tangent, bitangent, normal);
float occlusion = 1.0;
if (u_enableShadows) {
occlusion = 0.0;
for (int i = 0; i < kernelSize; i++) {
vec3 samplePos = tbn * u_ssaoSamples[i];
samplePos = position + samplePos * radius;
vec4 offset = vec4(samplePos, 1.0);
offset = u_projection * offset;
offset.xyz /= offset.w;
offset.xyz = offset.xyz * 0.5 + 0.5;
float sampleDepth = texture(u_position, offset.xy).z;
float rangeCheck = smoothstep(0.0, 1.0, radius / abs(position.z - sampleDepth));
occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck;
}
occlusion = min(1.0, 1.05 - (occlusion / kernelSize));
float occlusion = 0.0;
for (int i = 0; i < kernelSize; i++) {
vec3 samplePos = tbn * u_ssaoSamples[i];
samplePos = position + samplePos * radius;
vec4 offset = vec4(samplePos, 1.0);
offset = u_projection * offset;
offset.xyz /= offset.w;
offset.xyz = offset.xyz * 0.5 + 0.5;
float sampleDepth = texture(u_position, offset.xy).z;
float rangeCheck = smoothstep(0.0, 1.0, radius / abs(position.z - sampleDepth));
occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck;
}
occlusion = min(1.0, 1.05 - (occlusion / kernelSize));
float z = -position.z * 0.02;
z = max(0.0, 1.0 - z);