Render the scene (in multiple passes for shadow mapping)
| 174 | |
| 175 | // Render the scene (in multiple passes for shadow mapping) |
| 176 | void SceneDemo::render() { |
| 177 | |
| 178 | // Update the VBO for the debug infos |
| 179 | updateDebugVBO(); |
| 180 | |
| 181 | glEnable(GL_DEPTH_TEST); |
| 182 | glEnable(GL_CULL_FACE); |
| 183 | |
| 184 | glClearColor(mBackgroundColor.r, mBackgroundColor.g, mBackgroundColor.b, mBackgroundColor.a); |
| 185 | |
| 186 | Matrix4 shadowMapProjMatrix[NB_SHADOW_MAPS]; |
| 187 | openglframework::Matrix4 worldToLightCameraMatrix[NB_SHADOW_MAPS]; |
| 188 | for (int i = 0; i < NB_SHADOW_MAPS; i++) { |
| 189 | |
| 190 | shadowMapProjMatrix[i] = mShadowMapLightCameras[i].getProjectionMatrix(); |
| 191 | worldToLightCameraMatrix[i] = mShadowMapLightCameras[i].getTransformMatrix().getInverse(); |
| 192 | } |
| 193 | |
| 194 | // ---------- Render the scene to generate the shadow map (first pass) ----------- // |
| 195 | |
| 196 | // If Shadow Mapping is enabled |
| 197 | if (mIsShadowMappingEnabled) { |
| 198 | |
| 199 | // Culling switching, rendering only backface, this is done to avoid self-shadowing |
| 200 | glCullFace(GL_BACK); |
| 201 | |
| 202 | // For each shadow map |
| 203 | for (int i = 0; i < NB_SHADOW_MAPS; i++) { |
| 204 | |
| 205 | mFBOShadowMap[i].bind(); |
| 206 | |
| 207 | // Bind the shader |
| 208 | mDepthShader.bind(); |
| 209 | |
| 210 | // Set the variables of the shader |
| 211 | mDepthShader.setMatrix4x4Uniform("projectionMatrix", shadowMapProjMatrix[i]); |
| 212 | |
| 213 | // Set the viewport to render into the shadow map texture |
| 214 | glViewport(0, 0, SHADOWMAP_WIDTH, SHADOWMAP_HEIGHT); |
| 215 | |
| 216 | // Clear previous frame values |
| 217 | glClear(GL_DEPTH_BUFFER_BIT); |
| 218 | |
| 219 | // Disable color rendering, we only want to write to the Z-Buffer |
| 220 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
| 221 | |
| 222 | // Render the objects of the scene |
| 223 | renderSinglePass(mDepthShader, worldToLightCameraMatrix[i]); |
| 224 | |
| 225 | // Unbind the shader |
| 226 | mDepthShader.unbind(); |
| 227 | |
| 228 | mFBOShadowMap[i].unbind(); |
| 229 | } |
| 230 | |
| 231 | glDisable(GL_POLYGON_OFFSET_FILL); |
| 232 | } |
| 233 |
no test coverage detected