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

Function GetShadowableTris

Source/Main/engine.cpp:3791–3891  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3789};
3790
3791void GetShadowableTris(SceneGraph* scenegraph) {
3792 // For each cascade size
3793 // Divide scene into tiles
3794 // Draw tiles using shader that renders the triangle and object id to a texture
3795 // Read the texture and add triangle/object pair to a set
3796 // Create model for each tile
3797
3798 Graphics* graphics = Graphics::Instance();
3799 Camera* camera = ActiveCameras::Get();
3800
3801 vec3 light_dir = scenegraph->primary_light.pos;
3802 vec3 basis[3];
3803 basis[2] = light_dir;
3804 basis[0] = normalize(cross(vec3(0, 1, 0), basis[2]));
3805 basis[1] = normalize(cross(basis[0], basis[2]));
3806
3807 vec3 camera_pos;
3808
3809 ShadowCascadeParams shadow_params;
3810 for (int i = 0; i < NUM_SHADOW_CASCADES; ++i) {
3811 float shadow_size = shadow_sizes[i];
3812 float shadow_radius = shadow_size / 1.414213563731f / 2.0f; // Get radius of circle inscribed in square with sides 'shadow_size'
3813 vec3 shadow_center = camera_pos;
3814 vec3 light_space_center(
3815 dot(shadow_center, basis[0]),
3816 dot(shadow_center, basis[1]),
3817 dot(shadow_center, basis[2]));
3818 // Snap center to nearest texel to improve frame-to-frame coherency
3819 float texel_size = shadow_size * 2.0f / graphics->shadow_res;
3820 for (int j = 0; j < 3; ++j) {
3821 light_space_center[j] = floor(light_space_center[j] / texel_size) * texel_size;
3822 }
3823 // Update shadow center to new texel-snapped position
3824 shadow_center = light_space_center[0] * basis[0] +
3825 light_space_center[1] * basis[1];
3826
3827 GLuint res = graphics->cascade_shadow_res / 2;
3828 uvec4& viewport = shadow_params.viewport[i];
3829 switch (i) {
3830 case 0:
3831 viewport = uvec4(0, 0, res, res);
3832 break;
3833 case 1:
3834 viewport = uvec4(res, 0, res * 2, res);
3835 break;
3836 case 2:
3837 viewport = uvec4(0, res, res, res * 2);
3838 break;
3839 case 3:
3840 viewport = uvec4(res, res, res * 2, res * 2);
3841 break;
3842 }
3843 mat4 proj, view;
3844 camera->applyShadowViewpoint(light_dir, shadow_center, shadow_size, &proj, &view);
3845 mat4 proj_view_matrix = proj * view;
3846 graphics->cascade_shadow_mat[i] = proj_view_matrix;
3847 shadow_params.proj_view_matrix[i] = proj_view_matrix;
3848 for (int j = 0; j < 6; ++j) {

Callers

nothing calls this directly

Calls 15

uvec4Class · 0.85
DrawShadowCacheFunction · 0.85
applyShadowViewpointMethod · 0.80
PushFramebufferMethod · 0.80
bindFramebufferMethod · 0.80
PushViewportMethod · 0.80
PopViewportMethod · 0.80
PopFramebufferMethod · 0.80
GetFunction · 0.50
normalizeFunction · 0.50
crossFunction · 0.50
vec3Class · 0.50

Tested by

no test coverage detected