Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/pssmReceiverVp.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.9 KB
Line 
1#version 100
2
3precision mediump int;
4precision mediump float;
5
6float shadowPCF(sampler2D shadowMap, vec4 shadowMapPos, vec2 offset)
7{
8        shadowMapPos = shadowMapPos / shadowMapPos.w;
9        vec2 uv = shadowMapPos.xy;
10        vec3 o = vec3(offset, -offset.x) * 0.3;
11
12        // Note: We using 2x2 PCF. Good enough and is a lot faster.
13        float c =       (shadowMapPos.z <= texture2D(shadowMap, uv.xy - o.xy).r) ? 1.0 : 0.0; // top left
14        c +=            (shadowMapPos.z <= texture2D(shadowMap, uv.xy + o.xy).r) ? 1.0 : 0.0; // bottom right
15        c +=            (shadowMapPos.z <= texture2D(shadowMap, uv.xy + o.zy).r) ? 1.0 : 0.0; // bottom left
16        c +=            (shadowMapPos.z <= texture2D(shadowMap, uv.xy - o.zy).r) ? 1.0 : 0.0; // top right
17
18        return c / 4.0;
19}
20
21uniform vec4 lightPosition;                             // object space
22uniform vec3 eyePosition;                                       // object space
23uniform mat4 worldViewProjMatrix;
24uniform mat4 texWorldViewProjMatrix0;
25uniform mat4 texWorldViewProjMatrix1;
26uniform mat4 texWorldViewProjMatrix2;
27
28varying vec4 oUv0;
29varying vec3 oLightDir;
30varying vec3 oHalfAngle;
31varying vec4 oLightPosition0;
32varying vec4 oLightPosition1;
33varying vec4 oLightPosition2;
34varying vec3 oNormal;
35
36attribute vec4 position;
37attribute vec3 normal;
38attribute vec4 uv0;
39
40void main()
41{
42        // Calculate output position
43        gl_Position = worldViewProjMatrix * position;
44
45        // Pass the main uvs straight through unchanged
46        oUv0.xy = uv0.xy;
47        oUv0.z = gl_Position.z;
48
49        // Calculate tangent space light vector
50        // Get object space light direction
51        oLightDir = normalize(lightPosition.xyz - (position * lightPosition.w).xyz);
52
53        // Calculate half-angle in tangent space
54        vec3 eyeDir = normalize(eyePosition - position.xyz);
55        oHalfAngle = normalize(eyeDir + oLightDir);     
56
57        // Calculate the position of vertex in light space
58        oLightPosition0 = texWorldViewProjMatrix0 * position;
59        oLightPosition1 = texWorldViewProjMatrix1 * position;
60        oLightPosition2 = texWorldViewProjMatrix2 * position;
61
62        oNormal = normal;
63}
Note: See TracBrowser for help on using the repository browser.