armory/Shaders/std/ssrs.glsl

38 lines
1.1 KiB
Plaintext
Raw Normal View History

2017-12-15 12:52:58 +01:00
#include "std/gbuffer.glsl"
2017-07-05 23:26:13 +02:00
uniform mat4 VP;
vec2 getProjectedCoord(vec3 hitCoord) {
vec4 projectedCoord = VP * vec4(hitCoord, 1.0);
projectedCoord.xy /= projectedCoord.w;
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
2018-11-27 21:44:56 +01:00
#ifdef HLSL
2017-07-05 23:26:13 +02:00
projectedCoord.y = 1.0 - projectedCoord.y;
#endif
return projectedCoord.xy;
}
2018-11-22 18:07:32 +01:00
float getDeltaDepth(vec3 hitCoord, sampler2D gbufferD, mat4 invVP, vec3 eye) {
2017-07-05 23:26:13 +02:00
vec2 texCoord = getProjectedCoord(hitCoord);
2018-11-22 18:07:32 +01:00
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
2017-07-05 23:26:13 +02:00
vec3 wpos = getPos2(invVP, depth, texCoord);
float d1 = length(eye - wpos);
float d2 = length(eye - hitCoord);
return d1 - d2;
}
2018-11-22 18:07:32 +01:00
float traceShadowSS(vec3 dir, vec3 hitCoord, sampler2D gbufferD, mat4 invVP, vec3 eye) {
2017-07-05 23:26:13 +02:00
dir *= ssrsRayStep;
// for (int i = 0; i < maxSteps; i++) {
hitCoord += dir;
2018-11-22 18:07:32 +01:00
if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.6;
2017-07-05 23:26:13 +02:00
hitCoord += dir;
2018-11-22 18:07:32 +01:00
if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.7;
2017-07-05 23:26:13 +02:00
hitCoord += dir;
2018-11-22 18:07:32 +01:00
if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.8;
2017-07-05 23:26:13 +02:00
hitCoord += dir;
2018-11-22 18:07:32 +01:00
if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.9;
2017-07-05 23:26:13 +02:00
//}
return 1.0;
}