1 // Deprecated; use phong.glsl instead.
4 const bool use_vertex_color = false;
6 const bool use_lighting = false;
7 const bool use_specular = false;
8 const bool use_sky = false;
9 const bool use_fog = false;
11 const bool use_diffuse_map = false;
12 const bool use_normal_map = false;
14 const bool use_shadow_map = false;
16 const bool use_environment_map = false;
18 #pragma MSP stage(vertex)
19 vec4 get_vertex_position()
24 vec3 get_vertex_normal()
29 void singlepass_transform_and_lighting()
31 out vec4 eye_vertex = eye_obj_matrix*get_vertex_position();
32 gl_Position = projection_matrix*eye_vertex;
34 out vec3 eye_normal = eye_obj_normal_matrix*get_vertex_normal();
35 vec3 eye_tangent = eye_obj_normal_matrix*tangent;
36 vec3 eye_binormal = eye_obj_normal_matrix*binormal;
37 out mat3 eye_tbn_matrix = mat3(eye_tangent, eye_binormal, eye_normal);
39 out vec3 incident_dir = normalize(eye_vertex.xyz);
41 incident_dir = incident_dir*eye_tbn_matrix;
43 vec3 ldir = normalize(light_sources[0].position.xyz-eye_vertex.xyz*light_sources[0].position.w);
45 ldir = ldir*eye_tbn_matrix;
46 out vec3 light_dir = ldir;
48 out vec3 tbn_zenith_dir = eye_zenith_dir*eye_tbn_matrix;
49 out vec3 shadow_coord = (shd_eye_matrix*eye_vertex).xyz;
50 out float fog_coord = eye_vertex.z;
52 for(int i=0; i<max_clip_planes; ++i)
53 gl_ClipDistance[i] = dot(eye_vertex, clip_planes[i].equation);
58 singlepass_transform_and_lighting();
62 #pragma MSP stage(fragment)
63 vec4 get_diffuse_sample()
65 return texture(diffuse_map, texcoord.xy);
68 vec3 get_normal_sample()
70 return texture(normal_map, texcoord.xy).xyz*2.0-1.0;
73 vec4 get_environment_sample(vec3 direction)
75 return texture(environment_map, direction);
81 vec3 singlepass_lighting()
83 float shadow_sample = texture(shadow_map, shadow_coord);
84 float shadow_intensity = mix(1.0, shadow_sample, shadow_darkness);
86 vec3 ambient_light = ambient_color.rgb;
91 zenith_dir = tbn_zenith_dir;
93 zenith_dir = eye_zenith_dir;
94 float skylight_intensity = dot(normal, zenith_dir)*0.5+0.5;
95 ambient_light += skylight_intensity*sky_color.rgb;
98 vec3 n_light_dir = normalize(light_dir);
99 float diffuse_intensity = max(dot(normal, n_light_dir), 0.0);
101 diffuse_intensity *= shadow_intensity;
102 vec3 diffuse_light = diffuse_intensity*light_sources[0].diffuse.rgb;
104 vec3 half_vec = normalize(light_dir-incident_dir);
105 float specular_intensity = pow(max(dot(half_vec, normal), 0.0), basic_material.shininess);
107 specular_intensity *= shadow_intensity;
108 vec3 specular_light = specular_intensity*light_sources[0].specular.rgb;
110 vec3 result = basic_material.diffuse.rgb*ambient_light+basic_material.diffuse.rgb*diffuse_light;
112 result *= diffuse_sample.rgb;
114 result += basic_material.specular.rgb*specular_light;
119 float singlepass_transparency()
121 float alpha = basic_material.diffuse.a;
123 alpha *= diffuse_sample.a;
127 vec3 singlepass_reflection()
129 vec3 reflect_dir = reflect(incident_dir, normal);
131 reflect_dir = eye_tbn_matrix*reflect_dir;
133 return get_environment_sample(env_eye_matrix*reflect_dir).rgb;
136 vec4 singlepass_color()
138 vec4 result = vec4(1.0);
142 result *= get_diffuse_sample();
149 normal = get_normal_sample();
151 normal = normalize(eye_normal);
153 diffuse_sample = get_diffuse_sample();
157 final_color = vec4(singlepass_lighting(), singlepass_transparency());
159 final_color = singlepass_color();
161 if(use_environment_map)
162 final_color += vec4(singlepass_reflection(), 0.0);
165 float fog_value = exp(fog_coord*fog_density);
166 final_color = vec4(mix(fog_color.rgb, final_color.rgb, fog_value), final_color.a);
169 frag_color = final_color;