-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.x] Add an option to update shadow maps less often #54516
Open
Calinou
wants to merge
1
commit into
godotengine:3.x
Choose a base branch
from
Calinou:shadow-add-frameskip-option-3.x
base: 3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+31
−8
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2641,8 +2641,19 @@ 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; | ||
|
||
// directional lights | ||
{ | ||
if (bool(GLOBAL_GET("rendering/quality/shadows/update_every_2_frames"))) { | ||
// Toggle between directional and point light shadow updating every frame. | ||
// This update staggering avoids stuttering by splitting CPU/GPU load across frames. | ||
if (shadow_map_update == ShadowMapUpdate::SHADOW_MAP_UPDATE_DIRECTIONAL) { | ||
shadow_map_update = ShadowMapUpdate::SHADOW_MAP_UPDATE_POINT; | ||
} else { | ||
shadow_map_update = ShadowMapUpdate::SHADOW_MAP_UPDATE_DIRECTIONAL; | ||
} | ||
} else { | ||
shadow_map_update = ShadowMapUpdate::SHADOW_MAP_UPDATE_POINT_AND_DIRECTIONAL; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is just to rotate between 3 modes, we can alternatively just cast to an int and increment then wraparound to zero. |
||
{ // directional lights | ||
Instance **lights_with_shadow = (Instance **)alloca(sizeof(Instance *) * scenario->directional_lights.size()); | ||
int directional_shadow_count = 0; | ||
|
||
|
@@ -2668,17 +2679,18 @@ void VisualServerScene::_prepare_scene(const Transform p_cam_transform, const Ca | |
} | ||
} | ||
|
||
VSG::scene_render->set_directional_shadow_count(directional_shadow_count); | ||
if (shadow_map_update != ShadowMapUpdate::SHADOW_MAP_UPDATE_POINT) { | ||
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 (shadow_map_update != ShadowMapUpdate::SHADOW_MAP_UPDATE_DIRECTIONAL) { | ||
// Set up point light shadow maps. | ||
|
||
//SortArray<Instance*,_InstanceLightsort> sorter; | ||
//sorter.sort(light_cull_result,light_cull_count); | ||
for (int i = 0; i < light_cull_count; i++) { | ||
Instance *ins = light_cull_result[i]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This technique is discouraged to be used every frame, as these string methods are not efficient.
If you look in the comment section at the top of
project_settings.h
, there are now two methods to only query this when project settings have changed.From
VisualServerScene
, as it cannot receive signals, you probably want to cache this value, and callProjectSettings::has_changes()
and only call GLOBAL_GET if changes have occurred.We can probably centralize this for all such project settings that need to be cached in e.g.
VisualServer
. If you are not sure how to do this, just remind me after such a change and I can put this in.We may alternatively be able to use a little macro to do this and store the cached value in a static, much like the
WARN_PRINT_ONCE
type macros.