armory/Shaders/probe_cubemap/probe_cubemap.frag.glsl

55 lines
1.2 KiB
Plaintext
Raw Normal View History

2018-10-04 15:35:33 +02:00
#version 450
#include "compiled.inc"
#include "std/gbuffer.glsl"
uniform samplerCube probeTex;
2018-12-21 11:37:10 +01:00
uniform sampler2D gbufferD;
2018-10-04 15:35:33 +02:00
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
uniform mat4 invVP;
2018-10-05 17:32:02 +02:00
uniform vec3 probep;
2018-10-04 15:35:33 +02:00
uniform vec3 eye;
in vec4 wvpposition;
out vec4 fragColor;
void main() {
vec2 texCoord = wvpposition.xy / wvpposition.w;
texCoord = texCoord * 0.5 + 0.5;
2018-11-27 21:44:56 +01:00
#ifdef HLSL
2018-10-04 15:35:33 +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-04 15:35:33 +02:00
2019-07-07 22:02:07 +02:00
float roughness = g0.b;
2018-10-04 15:35:33 +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-04 15:35:33 +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-04 15:35:33 +02:00
vec3 wp = getPos2(invVP, depth, texCoord);
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);
vec3 v = wp - eye;
2019-01-15 20:49:03 +01:00
vec3 r = reflect(v, n);
#ifdef HLSL
r.y = -r.y;
#endif
2018-10-05 17:32:02 +02:00
float intensity = clamp((1.0 - roughness) * dot(wp - probep, n), 0.0, 1.0);
2019-01-15 20:49:03 +01:00
fragColor.rgb = texture(probeTex, r).rgb * intensity;
2018-10-04 15:35:33 +02:00
}