3 const bool use_vertex_color = false;
5 const bool use_lighting = false;
6 const bool use_specular = false;
7 const bool use_sky = false;
8 const bool use_fog = false;
10 const bool use_diffuse_map = false;
11 const bool use_normal_map = false;
13 const bool use_shadow_map = false;
15 const bool use_environment_map = false;
17 #pragma MSP stage(vertex)
18 vec4 get_vertex_position()
23 vec3 get_vertex_normal()
28 void singlepass_transform_and_lighting()
30 out vec4 eye_vertex = eye_obj_matrix*get_vertex_position();
31 gl_Position = projection_matrix*eye_vertex;
33 out vec3 eye_normal = eye_obj_normal_matrix*get_vertex_normal();
34 vec3 eye_tangent = eye_obj_normal_matrix*tangent;
35 vec3 eye_binormal = eye_obj_normal_matrix*binormal;
36 out mat3 eye_tbn_matrix = mat3(eye_tangent, eye_binormal, eye_normal);
38 out vec3 incident_dir = normalize(eye_vertex.xyz);
40 incident_dir = incident_dir*eye_tbn_matrix;
42 vec3 ldir = normalize(light_sources[0].position.xyz-eye_vertex.xyz*light_sources[0].position.w);
44 ldir = ldir*eye_tbn_matrix;
45 out vec3 light_dir = ldir;
47 out vec3 tbn_zenith_dir = eye_zenith_dir*eye_tbn_matrix;
48 out vec3 shadow_coord = (shd_eye_matrix*eye_vertex).xyz;
49 out float fog_coord = eye_vertex.z;
51 for(int i=0; i<max_clip_planes; ++i)
52 gl_ClipDistance[i] = dot(eye_vertex, clip_planes[i].equation);
57 singlepass_transform_and_lighting();
61 #pragma MSP stage(fragment)
62 vec4 get_diffuse_sample()
64 return texture(diffuse_map, texcoord.xy);
67 vec3 get_normal_sample()
69 return texture(normal_map, texcoord.xy).xyz*2.0-1.0;
72 vec4 get_environment_sample(vec3 direction)
74 return texture(environment, direction);
80 vec3 singlepass_lighting()
82 float shadow_sample = texture(shadow, shadow_coord);
83 float shadow_intensity = mix(1.0, shadow_sample, shadow_darkness);
85 vec3 ambient_light = ambient_color.rgb;
90 zenith_dir = tbn_zenith_dir;
92 zenith_dir = eye_zenith_dir;
93 float skylight_intensity = dot(normal, zenith_dir)*0.5+0.5;
94 ambient_light += skylight_intensity*sky_color.rgb;
97 vec3 n_light_dir = normalize(light_dir);
98 float diffuse_intensity = max(dot(normal, n_light_dir), 0.0);
100 diffuse_intensity *= shadow_intensity;
101 vec3 diffuse_light = diffuse_intensity*light_sources[0].diffuse.rgb;
103 vec3 half_vec = normalize(light_dir-incident_dir);
104 float specular_intensity = pow(max(dot(half_vec, normal), 0.0), material.shininess);
106 specular_intensity *= shadow_intensity;
107 vec3 specular_light = specular_intensity*light_sources[0].specular.rgb;
109 vec3 result = material.ambient.rgb*ambient_light+material.diffuse.rgb*diffuse_light;
111 result *= diffuse_sample.rgb;
113 result += material.specular.rgb*specular_light;
118 float singlepass_transparency()
120 float alpha = material.diffuse.a;
122 alpha *= diffuse_sample.a;
126 vec3 singlepass_reflection()
128 vec3 reflect_dir = reflect(incident_dir, normal);
130 reflect_dir = eye_tbn_matrix*reflect_dir;
132 return get_environment_sample(env_eye_matrix*reflect_dir).rgb;
135 vec4 singlepass_color()
137 vec4 result = vec4(1.0);
141 result *= get_diffuse_sample();
148 normal = get_normal_sample();
150 normal = normalize(eye_normal);
152 diffuse_sample = get_diffuse_sample();
156 final_color = vec4(singlepass_lighting(), singlepass_transparency());
158 final_color = singlepass_color();
160 if(use_environment_map)
161 final_color += vec4(singlepass_reflection(), 0.0);
164 float fog_value = exp(fog_coord*fog_density);
165 final_color = vec4(mix(fog_color.rgb, final_color.rgb, fog_value), final_color.a);
168 frag_color = final_color;