]> git.tdb.fi Git - libs/gl.git/blob - shaderlib/lighting.glsl
Check the flat qualifier from the correct member
[libs/gl.git] / shaderlib / lighting.glsl
1 struct LightSourceParameters
2 {
3         vec4 position;
4         vec3 color;
5         int type;
6         vec3 attenuation;
7 };
8
9 const int max_lights = 6;
10 layout(set=0) uniform Lighting
11 {
12         LightSourceParameters light_sources[max_lights];
13         vec4 ambient_color;
14         vec4 fog_color;
15         //float fog_start_distance;
16         float fog_density;
17 };
18
19 #pragma MSP stage(fragment)
20 struct IncomingLight
21 {
22         vec3 direction;
23         vec3 color;
24 };
25
26 virtual IncomingLight get_incoming_light(int index, vec3 world_pos)
27 {
28         vec4 light_pos = light_sources[index].position;
29         vec3 rel_pos = light_pos.xyz-world_pos*light_pos.w;
30         float d = length(rel_pos);
31         float attenuation = 1.0/dot(vec3(1.0, d, d*d), light_sources[index].attenuation);
32         return IncomingLight(rel_pos/d, light_sources[index].color*attenuation);
33 }