From 8925bd867e1a8791801698b1abaec4a46180656e Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 12 Aug 2021 20:25:25 -0400 Subject: graphics: Always use normal/ambient/etc. maps. If models don't specify their own textures, use noop textures as appropriate. --- data/shaders/phong-frag.glsl | 62 +++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 41 deletions(-) (limited to 'data/shaders/phong-frag.glsl') diff --git a/data/shaders/phong-frag.glsl b/data/shaders/phong-frag.glsl index 363c4e7..0beb75b 100644 --- a/data/shaders/phong-frag.glsl +++ b/data/shaders/phong-frag.glsl @@ -2,13 +2,9 @@ struct Material { vec3 ambient; - bool useAmbientMap; vec3 diffuse; - bool useDiffuseMap; vec3 specular; - bool useSpecularMap; float shininess; - bool useNormalMap; }; struct Light { @@ -100,53 +96,37 @@ vec3 lightRadiance(Light light, vec3 direction) { } vec3 materialAmbient() { - if(material.useAmbientMap) { - return texture(ambientMap, fragTex).rgb; - } else { - return material.ambient; - } + return texture(ambientMap, fragTex).rgb * material.ambient; } vec3 materialDiffuse() { - if(material.useDiffuseMap) { - vec4 color = texture(diffuseMap, fragTex); - // discard transparent fragments. - if(color.a == 0.0) { - discard; - } - return color.rgb; - } else { - return material.diffuse; + vec4 color = texture(diffuseMap, fragTex); + // discard transparent fragments. + if(color.a == 0.0) { + discard; } + return color.rgb * material.diffuse; } vec3 materialSpecular() { - if(material.useSpecularMap) { - return texture(specularMap, fragTex).rgb; - } else { - return material.specular; - } + return texture(specularMap, fragTex).rgb * material.specular; } vec3 materialNormal() { - if(material.useNormalMap) { - // Compute tangent space using fragment data rather than relying - // on tangent attributes. See: - // http://www.thetenthplanet.de/archives/1180 - vec3 tangentNormal = normalize(texture(normalMap, fragTex).xyz * 2.0 - 1.0); - vec3 q1 = dFdx(fragWorldPos); - vec3 q2 = dFdy(fragWorldPos); - vec2 st1 = dFdx(fragTex); - vec2 st2 = dFdy(fragTex); - vec3 N = normalize(fragNorm); - vec3 T = normalize(q1 * st2.t - q2 * st1.t); - vec3 B = -normalize(cross(N, T)); - mat3 TBN = mat3(T, B, N); - - return normalize(TBN * tangentNormal); - } else { - return normalize(fragNorm); - } + // Compute tangent space using fragment data rather than relying + // on tangent attributes. See: + // http://www.thetenthplanet.de/archives/1180 + vec3 tangentNormal = normalize(texture(normalMap, fragTex).xyz * 2.0 - 1.0); + vec3 q1 = dFdx(fragWorldPos); + vec3 q2 = dFdy(fragWorldPos); + vec2 st1 = dFdx(fragTex); + vec2 st2 = dFdy(fragTex); + vec3 N = normalize(fragNorm); + vec3 T = normalize(q1 * st2.t - q2 * st1.t); + vec3 B = -normalize(cross(N, T)); + mat3 TBN = mat3(T, B, N); + + return normalize(TBN * tangentNormal); } void main() { -- cgit v1.2.3