3 layout (location = 0) in vec3 pos;
\r
4 layout (location = 1) in vec3 normal;
\r
9 out float BacksideIrradiance;
\r
12 uniform sampler2D shadowmapTexture;
\r
13 uniform vec3 lightPos;
\r
14 uniform vec2 samplePositions[13];
\r
15 uniform vec3 sampleWeights[13];
\r
16 uniform int screenWidth;
\r
17 uniform int screenHeight;
\r
21 uniform mat4 lightView;
\r
22 uniform mat4 lightViewInv;
\r
23 uniform mat4 projection;
\r
24 uniform mat4 lightProjection;
\r
28 gl_Position = projection * view * model * vec4(pos, 1.0);
\r
29 // calculate fragment position in world coordinates
\r
30 FragPos = vec3(model * vec4(pos, 1));
\r
31 // and local coordinates
\r
36 // get fragment position in the light's projection space
\r
37 vec4 lightSpace = lightProjection * lightView * model * vec4(pos, 1.0);
\r
38 // and transform them to 2D coordinates
\r
39 // (this is usually done by OpenGL after applying the vertex shader,
\r
40 // so to get them here, we have to divide by w manually)
\r
41 lightSpace = lightSpace / lightSpace.w;
\r
42 vec2 shadowmapCoords = lightSpace.xy;
\r
43 // map coordinates from [0 1] to [-1 +1]
\r
44 // multiply by 0.99 first to shift coordinates towards the center slightly
\r
45 // to prevent artifacts at the edges
\r
46 shadowmapCoords = vec2(
\r
47 (shadowmapCoords.x * 0.99 + 1) / 2,
\r
48 (shadowmapCoords.y * 0.99 + 1) / 2
\r
51 // sample shadowmap (brightness encodes distance of fragment to light)
\r
52 vec4 t = texture(shadowmapTexture, shadowmapCoords);
\r
54 BacksideIrradiance = t.r;
\r
56 // calculate backside with distance(BacksideIrradiance) and lightDir
\r
57 vec3 lightDir = normalize(FragPos - lightPos);
\r
58 Backside = (lightPos + (lightDir * BacksideIrradiance));
\r