#version 450 const int MAX_TEXTURES = 256; out vec4 outPos; out vec3 outNormal; out vec3 outTangent; out vec3 outBitangent; out vec2 outTextCoords; out vec4 outAlbedo ; out vec4 outPosition; out vec4 outNormals; out vec4 outPBR; struct Material { vec4 diffuse; int hasTexture; int hasNormalMap; int hasRoughMap; float roughnessFactor; float metallicFactor; }; uniform sampler2D textureSampler; uniform sampler2D normalSampler; uniform sampler2D roughnessSampler; uniform Material material; vec3 calcNormal(Material material, vec3 normal, vec2 textCoords, mat3 TBN) { vec3 newNormal = normal; if (material.hasNormalMap > 0) { newNormal = texture(normalSampler, textCoords).rgb; newNormal = normalize(newNormal * 2.0 - 1.0); newNormal = normalize(TBN * newNormal); } return newNormal; } layout(push_constant) uniform pc { layout(offset = 64) uint materialIdx; } push_constants; void main() { outPosition = outPos; if (material.hasTexture == 1) { outAlbedo = texture(textureSampler, outTextCoords); } else { outAlbedo = material.diffuse; } if(outAlbedo.a < 0.5) discard; mat3 TBN = mat3( outTangent, outBitangent, outNormal); vec3 newNormal = calcNormal(material, outNormal, outTextCoords, TBN); outNormals = vec4(newNormal, 1.0f); float ao = 0.5f; float roughnessFactor = 0.0f; float metallicFactor = 0.0f; if (material.hasRoughMap > 0) { vec4 metRoughValue = texture(roughnessSampler, outTextCoords); roughnessFactor = metRoughValue.g; metallicFactor = metRoughValue.b; } else { roughnessFactor = material.roughnessFactor; metallicFactor = material.metallicFactor; } outPBR = vec4(ao, roughnessFactor, metallicFactor, 1.0f); }