Skip to content
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

Improve 3D global illumination demo (4.0) #758

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion 3d/global_illumination/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Global Illumination

This demo showcases Godot's global illumination systems:
VoxelGI, SDFGI, ReflectionProbe and screen-space effects like SSAO and SSIL.
LightmapGI, VoxelGI, SDFGI, ReflectionProbe and screen-space effects like SSAO and SSIL.

Use the mouse to look around, <kbd>W</kbd>/<kbd>A</kbd>/<kbd>S</kbd>/<kbd>D</kbd>
or arrow keys to move.
Expand All @@ -17,6 +17,10 @@ A ReflectionProbe is parented to the sphere to showcase real-time reflections.
When the ReflectionProbe is hidden, it is disabled. In this case,
VoxelGI, SDFGI or environment lighting will be used to provide fallback reflections.

A Decal node is parented to the moving sphere and cube to provide simple shadows for them.
This is especially effective when using the LightmapGI (All) global illumination mode,
which doesn't allow dynamic objects to cast shadows on static surfaces.

## Screenshots

![Screenshot](screenshots/global_illumination.png)
Expand Down
2 changes: 2 additions & 0 deletions 3d/global_illumination/cube.glb.import
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/cube.glb-ec927bc01951d93b2130ba52799eca7c.scn

nodes/root_type="Spatial"
nodes/root_name="Scene Root"
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
Expand All @@ -24,5 +25,6 @@ meshes/lightmap_texel_size=0.1
skins/use_named_skins=true
animation/import=true
animation/fps=15
animation/trimming=false
import_script/path=""
_subresources={}
10 changes: 5 additions & 5 deletions 3d/global_illumination/icon.png.import
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[remap]

importer="texture"
type="StreamTexture2D"
type="CompressedTexture2D"
uid="uid://q2k8m14vo3kr"
path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.png"
dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"]
dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"]

[params]

Expand All @@ -21,14 +21,14 @@ compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
compress/streamed=false
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/HDR_as_SRGB=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
9 changes: 8 additions & 1 deletion 3d/global_illumination/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ config_version=5
[application]

config/name="Global Illumination"
config/description="This demo showcases Godot's global illumination systems: LightmapGI, VoxelGI, SDFGI, ReflectionProbe and screen-space effects like SSAO and SSIL."
run/main_scene="res://test.tscn"
config/features=PackedStringArray("4.0")
config/icon="res://icon.png"
Expand All @@ -20,6 +21,10 @@ config/icon="res://icon.png"
window/stretch/mode="canvas_items"
window/stretch/aspect="expand"

[editor]

export/convert_text_resources_to_binary=true

[filesystem]

import/blender/enabled=false
Expand All @@ -31,7 +36,7 @@ cycle_gi_mode={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"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,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"unicode":0,"echo":false,"script":null)
]
Expand Down Expand Up @@ -78,5 +83,7 @@ common/enable_pause_aware_picking=true

[rendering]

anti_aliasing/quality/screen_space_aa=1
anti_aliasing/quality/use_debanding=true
quality/shadows/filter_mode=2
environment/default_environment="res://default_env.tres"
150 changes: 99 additions & 51 deletions 3d/global_illumination/test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ extends Node3D

