#ifdef TEXTURE #ifdef U_COLOR #error Texture and color attribute are mutually exclusive. #endif #endif out vec4 pixel_color; #ifdef TEXTURE layout (location = 3) uniform sampler2D tex; layout (location = 2) in vec2 frag_tex_coord; #endif #ifdef U_COLOR layout (location = 3) uniform vec4 color; #endif #ifdef LIGHTING layout (location = 4) uniform vec3 view_pos; layout (location = 5) uniform vec3 point_light_direction; layout (location = 6) uniform vec3 point_light_color; layout (location = 7) uniform vec3 ambient_light_color; layout (location = 8) uniform vec3 ambient_filter; layout (location = 9) uniform vec3 diffuse_filter; layout (location = 10) uniform vec3 specular_filter; layout (location = 11) uniform float shininess; layout (location = 0) in vec3 frag_position; layout (location = 1) in vec3 frag_normal; #endif #ifdef U_ALPHA layout (location = 12) uniform float alpha; #endif void main() { pixel_color = vec4(1); #ifdef TEXTURE pixel_color *= texture(tex, frag_tex_coord); #endif #ifdef U_COLOR pixel_color *= color; #endif #ifdef U_ALPHA pixel_color.w *= alpha; #endif #ifdef LIGHTING vec3 ambient = pixel_color.rgb * ambient_filter * ambient_light_color; float point_light_alignment = max(dot(frag_normal, point_light_direction), 0.0); vec3 diffuse = pixel_color.rgb * diffuse_filter * point_light_color * point_light_alignment; vec3 reflection_dir = reflect(-point_light_direction, frag_normal); vec3 view_dir = normalize(frag_position - view_pos); float specular_strength = pow(max(dot(view_dir, reflection_dir), 0.0), shininess); vec3 specular = specular_filter * point_light_color * specular_strength; pixel_color.rgb *= ambient + diffuse + specular; #endif }