diff options
author | David Thompson <dthompson2@worcester.edu> | 2021-08-12 20:25:25 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2021-08-12 20:25:25 -0400 |
commit | 8925bd867e1a8791801698b1abaec4a46180656e (patch) | |
tree | 9a7a31445e86952a85b185969bfde2780cfdc5d0 /data/shaders/phong-frag.glsl | |
parent | f82e5122c2feabb8d92e3d4d1789ee1490b96a90 (diff) |
graphics: Always use normal/ambient/etc. maps.
If models don't specify their own textures, use noop textures as
appropriate.
Diffstat (limited to 'data/shaders/phong-frag.glsl')
-rw-r--r-- | data/shaders/phong-frag.glsl | 62 |
1 files changed, 21 insertions, 41 deletions
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() { |