Exemple #1
0
void WorldRenderer::RenderWorld(const corgi::CameraInterface& camera,
                                fplbase::Renderer& renderer, World* world) {
  mat4 camera_transform = camera.GetTransformMatrix();
  renderer.set_color(mathfu::kOnes4f);
  renderer.DepthTest(true);
  renderer.set_model_view_projection(camera_transform);

  assert(textured_shadowed_shader_);
  textured_shadowed_shader_->SetUniform("view_projection", camera_transform);
  textured_shadowed_shader_->SetUniform("light_view_projection",
                                        light_camera_.GetTransformMatrix());
  textured_shadowed_shader_->SetUniform(
      "shadow_intensity",
      world->config->rendering_config()->shadow_intensity());

  float shadow_intensity =
      world->config->rendering_config()->shadow_intensity();
  float ambient_intensity = 1.0f - shadow_intensity;
  vec4 ambient =
      vec4(ambient_intensity, ambient_intensity, ambient_intensity, 1.0f);

  float diffuse_intensity = shadow_intensity;
  vec4 diffuse =
      vec4(diffuse_intensity, diffuse_intensity, diffuse_intensity, 1.0f);

  textured_lit_cutout_shader_->SetUniform("ambient_material", ambient);
  textured_lit_cutout_shader_->SetUniform("diffuse_material", diffuse);

  textured_lit_shader_->SetUniform("ambient_material", ambient);
  textured_lit_shader_->SetUniform("diffuse_material", diffuse);

  textured_lit_bank_shader_->SetUniform("ambient_material", ambient);
  textured_lit_bank_shader_->SetUniform("diffuse_material", diffuse);

  textured_skinned_lit_shader_->SetUniform("ambient_material", ambient);
  textured_skinned_lit_shader_->SetUniform("diffuse_material", diffuse);

  float texture_repeats = world->config->river_config()->texture_repeats();
  float river_offset = world->river_component.river_offset();

  river_shader_->SetUniform("river_offset",   river_offset);
  river_shader_->SetUniform("texture_repeats", texture_repeats);

  SetFogUniforms(textured_shadowed_shader_, world);
  SetFogUniforms(textured_lit_shader_, world);
  SetFogUniforms(textured_lit_bank_shader_, world);
  SetFogUniforms(textured_skinned_lit_shader_, world);

  shadow_map_.BindAsTexture(kShadowMapTextureID);

  if (!world->skip_rendermesh_rendering) {
    for (int pass = 0; pass < corgi::RenderPass_Count; pass++) {
      world->render_mesh_component.RenderPass(pass, camera, renderer);
    }
  }

  if (world->draw_debug_physics) {
    world->physics_component.DebugDrawWorld(&renderer, camera_transform);
  }
}
Exemple #2
0
// Draw the shadow map in the world, so we can see it.
void WorldRenderer::DebugShowShadowMap(const corgi::CameraInterface& camera,
                                       fplbase::Renderer& renderer) {
  fplbase::RenderTarget::ScreenRenderTarget(renderer).SetAsRenderTarget();

  static const mat4 kDebugTextureWorldTransform =
      mat4::FromScaleVector(mathfu::vec3(10.0f, 10.0f, 10.0f));

  const mat4 mvp = camera.GetTransformMatrix() * kDebugTextureWorldTransform;
  const mat4 world_matrix_inverse = kDebugTextureWorldTransform.Inverse();

  renderer.set_camera_pos(world_matrix_inverse * camera.position());
  renderer.set_light_pos(world_matrix_inverse * light_camera_.position());
  renderer.set_model_view_projection(mvp);
  renderer.set_color(vec4(1.0f, 1.0f, 1.0f, 1.0f));

  shadow_map_.BindAsTexture(0);

  textured_shader_->Set(renderer);

  // Render a large quad in the world, with the shadowmap texture on it:
  fplbase::Mesh::RenderAAQuadAlongX(vec3(0.0f, 0.0f, 0.0f),
                                    vec3(10.0f, 0.0f, 10.0f),
                                    vec2(1.0f, 0.0f), vec2(0.0f, 1.0f));
}
Exemple #3
0
void WorldRenderer::RenderWorld(const corgi::CameraInterface &camera,
                                fplbase::Renderer &renderer, World *world) {
  PushDebugMarker("Render World");

  PushDebugMarker("Scene Setup");
  if (world->RenderingOptionsDirty()) {
    RefreshGlobalShaderDefines(world);
  }

  mat4 camera_transform = camera.GetTransformMatrix();
  renderer.set_color(mathfu::kOnes4f);
  renderer.SetDepthFunction(fplbase::kDepthFunctionLess);
  renderer.set_model_view_projection(camera_transform);

  float texture_repeats =
      world->CurrentLevel()->river_config()->texture_repeats();
  float river_offset = world->river_component.river_offset();

  if (world->RenderingOptionEnabled(kShadowEffect)) {
    world->asset_manager->ForEachShaderWithDefine(
        kDefinesText[kShadowEffect], [&](fplbase::Shader *shader) {
          shader->SetUniform("view_projection", camera_transform);
          shader->SetUniform("light_view_projection",
                             light_camera_.GetTransformMatrix());
        });
  }

  world->asset_manager->ForEachShaderWithDefine(
      "WATER", [&](fplbase::Shader *shader) {
        shader->SetUniform("river_offset", river_offset);
        shader->SetUniform("texture_repeats", texture_repeats);
      });

  world->asset_manager->ForEachShaderWithDefine(
      kDefinesText[kPhongShading],
      [&](fplbase::Shader *shader) { SetLightingUniforms(shader, world); });

  world->asset_manager->ForEachShaderWithDefine(
      "FOG_EFFECT",
      [&](fplbase::Shader *shader) { SetFogUniforms(shader, world); });

  shadow_map_.BindAsTexture(kShadowMapTextureID);
  PopDebugMarker(); // Scene Setup

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

  if (world->draw_debug_physics) {
    PushDebugMarker("Debug Draw World");
    world->physics_component.DebugDrawWorld(&renderer, camera_transform);
    PopDebugMarker();
  }

  PushDebugMarker("Text");
  world->render_3d_text_component.RenderAllEntities(camera);
  PopDebugMarker();

  PopDebugMarker(); // Render World
}