enum GIMode {
NONE,
# BAKED_LIGHTMAP_ALL,
# BAKED_LIGHTMAP_INDIRECT,
LIGHTMAP_GI_ALL,
LIGHTMAP_GI_INDIRECT,
VOXEL_GI,
SDFGI,
MAX, # Maximum value of the enum, used internally.
Expand All @@ -12,12 +12,26 @@ enum GIMode {
# Keep this in sync with the GIMode enum (except for MAX).
const GI_MODE_TEXTS = [
"Environment Lighting (Fastest)",
# "Baked Lightmap All (Fast)",
# "Baked Lightmap Indirect (Average)",
"Baked Lightmap All (Fast)",
"Baked Lightmap Indirect (Average)",
"VoxelGI (Slow)",
"SDFGI (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 (Fast)",
"Enabled - \"Once\" Update Mode (Average)",
"Enabled - \"Always\" Update Mode (Slow)",
]

enum SSILMode {
NONE,
SSAO,
Expand All @@ -35,7 +49,7 @@ const SSIL_MODE_TEXTS = [
]

var gi_mode = GIMode.NONE
var use_reflection_probe = false
var reflection_probe_mode = ReflectionProbeMode.NONE
var ssil_mode = SSILMode.NONE

@onready var environment = $WorldEnvironment.environment
Expand All @@ -44,19 +58,24 @@ var ssil_mode = SSILMode.NONE
@onready var reflection_probe = $Camera/ReflectiveSphere/ReflectionProbe
@onready var ssil_mode_label = $SSILMode

# Several copies of the level mesh are required to cycle between different GI modes.
@onready var zdm2_no_lightmap = $Zdm2NoLightmap
@onready var zdm2_lightmap_all = $Zdm2LightmapAll
@onready var zdm2_lightmap_indirect = $Zdm2LightmapIndirect


func _ready():
set_gi_mode(gi_mode)
set_use_reflection_probe(use_reflection_probe)
set_reflection_probe_mode(reflection_probe_mode)
set_ssil_mode(ssil_mode)


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("cycle_ssil_mode"):
set_ssil_mode(wrapi(ssil_mode + 1, 0, SSILMode.MAX))
Expand All @@ -68,8 +87,14 @@ func set_gi_mode(p_gi_mode):

match p_gi_mode:
GIMode.NONE:
# $BakedLightmapIndirect.visible = false
# $BakedLightmapAll.visible = false
$Zdm2NoLightmap.visible = true
$Zdm2LightmapAll.visible = false
$Zdm2LightmapIndirect.visible = false

# Halve sky contribution to prevent shaded areas from looking too bright and blue.
environment.ambient_light_sky_contribution = 0.5
$LightmapGIIndirect.visible = false
$LightmapGIAll.visible = false
$VoxelGI.visible = false
environment.sdfgi_enabled = false

Expand All @@ -80,71 +105,94 @@ func set_gi_mode(p_gi_mode):
$GarageOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
$CornerSpotLight.light_bake_mode = Light3D.BAKE_DYNAMIC

# GIMode.BAKED_LIGHTMAP_ALL:
# $BakedLightmapIndirect.visible = false
# $BakedLightmapAll.visible = true
# $VoxelGI.visible = false
# environment.sdfgi_enabled = false
#
# # Make lights not affect baked surfaces by setting their bake mode to All.
# $Sun.light_bake_mode = Light3D.BAKE_STATIC
# $GrateOmniLight.light_bake_mode = Light3D.BAKE_STATIC
# $GarageOmniLight.light_bake_mode = Light3D.BAKE_STATIC
# $CornerSpotLight.light_bake_mode = Light3D.BAKE_STATIC

# GIMode.BAKED_LIGHTMAP_INDIRECT:
# $BakedLightmapIndirect.visible = true
# $BakedLightmapAll.visible = false
# $VoxelGI.visible = false
# environment.sdfgi_enabled = false
#
# $Sun.light_bake_mode = Light3D.BAKE_DYNAMIC
# $GrateOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
# $GarageOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
# $CornerSpotLight.light_bake_mode = Light3D.BAKE_DYNAMIC
GIMode.LIGHTMAP_GI_ALL:
$Zdm2NoLightmap.visible = false
$Zdm2LightmapAll.visible = true
$Zdm2LightmapIndirect.visible = false

# Halve sky contribution to prevent dynamic objects from looking too bright and blue.
# (When using lightmaps, this property doesn't affect lightmapped surfaces.)
environment.ambient_light_sky_contribution = 0.5
$LightmapGIIndirect.visible = false
$LightmapGIAll.visible = true
$VoxelGI.visible = false
environment.sdfgi_enabled = false

# Make lights not affect baked surfaces by setting their bake mode to All.
$Sun.light_bake_mode = Light3D.BAKE_STATIC
$GrateOmniLight.light_bake_mode = Light3D.BAKE_STATIC
$GarageOmniLight.light_bake_mode = Light3D.BAKE_STATIC
$CornerSpotLight.light_bake_mode = Light3D.BAKE_STATIC

GIMode.LIGHTMAP_GI_INDIRECT:
$Zdm2NoLightmap.visible = false
$Zdm2LightmapAll.visible = false
$Zdm2LightmapIndirect.visible = true

# Halve sky contribution to prevent dynamic objects from looking too bright and blue.
# (When using lightmaps, this property doesn't affect lightmapped surfaces.)
environment.ambient_light_sky_contribution = 0.5
$LightmapGIIndirect.visible = true
$LightmapGIAll.visible = false
$VoxelGI.visible = false
environment.sdfgi_enabled = false

$Sun.light_bake_mode = Light3D.BAKE_DYNAMIC
$GrateOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
$GarageOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
$CornerSpotLight.light_bake_mode = Light3D.BAKE_DYNAMIC

GIMode.VOXEL_GI:
# $BakedLightmapIndirect.visible = false
# $BakedLightmapAll.visible = false
$Zdm2NoLightmap.visible = true
$Zdm2LightmapAll.visible = false
$Zdm2LightmapIndirect.visible = false

environment.ambient_light_sky_contribution = 1.0
$LightmapGIIndirect.visible = false
$LightmapGIAll.visible = false
$VoxelGI.visible = true
environment.sdfgi_enabled = false

# Bake mode must be Indirect, not Disabled. Otherwise, GI will
# not be visible for those lights.
# Moving/blinking lights should generally have their bake mode set to Disabled
# to avoid visible GI pop-ins. This is because VoxelGI
# can take a while to update.
$Sun.light_bake_mode = Light3D.BAKE_DYNAMIC
$GrateOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
$GarageOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
$CornerSpotLight.light_bake_mode = Light3D.BAKE_DYNAMIC

GIMode.SDFGI:
# $BakedLightmapIndirect.visible = false
# $BakedLightmapAll.visible = false
$Zdm2NoLightmap.visible = true
$Zdm2LightmapAll.visible = false
$Zdm2LightmapIndirect.visible = false

environment.ambient_light_sky_contribution = 1.0
$LightmapGIIndirect.visible = false
$LightmapGIAll.visible = false
$VoxelGI.visible = false
environment.sdfgi_enabled = true

# Bake mode must be Indirect, not Disabled. Otherwise, GI will
# not be visible for those lights.
# Moving/blinking lights should generally have their bake mode set to Disabled
# to avoid visible GI pop-ins. This is because SDFGI
# can take a while to update.
$Sun.light_bake_mode = Light3D.BAKE_DYNAMIC
$GrateOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
$GarageOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
$CornerSpotLight.light_bake_mode = Light3D.BAKE_DYNAMIC


func set_use_reflection_probe(p_visible):
use_reflection_probe = p_visible

if p_visible:
reflection_probe_mode_label.text = "Reflection probe: Enabled - Using reflection probe (Average)"
else:
reflection_probe_mode_label.text = "Reflection probe: Disabled - Using environment, VoxelGI or SDFGI reflections (Fast)"

reflection_probe.visible = 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


func set_ssil_mode(p_ssil_mode):
Expand Down
Loading