#version 410 in vec3 Position; in vec3 Normal; in vec2 TexCoord; uniform mat4 ViewMatrix; struct LightInfo { vec3 Ldir; vec3 La; vec3 Ld; vec3 Ls; }; uniform LightInfo Light; struct MaterialInfo{ vec3 Ka; vec3 Kd; vec3 Ks; float Shininess; }; uniform MaterialInfo Material; uniform sampler2D BaseTex;; layout( location = 0 ) out vec4 Ambient; layout( location = 1 ) out vec4 DiffSpec; void shade( ) { vec4 s4 = ViewMatrix*vec4(Light.Ldir, 0.0); vec3 n = normalize(Normal); vec3 v = normalize(-Position); vec3 s = normalize(-vec3(s4)); vec3 r = reflect(-s, n); float dRate = max(dot(s, n), 0.0); float sRate = pow(max(dot(r, v), 0.0), Material.Shininess); vec4 texColor = texture(BaseTex, TexCoord); Ambient = vec4(texColor.rgb*Light.La * Material.Ka, 1.0); DiffSpec = vec4( texColor.rgb* Light.Ld * Material.Kd * dRate + Light.Ls * Material.Ks * sRate, 1.0); } void main() { shade(); }