-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathVertexShader.txt
41 lines (35 loc) · 1015 Bytes
/
VertexShader.txt
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
attribute vec3 aPosition;
attribute vec2 aTextureCoord;
varying vec2 vTextureCoord;
uniform mat4 uModelView;
uniform mat4 uProj;
attribute vec3 aVertexNormal;
uniform mat4 uNormalMatrix;
uniform vec3 uAmbientColor;
uniform vec3 uLightDirection;
uniform vec3 uDirectionalColor;
uniform bool uUseAmbientLight;
uniform bool uUseParallelLlight;
varying vec3 vLightWeighting;
void main()
{
gl_Position = uProj * uModelView * vec4(aPosition,1.0);
vTextureCoord = aTextureCoord;
if(uUseAmbientLight||uUseParallelLlight)
{
if(uUseAmbientLight)
{
vLightWeighting += uAmbientColor;
}
if(uUseParallelLlight)
{
vec3 transformedNormal = (uNormalMatrix * vec4(aVertexNormal, 1.0)).xyz;
float directionalLightWeighting = max(dot(transformedNormal,-uLightDirection), 0.0);
vLightWeighting += uDirectionalColor * directionalLightWeighting;
}
}
else
{
vLightWeighting = vec3(1.0, 1.0, 1.0);
}
}