-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvertexShader.vs
More file actions
47 lines (40 loc) · 1.34 KB
/
vertexShader.vs
File metadata and controls
47 lines (40 loc) · 1.34 KB
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
46
47
attribute vec4 vPosition;
uniform vec3 vLightPos;
attribute vec2 vTexCoord;
attribute vec4 vNormal;
uniform mat4 Proj;
uniform mat4 View;
uniform mat4 World;
uniform mat4 invWorld;
uniform sampler2D theSampler;
varying float lightPower;
varying vec2 theCoord;
//varying vec4 showNormal;
// varying vec4 showLight;
////////////////////////////////////////////////////////////////// uniform array test
attribute float vIndices;
uniform float weight[200];
//////////////////////////////////////////////////////////////////
void main(){
vec4 tempPos = vPosition;
mat4 tempView = View;
tempView[2].z = gl_DepthRange.diff/2.0;
tempView[3].z = ( gl_DepthRange.near +gl_DepthRange.far) /2.0;
vec4 worldPos = World * tempPos;
vec4 pos = tempView * Proj * World * tempPos;
pos = pos / pos.w;
vec4 tNormal = invWorld * vNormal;
//vec4 tNormal = World * vNormal;
tNormal = tNormal / tNormal.w;
vec4 tLight = tempView * Proj * World * vec4(vLightPos, 1.0);
tLight = tLight / tLight.w;
vec4 worldLight = World * vec4(vLightPos, 1.0);
tLight = tLight / tLight.w;
vec4 lightVec = vec4( worldLight.xyz - worldPos.xyz, 1.0);
float lightAngle = dot(lightVec.xyz, tNormal.xyz)/ (length(lightVec.xyz) * length(tNormal.xyz) );
theCoord = vTexCoord;
lightPower = clamp(lightAngle + 0.75, -1.0, 1.0);
//showNormal = tNormal;
// showLight = lightVec;
gl_Position = pos;
}