60 lines
1.6 KiB
GLSL
60 lines
1.6 KiB
GLSL
layout(location = 0) in vec3 inFragPos;
|
|
layout(location = 1) in vec3 inNormal;
|
|
layout(location = 2) in vec2 inUV;
|
|
layout(location = 3) in mat3 TBN;
|
|
|
|
layout(location = 0) out vec4 outFragPos;
|
|
layout(location = 1) out vec4 outNormal;
|
|
layout(location = 2) out vec4 outAlbedo;
|
|
layout(location = 3) out vec4 outMaterial;
|
|
|
|
layout(std140, binding = 0) uniform UniformObjectData {
|
|
mat4 projection, view, model;
|
|
vec4 albedoTint;
|
|
vec4 emission;
|
|
float metallic, roughness;
|
|
} objectData;
|
|
|
|
layout(binding = 1) uniform sampler2D albedoSampler;
|
|
layout(binding = 2) uniform sampler2D normalSampler;
|
|
layout(binding = 3) uniform sampler2D metallicSampler;
|
|
layout(binding = 4) uniform sampler2D roughnessSampler;
|
|
|
|
vec3 GetAlbedo() {
|
|
if(textureSize(albedoSampler, 0).x <= 1)
|
|
return objectData.albedoTint.rgb;
|
|
|
|
return texture(albedoSampler, inUV).rgb * objectData.albedoTint.rgb;
|
|
}
|
|
|
|
vec3 GetNormal() {
|
|
if(textureSize(normalSampler, 0).x <= 1)
|
|
return normalize(inNormal);
|
|
|
|
vec3 normal = texture(normalSampler, inUV).rgb;
|
|
normal = 2.0 * normal - 1.0;
|
|
normal = TBN * normal;
|
|
|
|
return normalize(normal);
|
|
}
|
|
|
|
float GetMetallic() {
|
|
if(textureSize(metallicSampler, 0).x <= 1)
|
|
return objectData.metallic;
|
|
|
|
return texture(metallicSampler, inUV).r;
|
|
}
|
|
|
|
float GetRoughness() {
|
|
if(textureSize(roughnessSampler, 0).x <= 1)
|
|
return objectData.roughness;
|
|
|
|
return texture(roughnessSampler, inUV).r;
|
|
}
|
|
|
|
void main() {
|
|
outFragPos = vec4(inFragPos, 1.0);
|
|
outNormal = vec4(GetNormal(), 1.0);
|
|
outAlbedo = vec4(GetAlbedo(), 1.0);
|
|
outMaterial = vec4(GetRoughness(), GetMetallic(), objectData.emission.r, 1.0);
|
|
}
|