1
0
Fork 0
fgdata/Shaders/HDR/geometry-pbr.frag

47 lines
1.3 KiB
GLSL
Raw Normal View History

2021-04-10 09:14:16 +00:00
#version 330 core
layout(location = 0) out vec4 gbuffer0;
layout(location = 1) out vec2 gbuffer1;
layout(location = 2) out vec4 gbuffer2;
in vec2 texCoord;
in mat3 TBN;
2021-07-31 10:59:16 +00:00
uniform sampler2D base_color_tex;
2021-04-10 09:14:16 +00:00
uniform sampler2D normal_tex;
2021-08-16 15:04:18 +00:00
uniform sampler2D metallic_roughness_tex;
2021-07-31 10:59:16 +00:00
uniform sampler2D occlusion_tex;
uniform sampler2D emissive_tex;
uniform vec4 base_color_factor;
uniform float metallic_factor;
uniform float roughness_factor;
uniform vec3 emissive_factor;
2021-08-16 15:04:18 +00:00
uniform float alpha_cutoff;
2021-04-10 09:14:16 +00:00
vec2 encodeNormal(vec3 n);
2021-07-31 10:59:16 +00:00
vec3 decodeSRGB(vec3 screenRGB);
2021-04-10 09:14:16 +00:00
void main()
{
2021-08-16 15:04:18 +00:00
vec4 baseColorTexel = texture(base_color_tex, texCoord);
vec4 baseColor = vec4(decodeSRGB(baseColorTexel.rgb), baseColorTexel.a)
* base_color_factor;
if (baseColor.a < alpha_cutoff)
discard;
gbuffer0.rgb = baseColor.rgb;
2021-07-31 10:59:16 +00:00
float occlusion = texture(occlusion_tex, texCoord).r;
gbuffer0.a = occlusion;
2021-04-10 09:14:16 +00:00
vec3 normal = texture(normal_tex, texCoord).rgb * 2.0 - 1.0;
normal = normalize(TBN * normal);
gbuffer1 = encodeNormal(normal);
2021-08-16 15:04:18 +00:00
vec4 metallicRoughness = texture(metallic_roughness_tex, texCoord);
float metallic = metallicRoughness.r * metallic_factor;
float roughness = metallicRoughness.g * roughness_factor;
2021-07-31 10:59:16 +00:00
gbuffer2 = vec4(metallic, roughness, 0.0, 0.0);
2021-04-10 09:14:16 +00:00
2021-07-31 10:59:16 +00:00
vec3 emissive = texture(emissive_tex, texCoord).rgb * emissive_factor;
2021-04-10 09:14:16 +00:00
}