void Game::render() { if(current_mode == MODE_GAME) { lights.lights[0]->render_shadow_map(camera, [&]() -> void { render_geometry(); }); geometry->bind(); geometry->clear(Color::black); passthru->bind(); Shader::upload_camera(camera); render_geometry(); geometry->unbind(); Shader::upload_state(composition->texture_size()); composition->bind(); RenderTarget::clear(sky_color); Shader::upload_camera(camera); Shader::upload_lights(lights); terrain->render(); rail_material.bind(); rails->render(); player.render(); passthru->bind(); for(Enemy * e : enemies) { e->render(); } particle_shader->bind(); geometry->depth_bind(Shader::TEXTURE_2D_0); attack_particles->render(); smoke->render(); explosions->render(); dust->render(); composition->unbind(); } render_display(); }
void LightPathsWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); const auto& rc = m_camera.get_rasterization_camera(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); const double ZNear = 0.01; const double ZFar = 1000.0; const double fy = tan(rc.m_hfov / rc.m_aspect_ratio * 0.5) * ZNear; const double fx = fy * rc.m_aspect_ratio; const double shift_x = rc.m_shift_x * 2.0 * fx; const double shift_y = rc.m_shift_y * 2.0 * fy; const double left = -fx + shift_x; const double right = fx + shift_x; const double top = -fy + shift_y; const double bottom = fy + shift_y; glFrustum(left, right, top, bottom, ZNear, ZFar); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (m_backface_culling_enabled) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); render_geometry(); render_light_paths(); }
void Client::render_shadows() { // get transform from light's perspective get_world()->set_light_camera(get_player()); // only render geometry of world render_geometry(); //fmat4 transform(1); //world->render_background(&transform, player); }
void Client::render() { // get transform from player's perspective get_player()->set_camera(); OGLAttr::current_shader->set_enable_shadows(true); render_geometry(); OGLAttr::current_shader->set_enable_shadows(false); fmat4 transform(1); get_world()->render_background(&transform); sprite_manager.render(&transform); render_ui(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mat4_identity(view); view = mat4_lookAt(eye, center, up, view); render_geometry(&g, model, view, projection); if (debug) { render_debug(&g, model, view, projection); } glutSwapBuffers(); }
void ShadowMap::render(RenderContext const& ctx, SceneGraph const& scene_graph, math::vec3 const& center_of_interest, Camera const& scene_camera, math::mat4 const& transform, unsigned map_size) { // init members update_members(ctx, map_size); projection_view_matrices_ = std::vector<math::mat4>(1); buffer_->bind(ctx); buffer_->clear_depth_stencil_buffer(ctx); ctx.render_context->set_depth_stencil_state(depth_stencil_state_); ctx.render_context->set_rasterizer_state(rasterizer_state_); ctx.render_context->set_viewport(scm::gl::viewport( math::vec2(0, 0), math::vec2(map_size, map_size))); // calculate light frustum math::mat4 screen_transform(scm::math::make_translation(0.f, 0.f, -1.f)); screen_transform = transform * screen_transform; Frustum shadow_frustum = Frustum::perspective(transform, screen_transform, pipeline_->config.near_clip(), pipeline_->config.far_clip()); // render geometries render_geometry(ctx, scene_graph, center_of_interest, shadow_frustum, scene_camera, 0, map_size); ctx.render_context->reset_state_objects(); buffer_->unbind(ctx); }
void Player::render(const glm::mat4 &m) { shader->bind(); render_geometry(m); }
void ShadowMap::render_cascaded(RenderContext const& ctx, SceneGraph const& scene_graph, math::vec3 const& center_of_interest, Frustum const& scene_frustum, Camera const& scene_camera, math::mat4 const& transform, unsigned map_size, float split_0, float split_1, float split_2, float split_3, float split_4, float near_clipping_in_sun_direction) { update_members(ctx, map_size*2); projection_view_matrices_ = std::vector<math::mat4>(4); buffer_->bind(ctx); buffer_->clear_depth_stencil_buffer(ctx); ctx.render_context->set_depth_stencil_state(depth_stencil_state_); ctx.render_context->set_rasterizer_state(rasterizer_state_); std::vector<float> splits({ split_0, split_1, split_2, split_3, split_4 }); if (pipeline_->config.near_clip() > split_0 || pipeline_->config.far_clip() < split_4) { Logger::LOG_WARNING << "Splits of cascaded shadow maps are not inside clipping range! Fallback to equidistant splits used." << std::endl; float clipping_range(pipeline_->config.far_clip() - pipeline_->config.near_clip()); splits = { pipeline_->config.near_clip(), pipeline_->config.near_clip() + clipping_range * 0.25f, pipeline_->config.near_clip() + clipping_range * 0.5f, pipeline_->config.near_clip() + clipping_range * 0.75f, pipeline_->config.far_clip() }; } for (int y(0); y<2; ++y) { for (int x(0); x<2; ++x) { int cascade(y*2 + x); // render each cascade to a quarter of the shadow map ctx.render_context->set_viewport(scm::gl::viewport( math::vec2(x * map_size, y * map_size), math::vec2(map_size, map_size))); // set clipping of camera frustum according to current cascade Frustum cropped_frustum(Frustum::perspective( scene_frustum.get_camera_transform(), scene_frustum.get_screen_transform(), splits[cascade], splits[cascade+1] )); // transform cropped frustum tu sun space and calculate radius and bbox // of transformed frustum auto cropped_frustum_corners(cropped_frustum.get_corners()); math::BoundingBox<math::vec3> extends_in_sun_space; float radius_in_sun_space = 0; std::vector<math::vec3> corners_in_sun_space; math::vec3 center_in_sun_space(0, 0, 0); auto inverse_sun_transform(scm::math::inverse(transform)); for (auto const& corner: cropped_frustum_corners) { math::vec3 new_corner(inverse_sun_transform * corner); center_in_sun_space += new_corner/8; corners_in_sun_space.push_back(new_corner); extends_in_sun_space.expandBy(new_corner); } for (auto const& corner: corners_in_sun_space) { float radius = scm::math::length(corner-center_in_sun_space); if (radius > radius_in_sun_space) radius_in_sun_space = radius; } // center of front plane of frustum auto center(math::vec3((extends_in_sun_space.min[0] + extends_in_sun_space.max[0])/2, (extends_in_sun_space.min[1] + extends_in_sun_space.max[1])/2, extends_in_sun_space.max[2] + near_clipping_in_sun_direction)); // eliminate sub-pixel movement float tex_coord_x = center.x * map_size / radius_in_sun_space / 2; float tex_coord_y = center.y * map_size / radius_in_sun_space / 2; float tex_coord_rounded_x = round(tex_coord_x); float tex_coord_rounded_y = round(tex_coord_y); float dx = tex_coord_rounded_x - tex_coord_x; float dy = tex_coord_rounded_y - tex_coord_y; dx /= map_size / radius_in_sun_space / 2; dy /= map_size / radius_in_sun_space / 2; center.x += dx; center.y += dy; // calculate transformation of shadow screen auto screen_in_sun_space(scm::math::make_translation(center) * scm::math::make_scale(radius_in_sun_space*2, radius_in_sun_space*2, 1.0f)); auto sun_screen_transform(transform * screen_in_sun_space); // calculate transformation of shadow eye auto sun_eye_transform(scm::math::make_translation(sun_screen_transform.column(3)[0], sun_screen_transform.column(3)[1], sun_screen_transform.column(3)[2])); auto sun_eye_depth(transform * math::vec4(0, 0, extends_in_sun_space.max[2] - extends_in_sun_space.min[2] + near_clipping_in_sun_direction, 0.0f)); auto shadow_frustum( Frustum::orthographic( sun_eye_transform, sun_screen_transform, 0, scm::math::length(sun_eye_depth) ) ); // render geometries render_geometry(ctx, scene_graph, center_of_interest, shadow_frustum, scene_camera, cascade, map_size); } } ctx.render_context->reset_state_objects(); buffer_->unbind(ctx); }