summaryrefslogtreecommitdiff
path: root/data/shaders/phong-frag.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'data/shaders/phong-frag.glsl')
-rw-r--r--data/shaders/phong-frag.glsl62
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() {