#version 330 uniform mat4 view; out vec4 color; in vec4 vertexColor; in mat3 TBN; in vec3 fPos; in vec2 TCordinate; uniform sampler2D diffuse; uniform sampler2D roughness; uniform sampler2D normal; const vec3 lightColor = vec3(1.0f, 1.0f, 1.0f); const vec3 lightDir = vec3(-1.0f, -1.0f, 1.0f); const float ambient = 0.24f; const float specularValue = 1.0f; void main() { vec4 diffuseBase = texture(diffuse, TCordinate); vec3 normal = texture(normal, TCordinate).rgb; normal = normal * 2.0f - 1.0f; normal = normalize(mat3(view) * TBN * normal); vec3 lightNormal = normalize(vec3(view * vec4(lightDir, 0.0f))); float diffValue = max(dot(normal, lightNormal), 0.0f); float diffuse = diffValue; vec3 viewDir = normalize(-fPos); vec3 reflectDir = reflect(-lightNormal, normal); float spec = pow(max(dot(viewDir, reflectDir), 0.0f), 16); float specular = specularValue * spec; float roughness = texture(roughness, TCordinate).g; color = vertexColor * diffuseBase * vec4((ambient + diffuse) * lightColor, 1.0f) + vec4(roughness * specular * lightColor, 1.0f); }