Skip to content

Commit

Permalink
Add a global illumination demo
Browse files Browse the repository at this point in the history
Port of the 3.x global illumination demo, with SDFGI support added
and screen-space lighting effect options added (SSAO, SSIL, or both).

Lightmap options were removed as I couldn't get both indirect-only
and fully baked lightmaps to work for now. They can be readded in the
future.
  • Loading branch information
Calinou committed Apr 5, 2022
1 parent 2e40f67 commit 4d4fbeb
Show file tree
Hide file tree
Showing 19 changed files with 296 additions and 2,398 deletions.
28 changes: 3 additions & 25 deletions 3d/global_illumination/README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
# Global Illumination

This demo showcases Godot's global illumination systems:
[GIProbe](https://docs.godotengine.org/en/stable/tutorials/3d/gi_probes.html),
[BakedLightmap](https://docs.godotengine.org/en/stable/tutorials/3d/baked_lightmaps.html)
(indirect only and fully baked) and
[ReflectionProbe](https://docs.godotengine.org/en/stable/tutorials/3d/reflection_probes.html).
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.

Language: GDScript

Renderer: GLES 3[^1]

Check out this demo on the asset library: https://godotengine.org/asset-library/asset/1290
Renderer: Vulkan

## How does it work?

A glTF scene (which acts as the level mesh) is imported with its **Light Baking**
option set to **Gen Lightmaps**.
This is required for BakedLightmap to work (but is not required for GIProbe
or BakedLightmap).

The level mesh is duplicated several times to allow displaying it with various bake settings:

- No baking (uses GIProbe or environment lighting).
- Baked indirect lighting. Slower, but allows for real-time shadows to display
on baked surfaces.
- Baked direct *and* indirect lighting. Faster, but does not allow for real-time
shadows to display on baked surfaces.

A sphere and box are parented to the camera to showcase dynamic object lighting.
A ReflectionProbe is parented to the sphere to showcase real-time reflections.
When the ReflectionProbe is hidden, it is disabled. In this case,
GIProbe or environment lighting will be used to provide fallback reflections.
VoxelGI, SDFGI or environment lighting will be used to provide fallback reflections.

## Screenshots

Expand All @@ -45,7 +27,3 @@ GIProbe or environment lighting will be used to provide fallback reflections.
map "zdm2" and is
[licensed under CC BY 4.0 Unported](https://github.com/Calinou/game-maps-obj/blob/master/sauerbraten/zdm2.txt).
The OBJ file which it was converted from is available in the [game-maps-obj](https://github.com/Calinou/game-maps-obj) repository.

[^1]: This demo can be made to work with GLES2, but GIProbe will not work.
Additionally, lightmaps have to be rebaked with the **Atlas > Generate** property
disabled in BakedLightmap.
8 changes: 4 additions & 4 deletions 3d/global_illumination/camera.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends Camera
extends Camera3D

const MOUSE_SENSITIVITY = 0.002
const MOVE_SPEED = 1.5
Expand All @@ -18,7 +18,7 @@ func _input(event):
rot.y -= event.relative.x * MOUSE_SENSITIVITY
# Vertical mouse look.
rot.x = clamp(rot.x - event.relative.y * MOUSE_SENSITIVITY, -1.57, 1.57)
transform.basis = Basis(rot)
transform.basis = Basis.from_euler(rot)

if event.is_action_pressed("toggle_mouse_capture"):
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
Expand All @@ -38,6 +38,6 @@ func _process(delta):
# `sqrt(2)` times faster than straight movement.
motion = motion.normalized()

velocity += MOVE_SPEED * delta * transform.basis.xform(motion)
velocity += MOVE_SPEED * delta * (transform.basis * motion)
velocity *= 0.85
translation += velocity
position += velocity
Loading

0 comments on commit 4d4fbeb

Please sign in to comment.