Solution

Files changed (2) hide show
  1. lab6-shadowmaps/lab6_main.cpp +4 -1
  2. lab6-shadowmaps/shading.frag +3 -9
lab6-shadowmaps/lab6_main.cpp CHANGED
@@ -2,7 +2,7 @@
2
2
  /* WARNING: if you change one the following, you also have to change the
3
3
  * fragment shader!
4
4
  */
5
- #define SOLUTION_USE_BUILTIN_SHADOW_TEST 0
5
+ #define SOLUTION_USE_BUILTIN_SHADOW_TEST 1
6
6
 
7
7
  #include <GL/glew.h>
8
8
  #include <cmath>
@@ -232,6 +232,9 @@ void initialize()
232
232
  ///////////////////////////////////////////////////////////////////////
233
233
  shadowMapFB.resize(shadowMapResolution, shadowMapResolution);
234
234
 
235
+ glBindTexture(GL_TEXTURE_2D, shadowMapFB.depthBuffer);
236
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
237
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
235
238
 
236
239
  glEnable(GL_DEPTH_TEST); // enable Z-buffering
237
240
  glEnable(GL_CULL_FACE); // enables backface culling
lab6-shadowmaps/shading.frag CHANGED
@@ -1,4 +1,7 @@
1
1
  #version 420
2
+ /* WARNNING: the following must match the values in lab6_main.cpp
3
+ */
4
+ #define SOLUTION_USE_BUILTIN_SHADOW_TEST 1
2
5
 
3
6
  // required by GLSL spec Sect 4.5.3 (though nvidia does not, amd does)
4
7
  precision highp float;
@@ -58,11 +61,7 @@ layout(location = 0) out vec4 fragmentColor;
58
61
 
59
62
  uniform mat4 lightMatrix;
60
63
 
61
- #if SOLUTION_USE_BUILTIN_SHADOW_TEST
62
64
  layout(binding = 10) uniform sampler2DShadow shadowMapTex;
63
- #else // USE_BUILTIN_SHADOW_TEST
64
- layout(binding = 10) uniform sampler2D shadowMapTex;
65
- #endif // ~ USE_BUILTIN_SHADOW_TEST
66
65
 
67
66
  uniform int useSpotLight;
68
67
  uniform int useSoftFalloff;
@@ -136,12 +135,7 @@ void main()
136
135
  float visibility = 1.0;
137
136
  float attenuation = 1.0;
138
137
 
139
- #if SOLUTION_USE_BUILTIN_SHADOW_TEST // SOLUTION_CODE >= 8
140
138
  visibility = textureProj(shadowMapTex, shadowMapCoord);
141
- #else
142
- float depth = texture(shadowMapTex, shadowMapCoord.xy / shadowMapCoord.w).r;
143
- visibility = (depth >= (shadowMapCoord.z / shadowMapCoord.w)) ? 1.0 : 0.0;
144
- #endif // ~ USE_BUILTIN_SHADOW_TEST
145
139
  attenuation = 1.0;
146
140
  if(useSpotLight == 1)
147
141
  {