armory/Shaders/probe_planar/probe_planar.frag.glsl

55 lines
1.2 KiB
Plaintext
Raw Permalink Normal View History

2018-10-01 22:01:03 +02:00
#version 450
#include "compiled.inc"
#include "std/gbuffer.glsl"
2018-10-04 15:35:33 +02:00
uniform sampler2D probeTex;
2018-11-22 18:07:32 +01:00
uniform sampler2D gbufferD;
2018-10-03 13:59:34 +02:00
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
uniform mat4 probeVP;
uniform mat4 invVP;
uniform vec3 proben;
2018-10-01 22:01:03 +02:00
in vec4 wvpposition;
out vec4 fragColor;
void main() {
vec2 texCoord = wvpposition.xy / wvpposition.w;
texCoord = texCoord * 0.5 + 0.5;
2020-05-11 09:03:13 +02:00
#ifdef _InvY
2018-10-01 22:01:03 +02:00
texCoord.y = 1.0 - texCoord.y;
#endif
2018-12-06 15:23:08 +01:00
vec4 g0 = textureLod(gbuffer0, texCoord, 0.0); // Normal.xy, metallic/roughness, depth
2018-10-03 13:59:34 +02:00
2019-07-07 22:02:07 +02:00
float roughness = g0.b;
2018-10-03 13:59:34 +02:00
if (roughness > 0.95) {
fragColor.rgb = vec3(0.0);
return;
}
2018-12-06 15:23:08 +01:00
float spec = fract(textureLod(gbuffer1, texCoord, 0.0).a);
2018-10-03 13:59:34 +02:00
if (spec == 0.0) {
fragColor.rgb = vec3(0.0);
return;
}
2018-12-06 15:23:08 +01:00
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
2018-10-03 13:59:34 +02:00
vec3 wp = getPos2(invVP, depth, texCoord);
vec4 pp = probeVP * vec4(wp.xyz, 1.0);
vec2 tc = (pp.xy / pp.w) * 0.5 + 0.5;
2020-05-11 09:03:13 +02:00
#ifdef _InvY
2018-12-21 11:37:10 +01:00
tc.y = 1.0 - tc.y;
#endif
2018-10-03 13:59:34 +02:00
vec2 enc = g0.rg;
vec3 n;
n.z = 1.0 - abs(enc.x) - abs(enc.y);
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
n = normalize(n);
float intensity = clamp((1.0 - roughness) * dot(n, proben), 0.0, 1.0);
2018-10-04 15:35:33 +02:00
fragColor.rgb = texture(probeTex, tc).rgb * intensity;
2018-10-01 22:01:03 +02:00
}