5 struct BasicMaterialParameters
14 layout(set=1) uniform BasicMaterial
16 BasicMaterialParameters basic_material;
17 AlphaCutoffParameters alpha_cutoff;
20 layout(set=1) uniform sampler2D diffuse_map;
21 layout(set=1) uniform sampler2D specular_map;
22 layout(set=1) uniform sampler2D shininess_map;
23 layout(set=1) uniform sampler2D emission_map;
24 layout(set=1) uniform sampler2D reflectivity_map;
26 layout(constant_id=auto) const bool use_diffuse_map = false;
27 layout(constant_id=auto) const bool use_specular = false;
28 layout(constant_id=auto) const bool use_specular_map = false;
29 layout(constant_id=auto) const bool use_shininess_map = false;
30 layout(constant_id=auto) const bool use_emission = false;
31 layout(constant_id=auto) const bool use_emission_map = false;
32 layout(constant_id=auto) const bool use_reflectivity = false;
33 layout(constant_id=auto) const bool use_reflectivity_map = false;
35 #pragma MSP stage(fragment)
36 virtual vec4 get_diffuse_color()
39 return texture(diffuse_map, texcoord.xy);
41 return basic_material.diffuse;
44 virtual vec3 get_specular_color()
47 return texture(specular_map, texcoord.xy).rgb;
49 return basic_material.specular.rgb;
52 virtual float get_shininess_value()
55 return texture(shininess_map, texcoord.xy).r*255.0;
57 return basic_material.shininess;
60 virtual vec3 get_emission_color()
63 return texture(emission_map, texcoord.xy).rgb;
65 return basic_material.emission.rgb;
68 virtual float get_reflectivity_value()
70 if(use_reflectivity_map)
71 return texture(reflectivity_map, texcoord.xy).r;
73 return basic_material.reflectivity;
76 vec3 phong_ambient(vec3 surface_diffuse)
78 return ambient_color.rgb*surface_diffuse;
81 vec3 phong_one_light(vec3 light, vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_specular, float shininess)
83 float diffuse_intensity = max(dot(light, normal), 0.0);
84 vec3 color = surface_diffuse*diffuse_intensity;
87 vec3 reflected = reflect(look, normal);
88 float specular_intensity = pow(max(dot(reflected, light), 0.0), shininess);
89 color += surface_specular*specular_intensity;
94 vec3 phong_lighting(vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_specular, float shininess)
96 vec3 color = phong_ambient(surface_diffuse);
97 for(int i=0; i<max_lights; ++i)
98 if(light_sources[i].type!=0)
100 IncomingLight incoming = get_incoming_light(i, world_vertex.xyz);
101 float shadow = get_shadow_factor(i, world_vertex);
102 color += phong_one_light(incoming.direction, normal, look, surface_diffuse, surface_specular, shininess)*incoming.color*shadow;
106 color += get_emission_color();
109 color += get_reflection(normal, look)*get_reflectivity_value();
116 vec4 surface_diffuse = get_diffuse_color();
117 float alpha = apply_alpha_cutoff(surface_diffuse.a, alpha_cutoff);
119 vec3 normal = get_fragment_normal();
120 vec3 look = normalize(world_look_dir);
122 vec3 surface_specular = get_specular_color();
123 float shininess = get_shininess_value();
125 vec3 lit_color = phong_lighting(normal, look, surface_diffuse.rgb, surface_specular, shininess);
127 frag_color = vec4(lit_color, alpha);