-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADSGouraud.vert
45 lines (38 loc) · 1.19 KB
/
ADSGouraud.vert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#version 150
in vec4 vertex;
in vec3 normal;
uniform vec4 ambientColor;
uniform vec4 diffuseColor;
uniform vec4 specularColor;
uniform vec3 lightPosition;// light in world space
uniform float ns;
uniform mat4 mvpMatrix;
uniform mat4 mvMatrix;
uniform mat3 normalMatrix;
smooth out vec4 varyingColor;
void main(void)
{
// varyingColor=vec4(0.0,0.0,0.0,1.0);
varyingColor = ambientColor;
vec3 vEyeNormal = normalize(normalMatrix * normal);
//vec3 vEyeNormal =normalize(normal);
vec4 vPosition4 = mvMatrix * vertex;
//vec3 vPosition3 =vec3(vPosition4);
vec3 vPosition3 = vPosition4.xyz / vPosition4.w;
// Get vector to light source
vec3 vLightDir = normalize(lightPosition - vPosition3);
// Dot product gives us diffuse intensity
float diff = max(0.0, dot(vEyeNormal, vLightDir));
// Multiply intensity by diffuse color, force alpha to 1.0
varyingColor += diff * diffuseColor;
// Add in ambient light
// Specular Light
vec3 vReflection = normalize(reflect(-vLightDir, vEyeNormal));
float spec = max(0.0, dot(vEyeNormal, vReflection));
if(diff != 0) {
float fSpec = pow(spec, 128.0);
varyingColor.rgb += vec3(fSpec, fSpec, fSpec);
}
// Don’t forget to transform the geometry!
gl_Position = mvpMatrix * vertex;
}