5 struct BasicMaterialParameters
16 BasicMaterialParameters basic_material;
19 uniform sampler2D diffuse_map;
20 uniform sampler2D specular_map;
21 uniform sampler2D shininess_map;
22 uniform sampler2D emission_map;
23 uniform sampler2D reflectivity_map;
25 layout(constant_id=auto) const bool use_diffuse_map = false;
26 layout(constant_id=auto) const bool use_specular = false;
27 layout(constant_id=auto) const bool use_specular_map = false;
28 layout(constant_id=auto) const bool use_shininess_map = false;
29 layout(constant_id=auto) const bool use_emission = false;
30 layout(constant_id=auto) const bool use_emission_map = false;
31 layout(constant_id=auto) const bool use_reflectivity = false;
32 layout(constant_id=auto) const bool use_reflectivity_map = false;
33 layout(constant_id=auto) const bool use_sky = false;
34 layout(constant_id=auto) const bool use_fog = false;
36 #pragma MSP stage(fragment)
37 virtual vec4 get_diffuse_color()
40 return texture(diffuse_map, texcoord.xy);
42 return basic_material.diffuse;
45 virtual vec3 get_specular_color()
48 return texture(specular_map, texcoord.xy).rgb;
50 return basic_material.specular.rgb;
53 virtual float get_shininess_value()
56 return texture(shininess_map, texcoord.xy).r*255.0;
58 return basic_material.shininess;
61 virtual vec3 get_emission_color()
64 return texture(emission_map, texcoord.xy).rgb;
66 return basic_material.emission.rgb;
69 virtual float get_reflectivity_value()
71 if(use_reflectivity_map)
72 return texture(reflectivity_map, texcoord.xy).r;
74 return basic_material.reflectivity;
77 vec3 phong_ambient(vec3 surface_diffuse)
79 return ambient_color.rgb*surface_diffuse;
82 vec3 phong_one_light(vec3 light, vec3 normal, vec3 look, vec3 light_color, vec3 surface_diffuse, vec3 surface_specular, float shininess)
84 float diffuse_intensity = max(dot(light, normal), 0.0);
85 vec3 color = light_color*surface_diffuse*diffuse_intensity;
88 vec3 reflected = reflect(look, normal);
89 float specular_intensity = pow(max(dot(reflected, light), 0.0), shininess);
90 color += light_color*surface_specular*specular_intensity;
95 vec3 phong_lighting(vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_specular, float shininess)
97 vec3 color = phong_ambient(surface_diffuse);
98 for(int i=0; i<max_lights; ++i)
99 if(light_sources[i].type!=0)
101 vec3 light = get_light_direction(i);
102 float shadow = get_shadow_factor(i);
103 color += phong_one_light(light, normal, look, light_sources[i].color, surface_diffuse, surface_specular, shininess)*shadow;
107 color += get_emission_color();
110 color += get_reflection(normal, look)*get_reflectivity_value();
117 vec3 normal = get_fragment_normal();
118 vec3 look = normalize(world_look_dir);
120 vec4 surface_diffuse = get_diffuse_color();
121 vec3 surface_specular = get_specular_color();
122 float shininess = get_shininess_value();
124 vec3 lit_color = phong_lighting(normal, look, surface_diffuse.rgb, surface_specular, shininess);
126 frag_color = vec4(lit_color, surface_diffuse.a);