MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / UpdateShadowCache

Function UpdateShadowCache

Source/Main/engine.cpp:3444–3766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3442}
3443
3444static bool UpdateShadowCache(SceneGraph* scenegraph) {
3445 Graphics* graphics = Graphics::Instance();
3446 Textures* textures = Textures::Instance();
3447 Shaders* shaders = Shaders::Instance();
3448 PROFILER_ENTER(g_profiler_ctx, "Get bounds");
3449
3450 // Get basis from light perspective
3451 vec3 light_dir = scenegraph->primary_light.pos;
3452 vec3 light_to_world_basis[3];
3453 light_to_world_basis[2] = light_dir;
3454 light_to_world_basis[0] = normalize(cross(vec3(0, 1, 0), light_to_world_basis[2]));
3455 light_to_world_basis[1] = normalize(cross(light_to_world_basis[0], light_to_world_basis[2]));
3456 mat4 light_to_world_transform = {
3457 light_to_world_basis[0][0],
3458 light_to_world_basis[0][1],
3459 light_to_world_basis[0][2],
3460 0.0f,
3461 light_to_world_basis[1][0],
3462 light_to_world_basis[1][1],
3463 light_to_world_basis[1][2],
3464 0.0f,
3465 light_to_world_basis[2][0],
3466 light_to_world_basis[2][1],
3467 light_to_world_basis[2][2],
3468 0.0f,
3469 0.0f,
3470 0.0f,
3471 0.0f,
3472 1.0f,
3473 };
3474 mat4 world_to_light_transform = transpose(light_to_world_transform);
3475
3476 // Get bounds of scene in light space
3477 const int kMaxUpdatesPerFrame = 32;
3478 bool max_updates_hit = false;
3479 int current_update_count = 0;
3480 if (shadow_cache_dirty_sun_moved) {
3481 // Dirty all objects once, so iterative processing can clean them up
3482 for (auto& lb : scenegraph->visible_static_meshes_shadow_cache_bounds_) {
3483 if (!lb.is_ignored) {
3484 lb.is_calculated = false;
3485 }
3486 }
3487 for (auto& lb : scenegraph->terrain_objects_shadow_cache_bounds_) {
3488 lb.is_calculated = false;
3489 }
3490 }
3491 float bounds[4] = {FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX}; // min_x, min_y, max_x, max_y
3492 for (size_t i = 0, len = scenegraph->visible_static_meshes_.size(); i < len && !max_updates_hit; ++i) {
3493 EnvObject& eo = *scenegraph->visible_static_meshes_[i];
3494 ShadowCacheObjectLightBounds& lb = scenegraph->visible_static_meshes_shadow_cache_bounds_[i];
3495 lb.is_ignored = eo.attached_ != NULL;
3496 if (!lb.is_ignored) {
3497 if (!lb.is_calculated || shadow_cache_dirty_level_loaded) {
3498 const Model& env_model = *eo.GetModel();
3499 const mat4& model_to_world_transform = eo.GetTransform();
3500 CalculateMinMax(world_to_light_transform * model_to_world_transform, env_model, &lb.min_bounds[0]);
3501 lb.is_calculated = true;

Callers 1

DrawMethod · 0.85

Calls 15

CalculateMinMaxFunction · 0.85
maxFunction · 0.85
DrawShadowCacheFunction · 0.85
PushFramebufferMethod · 0.80
bindFramebufferMethod · 0.80
PushViewportMethod · 0.80
applyShadowViewpointMethod · 0.80
PopViewportMethod · 0.80
PopFramebufferMethod · 0.80
SetBlendFuncMethod · 0.80
returnProgramMethod · 0.80
genFramebuffersMethod · 0.80

Tested by

no test coverage detected