]> git.tdb.fi Git - libs/gl.git/blobdiff - shaderlib/common.glsl
Hide the use of the tangent variable in common.glsl behind an if
[libs/gl.git] / shaderlib / common.glsl
index 4d6112d9f2b37a58127f6a5330837b5b55973217..35d5a87eafb8bf8c83e8fe877cdf5e90b0a3d724 100644 (file)
@@ -43,20 +43,17 @@ void standard_transform()
        gl_Position = clip_eye_matrix*eye_vertex;
 
        out vec3 world_normal = normal_tf*get_vertex_normal();
-       vec3 world_tangent = normal_tf*tangent;
-       vec3 world_binormal = cross(world_normal, world_tangent);
-       out mat3 world_tbn_matrix = mat3(world_tangent, world_binormal, world_normal);
+       if(use_normal_map)
+       {
+               vec3 world_tangent = normal_tf*tangent;
+               vec3 world_binormal = cross(world_normal, world_tangent);
+               out mat3 world_tbn_matrix = mat3(world_tangent, world_binormal, world_normal);
+       }
 
-       vec3 eye_pos = (inverse(eye_world_matrix)*vec4(0.0, 0.0, 0.0, 1.0)).xyz;
+       vec3 eye_pos = world_eye_matrix[3].xyz;
        out vec3 world_look_dir = normalize(world_vertex.xyz-eye_pos);
 
        out float fog_coord = eye_vertex.z;
-
-       if(use_clipping)
-       {
-               for(int i=0; i<max_clip_planes; ++i)
-                       gl_ClipDistance[i] = dot(world_vertex, clip_planes[i].equation);
-       }
 }
 
 virtual void custom_transform()
@@ -77,6 +74,8 @@ struct IncomingLight
        vec3 color;
 };
 
+layout(location=0) out vec4 frag_color;
+
 virtual vec3 get_fragment_normal()
 {
        if(use_normal_map)
@@ -90,7 +89,8 @@ virtual IncomingLight get_incoming_light(int index, vec3 world_pos)
        vec4 light_pos = light_sources[index].position;
        vec3 rel_pos = light_pos.xyz-world_pos*light_pos.w;
        float d = length(rel_pos);
-       return IncomingLight(rel_pos/d, light_sources[index].color);
+       float attenuation = 1.0/dot(vec3(1.0, d, d*d), light_sources[index].attenuation);
+       return IncomingLight(rel_pos/d, light_sources[index].color*attenuation);
 }
 
 virtual vec3 get_environment_sample(vec3 direction, float roughness)