MCPcopy Create free account
hub / github.com/OpenNFS/OpenNFS / renderShadowMap

Method renderShadowMap

src/Renderer/ShadowMapRenderer.cpp:36–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36void ShadowMapRenderer::renderShadowMap(const glm::mat4 &lightViewMatrix, std::vector<int> activeTrackBlockIDs, const std::shared_ptr<Car> &car){
37 /* ------- SHADOW MAPPING ------- */
38 glCullFace(GL_FRONT);
39 depthShader.use();
40 float near_plane = 160.0f, far_plane = 280.f;
41 glm::mat4 lightProjection = glm::ortho(-20.0f, 20.0f, -20.0f, 20.0f, near_plane, far_plane);
42 lightSpaceMatrix = lightProjection * lightViewMatrix;
43
44 depthShader.loadLightSpaceMatrix(lightSpaceMatrix);
45 depthShader.bindTextureArray(track->textureArrayID);
46
47 glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
48 glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
49 glClear(GL_DEPTH_BUFFER_BIT);
50
51 /* Render the track using this simple shader to get depth texture to test against during draw */
52 for (int activeBlk_Idx = 0; activeBlk_Idx < activeTrackBlockIDs.size(); ++activeBlk_Idx) {
53 TrackBlock active_track_Block = track->track_blocks[activeTrackBlockIDs[activeBlk_Idx]];
54 std::vector<Light> contributingLights;
55 for (auto &light_entity : active_track_Block.lights) {
56 contributingLights.emplace_back(boost::get<Light>(light_entity.glMesh));
57 }
58 for (auto &track_block_entity : active_track_Block.track) {
59 boost::get<Track>(track_block_entity.glMesh).update();
60 depthShader.loadTransformMatrix(boost::get<Track>(track_block_entity.glMesh).ModelMatrix);
61 boost::get<Track>(track_block_entity.glMesh).render();
62 }
63 for (auto &track_block_entity : active_track_Block.objects) {
64 boost::get<Track>(track_block_entity.glMesh).update();
65 depthShader.loadTransformMatrix(boost::get<Track>(track_block_entity.glMesh).ModelMatrix);
66 boost::get<Track>(track_block_entity.glMesh).render();
67 }
68 }
69 /* And the Car */
70 depthShader.bindTextureArray(car->textureArrayID);
71 for (auto &misc_model : car->misc_models) {
72 depthShader.loadTransformMatrix(misc_model.ModelMatrix);
73 misc_model.render();
74 }
75 depthShader.loadTransformMatrix(car->left_front_wheel_model.ModelMatrix);
76 car->left_front_wheel_model.render();
77 depthShader.loadTransformMatrix(car->left_rear_wheel_model.ModelMatrix);
78 car->left_rear_wheel_model.render();
79 depthShader.loadTransformMatrix(car->right_front_wheel_model.ModelMatrix);
80 car->right_front_wheel_model.render();
81 depthShader.loadTransformMatrix(car->right_rear_wheel_model.ModelMatrix);
82 car->right_rear_wheel_model.render();
83 depthShader.loadTransformMatrix(car->car_body_model.ModelMatrix);
84 car->car_body_model.render();
85
86 glCullFace(GL_BACK); // Reset original culling face
87 glBindFramebuffer(GL_FRAMEBUFFER, 0);
88
89 glViewport(0, 0, Config::get().resX, Config::get().resY);
90}
91
92ShadowMapRenderer::~ShadowMapRenderer() {
93 glDeleteFramebuffers(1, &depthMapFBO);

Callers 1

RenderMethod · 0.80

Calls 6

useMethod · 0.80
loadLightSpaceMatrixMethod · 0.45
bindTextureArrayMethod · 0.45
updateMethod · 0.45
loadTransformMatrixMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected