Skip to content

Commit

Permalink
Add a setting to disable real-time light shadows
Browse files Browse the repository at this point in the history
Disabling shadows reduces the number of draw calls significantly,
which improves rendering performance a lot.
  • Loading branch information
Calinou committed Aug 7, 2022
1 parent c1c4cc2 commit b93a898
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 26 deletions.
5 changes: 5 additions & 0 deletions level/level.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func _ready():
else:
get_viewport().msaa = Viewport.MSAA_DISABLED

if not Settings.shadow_enabled:
# Disable shadows on all lights present on level load,
# reducing the number of draw calls significantly.
propagate_call("set", ["shadow_enabled", false])

if Settings.ssao_quality == Settings.SSAOQuality.HIGH:
world_environment.environment.ssao_enabled = true
world_environment.environment.ssao_quality = world_environment.environment.SSAO_QUALITY_HIGH
Expand Down
11 changes: 11 additions & 0 deletions menu/menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ onready var aa_4x = aa_menu.get_node(@"4X")
onready var aa_2x = aa_menu.get_node(@"2X")
onready var aa_disabled = aa_menu.get_node(@"Disabled")

onready var shadow_menu = settings_menu.get_node(@"Shadow")
onready var shadow_enabled = shadow_menu.get_node(@"Enabled")
onready var shadow_disabled = shadow_menu.get_node(@"Disabled")

onready var ssao_menu = settings_menu.get_node(@"SSAO")
onready var ssao_high = ssao_menu.get_node(@"High")
onready var ssao_low = ssao_menu.get_node(@"Low")
Expand Down Expand Up @@ -124,6 +128,11 @@ func _on_settings_pressed():
elif Settings.aa_quality == Settings.AAQuality.DISABLED:
aa_disabled.pressed = true

if Settings.shadow_enabled:
shadow_enabled.pressed = true
else:
shadow_disabled.pressed = true

if Settings.ssao_quality == Settings.SSAOQuality.HIGH:
ssao_high.pressed = true
elif Settings.ssao_quality == Settings.SSAOQuality.LOW:
Expand Down Expand Up @@ -178,6 +187,8 @@ func _on_apply_pressed():
elif aa_disabled.pressed:
Settings.aa_quality = Settings.AAQuality.DISABLED

Settings.shadow_enabled = shadow_enabled.pressed

if ssao_high.pressed:
Settings.ssao_quality = Settings.SSAOQuality.HIGH
elif ssao_low.pressed:
Expand Down
85 changes: 60 additions & 25 deletions menu/menu.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=42 format=2]
[gd_scene load_steps=43 format=2]

[ext_resource path="res://menu/menu.gd" type="Script" id=1]
[ext_resource path="res://menu/experiment.hdr" type="Texture" id=2]
Expand Down Expand Up @@ -92,6 +92,8 @@ Label/styles/normal = null

[sub_resource type="ButtonGroup" id=11]

[sub_resource type="ButtonGroup" id=22]

[sub_resource type="ButtonGroup" id=12]

[sub_resource type="ButtonGroup" id=13]
Expand Down Expand Up @@ -196,9 +198,6 @@ anchor_left = 0.00106799
anchor_right = 1.00107
anchor_bottom = 1.0
theme = SubResource( 9 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Main" type="Control" parent="UI"]
anchor_left = -0.000673103
Expand Down Expand Up @@ -246,9 +245,9 @@ texture_hover = ExtResource( 12 )
[node name="Settings" type="VBoxContainer" parent="UI"]
visible = false
anchor_left = 0.109896
anchor_top = 0.32037
anchor_top = 0.268518
anchor_right = 0.808854
anchor_bottom = 0.785185
anchor_bottom = 0.931481
custom_constants/separation = 30
__meta__ = {
"_edit_use_anchors_": true
Expand Down Expand Up @@ -329,36 +328,72 @@ text = "8x"

[node name="4X" type="Button" parent="UI/Settings/AA"]
margin_left = 665.0
margin_right = 870.0
margin_right = 871.0
margin_bottom = 57.0
size_flags_horizontal = 3
toggle_mode = true
group = SubResource( 11 )
text = "4x"

[node name="2X" type="Button" parent="UI/Settings/AA"]
margin_left = 900.0
margin_right = 1105.0
margin_left = 901.0
margin_right = 1106.0
margin_bottom = 57.0
size_flags_horizontal = 3
toggle_mode = true
group = SubResource( 11 )
text = "2x"

[node name="Disabled" type="Button" parent="UI/Settings/AA"]
margin_left = 1135.0
margin_left = 1136.0
margin_right = 1342.0
margin_bottom = 57.0
size_flags_horizontal = 3
toggle_mode = true
group = SubResource( 11 )
text = "Disabled"

[node name="SSAO" type="HBoxContainer" parent="UI/Settings"]
[node name="Shadow" type="HBoxContainer" parent="UI/Settings"]
margin_top = 174.0
margin_right = 1342.0
margin_bottom = 231.0
custom_constants/separation = 30

[node name="Label" type="Label" parent="UI/Settings/Shadow"]
margin_top = 2.0
margin_right = 400.0
margin_bottom = 55.0
rect_min_size = Vector2( 400, 0 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
text = "Shadow Mapping:"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Enabled" type="Button" parent="UI/Settings/Shadow"]
margin_left = 430.0
margin_right = 871.0
margin_bottom = 57.0
size_flags_horizontal = 3
toggle_mode = true
pressed = true
group = SubResource( 22 )
text = "Enabled"

[node name="Disabled" type="Button" parent="UI/Settings/Shadow"]
margin_left = 901.0
margin_right = 1342.0
margin_bottom = 57.0
size_flags_horizontal = 3
toggle_mode = true
group = SubResource( 22 )
text = "Disabled"

[node name="SSAO" type="HBoxContainer" parent="UI/Settings"]
margin_top = 261.0
margin_right = 1342.0
margin_bottom = 318.0
custom_constants/separation = 30
__meta__ = {
"_edit_group_": true
}
Expand Down Expand Up @@ -403,9 +438,9 @@ group = SubResource( 12 )
text = "Disabled"

[node name="Bloom" type="HBoxContainer" parent="UI/Settings"]
margin_top = 174.0
margin_top = 348.0
margin_right = 1342.0
margin_bottom = 231.0
margin_bottom = 405.0
custom_constants/separation = 30
__meta__ = {
"_edit_group_": true
Expand Down Expand Up @@ -451,9 +486,9 @@ group = SubResource( 13 )
text = "Disabled"

[node name="Resolution" type="HBoxContainer" parent="UI/Settings"]
margin_top = 261.0
margin_top = 435.0
margin_right = 1342.0
margin_bottom = 318.0
margin_bottom = 492.0
custom_constants/separation = 30
__meta__ = {
"_edit_group_": true
Expand Down Expand Up @@ -482,24 +517,24 @@ text = "Native"

[node name="1080" type="Button" parent="UI/Settings/Resolution"]
margin_left = 665.0
margin_right = 870.0
margin_right = 871.0
margin_bottom = 57.0
size_flags_horizontal = 3
toggle_mode = true
group = SubResource( 14 )
text = "1080"

[node name="720" type="Button" parent="UI/Settings/Resolution"]
margin_left = 900.0
margin_right = 1105.0
margin_left = 901.0
margin_right = 1106.0
margin_bottom = 57.0
size_flags_horizontal = 3
toggle_mode = true
group = SubResource( 14 )
text = "720"

[node name="540" type="Button" parent="UI/Settings/Resolution"]
margin_left = 1135.0
margin_left = 1136.0
margin_right = 1342.0
margin_bottom = 57.0
size_flags_horizontal = 3
Expand All @@ -508,9 +543,9 @@ group = SubResource( 14 )
text = "540"

[node name="Fullscreen" type="HBoxContainer" parent="UI/Settings"]
margin_top = 348.0
margin_top = 522.0
margin_right = 1342.0
margin_bottom = 405.0
margin_bottom = 579.0
custom_constants/separation = 30

[node name="Label" type="Label" parent="UI/Settings/Fullscreen"]
Expand Down Expand Up @@ -545,15 +580,15 @@ text = "No"

[node name="HSeparator" type="HSeparator" parent="UI/Settings"]
modulate = Color( 1, 1, 1, 0 )
margin_top = 435.0
margin_top = 609.0
margin_right = 1342.0
margin_bottom = 455.0
margin_bottom = 629.0
rect_min_size = Vector2( 0, 20 )

[node name="Actions" type="HBoxContainer" parent="UI/Settings"]
margin_top = 485.0
margin_top = 659.0
margin_right = 1342.0
margin_bottom = 542.0
margin_bottom = 716.0
custom_constants/separation = 50

[node name="Apply" type="Button" parent="UI/Settings/Actions"]
Expand Down
6 changes: 5 additions & 1 deletion menu/settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum Resolution {

var gi_quality = GIQuality.LOW
var aa_quality = AAQuality.AA_2X
var shadow_enabled = true
var ssao_quality = SSAOQuality.DISABLED
var bloom_quality = BloomQuality.HIGH
var resolution = Resolution.NATIVE
Expand Down Expand Up @@ -66,6 +67,9 @@ func load_settings():
if "aa" in d:
aa_quality = int(d.aa)

if "shadow_enabled" in d:
shadow_enabled = bool(d.shadow_enabled)

if "ssao" in d:
ssao_quality = int(d.ssao)

Expand All @@ -84,5 +88,5 @@ func save_settings():
var error = f.open("user://settings.json", File.WRITE)
assert(not error)

var d = { "gi":gi_quality, "aa":aa_quality, "ssao":ssao_quality, "bloom":bloom_quality, "resolution":resolution, "fullscreen":fullscreen }
var d = { "gi":gi_quality, "aa":aa_quality, "shadow_enabled":shadow_enabled, "ssao":ssao_quality, "bloom":bloom_quality, "resolution":resolution, "fullscreen":fullscreen }
f.store_line(to_json(d))

0 comments on commit b93a898

Please sign in to comment.