5 const bool use_diffuse_map = false;
6 const bool use_specular = false;
7 const bool use_specular_map = false;
8 const bool use_shininess_map = false;
9 const bool use_emission = false;
10 const bool use_emission_map = false;
11 const bool use_reflectivity = false;
12 const bool use_reflectivity_map = false;
13 const bool use_sky = false;
14 const bool use_fog = false;
16 #pragma MSP stage(fragment)
17 vec4 get_diffuse_color()
20 return texture(diffuse_map, texcoord.xy);
22 return basic_material.diffuse;
25 vec3 get_specular_color()
28 return texture(specular_map, texcoord.xy).rgb;
30 return basic_material.specular.rgb;
33 float get_shininess_value()
36 return texture(shininess_map, texcoord.xy).r*255.0;
38 return basic_material.shininess;
41 vec3 get_emission_color()
44 return texture(emission_map, texcoord.xy).rgb;
46 return basic_material.emission.rgb;
49 float get_reflectivity_value()
51 if(use_reflectivity_map)
52 return texture(reflectivity_map, texcoord.xy).r;
54 return basic_material.reflectivity;
57 vec3 phong_ambient(vec3 surface_diffuse)
59 return ambient_color.rgb*surface_diffuse;
62 vec3 phong_one_light(vec3 light, vec3 normal, vec3 look, vec3 light_color, vec3 surface_diffuse, vec3 surface_specular, float shininess)
64 float diffuse_intensity = max(dot(light, normal), 0.0);
65 vec3 color = light_color*surface_diffuse*diffuse_intensity;
68 /* The light vector points towards the light, so reflected will point
69 towards the surface - but so does the look vector. */
70 vec3 reflected = reflect(light, normal);
71 float specular_intensity = pow(max(dot(reflected, look), 0.0), shininess);
72 color += light_color*surface_specular*specular_intensity;
77 vec3 phong_lighting(vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_specular, float shininess)
81 light = normalize(tbn_light_dir);
83 light = normalize(eye_light_dir);
85 vec3 color = phong_ambient(surface_diffuse);
86 float shadow = get_shadow_factor(0);
87 color += phong_one_light(light, normal, look, light_sources[0].diffuse.rgb, surface_diffuse, surface_specular, shininess)*shadow;
90 color += get_emission_color();
93 color += get_reflection(normal, look)*get_reflectivity_value();
104 normal = get_fragment_normal();
105 look = normalize(tbn_look_dir);
109 normal = normalize(eye_normal);
110 look = normalize(eye_look_dir);
113 vec4 surface_diffuse = get_diffuse_color();
114 vec3 surface_specular = get_specular_color();
115 float shininess = get_shininess_value();
117 vec3 lit_color = phong_lighting(normal, look, surface_diffuse.rgb, surface_specular, shininess);
119 frag_color = vec4(lit_color, surface_diffuse.a);