Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/GrassReceiverVp.glsles @ 12091

Last change on this file since 12091 was 12091, checked in by wiesep, 5 years ago

Updated programs and adjusted Material to work with GLSL>150

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