111 lines
2.3 KiB
GLSL
111 lines
2.3 KiB
GLSL
// - Position in view space
|
|
layout (location = 0) out vec4 outPosition;
|
|
// - Albedo + Roughness
|
|
layout (location = 1) out vec4 outAlbedo;
|
|
// - Normal buffer
|
|
layout (location = 2) out vec3 outNormal;
|
|
// - Emission + Metallic
|
|
layout (location = 3) out vec4 outEmission;
|
|
|
|
#ifdef ALPHA_MASK
|
|
uniform sampler2D alphaMask;
|
|
#endif
|
|
|
|
#ifdef ALBEDO_TEXTURE
|
|
uniform sampler2D albedoTexture;
|
|
#else
|
|
uniform vec3 albedo;
|
|
#endif
|
|
|
|
#ifdef EMISSION_TEXTURE
|
|
uniform sampler2D emissionTexture;
|
|
#else
|
|
uniform vec3 emission;
|
|
#endif
|
|
|
|
#ifdef ROUGHNESS_TEXTURE
|
|
uniform sampler2D roughnessTexture;
|
|
#else
|
|
uniform float roughness;
|
|
#endif
|
|
|
|
#ifdef METALLIC_TEXTURE
|
|
uniform sampler2D metallicTexture;
|
|
#else
|
|
uniform float metallic;
|
|
#endif
|
|
|
|
in vec4 posInView;
|
|
#ifdef NORMAL_MAP
|
|
uniform sampler2D normalMap;
|
|
|
|
in vec3 varTangent;
|
|
in vec3 varBinormal;
|
|
#endif
|
|
|
|
#ifdef WIREFRAME
|
|
in vec3 varColor;
|
|
#else
|
|
in vec3 varNormal;
|
|
|
|
in vec2 varTexCoord;
|
|
#endif
|
|
|
|
void main()
|
|
{
|
|
#ifdef WIREFRAME
|
|
outAlbedo.rgb = vec3(0., 0., 0.); // black
|
|
outAlbedo.a = 1.; // full roughness
|
|
outEmission.rgb = varColor;
|
|
outEmission.a = 0.; // not metallic
|
|
outNormal = vec3(0., 0., 1.); // oriented towards the eye
|
|
#else
|
|
|
|
#ifdef ALPHA_MASK
|
|
if(texture(alphaMask, varTexCoord).r < 0.5)
|
|
discard;
|
|
#endif
|
|
|
|
#ifdef NORMAL_MAP
|
|
vec3 normalTexel = normalize(texture(normalMap, varTexCoord).xyz -0.5);
|
|
vec3 tangent = normalize(varTangent);
|
|
vec3 binormal = normalize(varBinormal);
|
|
vec3 normal = normalize(varNormal);
|
|
mat3 tangentSpace = mat3(vec3(tangent.x, binormal.x, normal.x),
|
|
vec3(tangent.y, binormal.y, normal.y),
|
|
vec3(tangent.z, binormal.z, normal.z));
|
|
|
|
outNormal = normalize(normalTexel * tangentSpace);
|
|
#else
|
|
outNormal = normalize(varNormal);
|
|
#endif
|
|
|
|
#ifdef ALBEDO_TEXTURE
|
|
outAlbedo.rgb = texture(albedoTexture, varTexCoord).rgb;
|
|
#else
|
|
outAlbedo.rgb = albedo;
|
|
#endif
|
|
|
|
#ifdef ROUGHNESS_TEXTURE
|
|
outAlbedo.a = texture(roughnessTexture, varTexCoord).r;
|
|
#else
|
|
outAlbedo.a = roughness;
|
|
#endif
|
|
|
|
#ifdef EMISSION_TEXTURE
|
|
outEmission.rgb = texture(emissionTexture, varTexCoord).rgb;
|
|
#else
|
|
outEmission.rgb = emission;
|
|
#endif
|
|
|
|
#ifdef METALLIC_TEXTURE
|
|
outEmission.a = texture(metallicTexture, varTexCoord).r;
|
|
#else
|
|
outEmission.a = metallic;
|
|
#endif
|
|
|
|
#endif // WIREFRAME
|
|
|
|
outPosition = posInView;
|
|
}
|