Skip to content

Commit

Permalink
Improve 3D global illumination demo (3.x) (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
Calinou authored Jan 17, 2023
1 parent 24519e5 commit 4357b5b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 25 deletions.
3 changes: 2 additions & 1 deletion 3d/global_illumination/default_env.tres
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ background_mode = 2
background_sky = SubResource( 1 )
fog_sun_amount = 1.0
fog_depth_begin = 0.0
tonemap_mode = 2
tonemap_mode = 4
tonemap_white = 6.0
ssao_intensity = 0.5
12 changes: 10 additions & 2 deletions 3d/global_illumination/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ cycle_gi_mode={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
toggle_reflection_probe={
cycle_reflection_probe_mode={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":82,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":82,"unicode":0,"echo":false,"script":null)
]
}
move_forward={
Expand Down Expand Up @@ -62,6 +62,11 @@ toggle_mouse_capture={
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777217,"unicode":0,"echo":false,"script":null)
]
}
toggle_ssao={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":70,"unicode":0,"echo":false,"script":null)
]
}

[physics]

Expand All @@ -70,4 +75,7 @@ common/enable_pause_aware_picking=true
[rendering]

quality/shadows/filter_mode=2
quality/filters/use_fxaa=true
quality/filters/use_debanding=true
environment/default_environment="res://default_env.tres"
quality/filters/use_debanding.mobile=false
54 changes: 43 additions & 11 deletions 3d/global_illumination/test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,45 @@ const GI_MODE_TEXTS = [
"GIProbe (Slow)",
]

enum ReflectionProbeMode {
NONE,
ONCE,
ALWAYS,
MAX,
}

# Keep this in sync with the ReflectionProbeMode enum (except for MAX).
const REFLECTION_PROBE_MODE_TEXTS = [
"Disabled - Using environment, VoxelGI or SDFGI reflections (Fastest)",
"Enabled - \"Once\" Update Mode (Average)",
"Enabled - \"Always\" Update Mode (Slow)",
]

var gi_mode = GIMode.NONE
var use_reflection_probe = false
var reflection_probe_mode = ReflectionProbeMode.NONE
var use_ssao = false

onready var environment = preload("res://default_env.tres")
onready var gi_mode_label = $GIMode
onready var reflection_probe_mode_label = $ReflectionProbeMode
onready var reflection_probe = $Camera/ReflectiveSphere/ReflectionProbe


func _ready():
set_gi_mode(GIMode.NONE)
set_use_reflection_probe(false)
set_reflection_probe_mode(ReflectionProbeMode.NONE)
set_use_ssao(use_ssao)


func _input(event):
if event.is_action_pressed("cycle_gi_mode"):
set_gi_mode(wrapi(gi_mode + 1, 0, GIMode.MAX))

if event.is_action_pressed("toggle_reflection_probe"):
set_use_reflection_probe(not use_reflection_probe)
if event.is_action_pressed("cycle_reflection_probe_mode"):
set_reflection_probe_mode(wrapi(reflection_probe_mode + 1, 0, ReflectionProbeMode.MAX))

if event.is_action_pressed("toggle_ssao"):
set_use_ssao(not use_ssao)


func set_gi_mode(p_gi_mode):
Expand Down Expand Up @@ -103,12 +123,24 @@ func set_gi_mode(p_gi_mode):
$CornerSpotLight.light_bake_mode = Light.BAKE_INDIRECT


func set_use_reflection_probe(p_visible):
use_reflection_probe = p_visible
func set_reflection_probe_mode(p_reflection_probe_mode):
reflection_probe_mode = p_reflection_probe_mode
reflection_probe_mode_label.text = "Reflection probe: %s " % REFLECTION_PROBE_MODE_TEXTS[reflection_probe_mode]

match p_reflection_probe_mode:
ReflectionProbeMode.NONE:
reflection_probe.visible = false
reflection_probe.update_mode = ReflectionProbe.UPDATE_ONCE
ReflectionProbeMode.ONCE:
reflection_probe.visible = true
reflection_probe.update_mode = ReflectionProbe.UPDATE_ONCE
ReflectionProbeMode.ALWAYS:
reflection_probe.visible = true
reflection_probe.update_mode = ReflectionProbe.UPDATE_ALWAYS


if p_visible:
reflection_probe_mode_label.text = "Current reflection probe mode: Enabled - Using reflection probe (Average)"
else:
reflection_probe_mode_label.text = "Current reflection probe mode: Disabled - Using environment or GIProbe reflections (Fast)"
func set_use_ssao(p_use_ssao):
use_ssao = p_use_ssao
reflection_probe_mode_label.text = "Screen-space ambient occlusion: %s" % "Enabled (Slow)" if use_ssao else "Disabled (Fastest)"

reflection_probe.visible = p_visible
environment.ssao_enabled = use_ssao
28 changes: 17 additions & 11 deletions 3d/global_illumination/test.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ data = SubResource( 1 )
[node name="Sun" type="DirectionalLight" parent="."]
transform = Transform( 0.889832, -0.251497, 0.380722, 0, 0.834387, 0.551179, -0.456289, -0.490456, 0.742464, 4.47302, 6.47568, 8.72305 )
shadow_enabled = true
directional_shadow_normal_bias = 0.1
directional_shadow_bias_split_scale = 1.0
directional_shadow_max_distance = 85.0

[node name="GrateOmniLight" type="OmniLight" parent="."]
Expand Down Expand Up @@ -133,7 +135,7 @@ material/0 = SubResource( 3 )
[node name="ReflectionProbe" type="ReflectionProbe" parent="Camera/ReflectiveSphere"]
transform = Transform( 1, -8.38189e-09, -8.9407e-08, 5.58791e-09, 1, -5.21541e-07, 4.47035e-08, 1.11759e-07, 1, 0, 0, 0 )
max_distance = 50.0
extents = Vector3( 10, 10, 10 )
extents = Vector3( 2, 2, 2 )
box_projection = true
enable_shadows = true

Expand All @@ -152,20 +154,24 @@ margin_left = 16.0
margin_top = 40.0
margin_right = 272.0
margin_bottom = 54.0
text = "Reflection probe:"
__meta__ = {
"_edit_use_anchors_": false
}
text = "Disabled - Using environment, VoxelGI or SDFGI reflections (Fastest)"

[node name="Label" type="Label" parent="."]
[node name="SSAO" type="Label" parent="."]
margin_left = 16.0
margin_top = 64.0
margin_right = 454.0
margin_right = 455.0
margin_bottom = 78.0
text = "Press Space to cycle between GI modes, R to toggle reflection probe
text = "Screen-space ambient occlusion: Disabled (Fastest)"

[node name="Label" type="Label" parent="."]
anchor_top = 1.0
anchor_bottom = 1.0
margin_left = 16.0
margin_top = -50.0
margin_right = 496.0
margin_bottom = -16.0
custom_constants/line_spacing = 6
text = "Press Space to cycle between GI modes, R to cycle reflection probe modes
Press Esc or F10 to toggle mouse capture"
__meta__ = {
"_edit_use_anchors_": false
}

[editable path="GlowingBox"]

0 comments on commit 4357b5b

Please sign in to comment.