1 | #version 150 |
---|
2 | |
---|
3 | uniform mat4 world; |
---|
4 | uniform mat4 worldViewProj; |
---|
5 | uniform mat4 texViewProj; |
---|
6 | uniform vec4 camObjPos; |
---|
7 | uniform vec4 objSpaceLight; |
---|
8 | uniform vec4 lightColour; |
---|
9 | uniform vec4 offset; |
---|
10 | |
---|
11 | in vec4 position; |
---|
12 | in vec4 normal; |
---|
13 | in vec4 uv0; |
---|
14 | |
---|
15 | out vec4 oShadowUV; |
---|
16 | out vec3 oUv0; |
---|
17 | out vec4 oColour; |
---|
18 | |
---|
19 | //////////////////////// GRASS SHADOW RECEIVER |
---|
20 | void main() |
---|
21 | { |
---|
22 | vec4 mypos = position; |
---|
23 | vec4 factor = vec4(1.0, 1.0, 1.0, 1.0) - uv0.yyyy; |
---|
24 | mypos = mypos + offset * factor; |
---|
25 | gl_Position = worldViewProj * mypos; |
---|
26 | oUv0.xy = uv0.xy; |
---|
27 | // Transform position to world space |
---|
28 | vec4 worldPos = world * mypos; |
---|
29 | // calculate shadow map coords |
---|
30 | oShadowUV = texViewProj * worldPos; |
---|
31 | |
---|
32 | // Make vec from vertex to camera |
---|
33 | vec4 EyeVec = camObjPos - mypos; |
---|
34 | // Dot the v to eye and the normal to see if they point |
---|
35 | // in the same direction or opposite |
---|
36 | float alignedEye = dot(normal, EyeVec); // -1..1 |
---|
37 | // If aligned is negative, we need to flip the normal |
---|
38 | vec4 myNormal = normal; |
---|
39 | if (alignedEye < 0.0) |
---|
40 | myNormal = -normal; |
---|
41 | //oNormal = normal; |
---|
42 | |
---|
43 | // get vertex light direction (support directional and point) |
---|
44 | vec3 lightVec = normalize(objSpaceLight.xyz - (mypos.xyz * objSpaceLight.w).xyz); |
---|
45 | // Dot the v to light and the normal to see if they point |
---|
46 | // in the same direction or opposite |
---|
47 | float alignedLight = dot(myNormal.xyz, lightVec); // -1..1 |
---|
48 | // If aligned is negative, shadowing/lighting is not possible. |
---|
49 | oUv0.z = (alignedLight < 0.0) ? 0.0 : 1.0 ; |
---|
50 | |
---|
51 | float diffuseFactor = max(alignedLight, 0.0); |
---|
52 | //oColour = diffuseFactor * lightColour; |
---|
53 | oColour = lightColour; |
---|
54 | } |
---|