Skip to content

Commit

Permalink
Update shadowmaps at half framerate
Browse files Browse the repository at this point in the history
  • Loading branch information
m4nu3lf committed Nov 1, 2021
1 parent d5adb9e commit f2382a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions servers/visual/visual_server_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2641,6 +2641,8 @@ void VisualServerScene::_prepare_scene(const Transform p_cam_transform, const Ca
RID *directional_light_ptr = &light_instance_cull_result[light_cull_count];
directional_light_count = 0;

update_shadows = !update_shadows;

// directional lights
{
Instance **lights_with_shadow = (Instance **)alloca(sizeof(Instance *) * scenario->directional_lights.size());
Expand Down Expand Up @@ -2668,14 +2670,18 @@ void VisualServerScene::_prepare_scene(const Transform p_cam_transform, const Ca
}
}

VSG::scene_render->set_directional_shadow_count(directional_shadow_count);
if(update_shadows) {

VSG::scene_render->set_directional_shadow_count(directional_shadow_count);

for (int i = 0; i < directional_shadow_count; i++) {
_light_instance_update_shadow(lights_with_shadow[i], p_cam_transform, p_cam_projection, p_cam_orthogonal, p_shadow_atlas, scenario);
for (int i = 0; i < directional_shadow_count; i++) {
_light_instance_update_shadow(lights_with_shadow[i], p_cam_transform, p_cam_projection, p_cam_orthogonal, p_shadow_atlas, scenario);
}
}
}

{ //setup shadow maps

if (update_shadows) { //setup shadow maps

//SortArray<Instance*,_InstanceLightsort> sorter;
//sorter.sort(light_cull_result,light_cull_count);
Expand Down
4 changes: 4 additions & 0 deletions servers/visual/visual_server_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef VISUALSERVERSCENE_H
#define VISUALSERVERSCENE_H

#include "core/math/transform.h"
#include "servers/visual/rasterizer.h"

#include "core/math/bvh.h"
Expand Down Expand Up @@ -709,6 +710,9 @@ class VisualServerScene {
void render_camera(Ref<ARVRInterface> &p_interface, ARVRInterface::Eyes p_eye, RID p_camera, RID p_scenario, Size2 p_viewport_size, RID p_shadow_atlas);
void update_dirty_instances();

bool update_shadows = true;
Transform shadow_cam_transform;

//probes
struct GIProbeDataHeader {
uint32_t version;
Expand Down

0 comments on commit f2382a7

Please sign in to comment.