示例#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_);
  }
}
示例#2
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
}
示例#3
0
void RenderWorld(fplbase::Renderer& renderer, World* world, Camera& camera,
                 Camera* cardboard_camera, fplbase::InputSystem* input_system) {
  vec2 window_size = vec2(renderer.window_size());
  world->river_component.UpdateRiverMeshes();
  if (world->rendering_mode() == kRenderingStereoscopic) {
    window_size.x = window_size.x / 2;
    cardboard_camera->set_viewport_resolution(window_size);
  }
  camera.set_viewport_resolution(window_size);
  if (world->rendering_mode() == kRenderingStereoscopic) {
    // This takes care of setting/clearing the framebuffer for us.
    RenderStereoscopic(renderer, world, camera, cardboard_camera, input_system);
  } else {
    // Always clear the framebuffer, even though we overwrite it with the
    // skybox, since it's a speedup on tile-based architectures, see .e.g.:
    // http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-TileBasedArchitectures.pdf
    renderer.ClearFrameBuffer(mathfu::kZeros4f);

    if (world->RenderingOptionEnabled(kShadowEffect)) {
      world->world_renderer->RenderShadowMap(camera, renderer, world);
    }
    world->world_renderer->RenderWorld(camera, renderer, world);
  }
}