Exemple #1
0
void WorldRenderer::CreateShadowMap(const corgi::CameraInterface& camera,
                                    fplbase::Renderer& renderer, World* world) {
  float shadow_map_resolution = static_cast<float>(
        world->config->rendering_config()->shadow_map_resolution());
  float shadow_map_zoom = world->config->rendering_config()->shadow_map_zoom();
  float shadow_map_offset =
      world->config->rendering_config()->shadow_map_offset();
  vec3 light_position =
      LoadVec3(world->config->rendering_config()->light_position());
  SetLightPosition(light_position);
  light_camera_.set_viewport_angle(kShadowMapViewportAngle / shadow_map_zoom);
  light_camera_.set_viewport_resolution(
      vec2(shadow_map_resolution, shadow_map_resolution));
  vec3 light_camera_focus =
      camera.position() + camera.facing() * shadow_map_offset;
  light_camera_focus.z() = 0;
  vec3 light_facing = light_camera_focus - light_camera_.position();
  light_camera_.set_facing(light_facing.Normalized());

  // Shadow map needs to be cleared to near-white, since that's
  // the maximum (furthest) depth.
  shadow_map_.SetAsRenderTarget();
  renderer.ClearFrameBuffer(kShadowMapClearColor);
  renderer.SetCulling(fplbase::Renderer::kCullBack);

  depth_shader_->Set(renderer);
  // Generate the shadow map:
  // TODO - modify this so that shadowcast is its own render pass
  for (int pass = 0; pass < corgi::RenderPass_Count; pass++) {
    world->render_mesh_component.RenderPass(pass, light_camera_,
                                            renderer, depth_shader_);
  }
}
Exemple #2
0
void RenderMeshComponent::RenderAllEntities(fplbase::Renderer& renderer,
                                            const CameraInterface& camera) {
  // Make sure we only draw the front-facing polygons:
  renderer.SetCulling(fplbase::Renderer::kCullBack);

  // Render the actual game:
  for (int pass = 0; pass < RenderPass_Count; pass++) {
    RenderPass(pass, camera, renderer);
  }
}
Exemple #3
0
void WorldRenderer::CreateShadowMap(const corgi::CameraInterface &camera,
                                    fplbase::Renderer &renderer, World *world) {
  PushDebugMarker("CreateShadowMap");

  PushDebugMarker("Setup");
  float shadow_map_resolution = static_cast<float>(
      world->config->rendering_config()->shadow_map_resolution());
  float shadow_map_zoom = world->config->rendering_config()->shadow_map_zoom();
  float shadow_map_offset =
      world->config->rendering_config()->shadow_map_offset();
  LightComponent *light_component =
      world->entity_manager.GetComponent<LightComponent>();

  const EntityRef &main_light_entity = light_component->begin()->entity;
  const TransformData *light_transform =
      world->entity_manager.GetComponentData<TransformData>(main_light_entity);
  vec3 light_position = light_transform->position;
  SetLightPosition(light_position);

  float viewport_angle =
      world->config->rendering_config()->shadow_map_viewport_angle() *
      kDegreesToRadians;
  light_camera_.set_viewport_angle(viewport_angle / shadow_map_zoom);
  light_camera_.set_viewport_resolution(
      vec2(shadow_map_resolution, shadow_map_resolution));
  vec3 light_camera_focus =
      camera.position() + camera.facing() * shadow_map_offset;
  light_camera_focus.z = 0;
  vec3 light_facing = light_camera_focus - light_camera_.position();
  light_camera_.set_facing(light_facing.Normalized());

  // Shadow map needs to be cleared to near-white, since that's
  // the maximum (furthest) depth.
  shadow_map_.SetAsRenderTarget();
  renderer.ClearFrameBuffer(kShadowMapClearColor);
  renderer.SetCulling(fplbase::kCullingModeBack);

  depth_shader_->Set(renderer);
  depth_skinned_shader_->Set(renderer);
  // Generate the shadow map:
  // TODO - modify this so that shadowcast is its own render pass
  PopDebugMarker(); // Setup

  for (int pass = 0; pass < corgi::RenderPass_Count; pass++) {
    PushDebugMarker("RenderPass");
    world->render_mesh_component.RenderPass(pass, light_camera_, renderer,
                                            ShaderIndex_Depth);
    PopDebugMarker();
  }

  fplbase::RenderTarget::ScreenRenderTarget(renderer).SetAsRenderTarget();
  PopDebugMarker(); // CreateShadowMap
}