Stage 3 of 11
The ground, the sun and the dusk
By the end
- Three checker materials, each exactly two flat greys.
- The level kit's first three scripts, and with them a Block node you can add like any other.
main.tscn: an 80 m floor, a low sun from the left, and an environment with dusk fog.
Nothing runs yet, because there's no camera. You'll see it in the editor's 3D view.
This stage makes the world: a floor to stand on, light and fog. The look is Wagee's, which follows PolyCube's prototypes: every surface is a checker of exactly two flat greys, and what a thing is for decides which checker it gets.
| Look | Greys | Squares | For |
|---|---|---|---|
floor | 0.47 / 0.36 | 1 m | The ground |
dark | 0.30 / 0.23 | 0.5 m | Everything standing on the ground |
light | 0.82 / 0.68 | 0.25 m | What you use (it glows a little) |
Three tiny pictures
Each checker's texture is four pixels: two greys on the diagonals. Godot's editor doesn't paint, so make them in any paint program as 2 × 2 pixel PNGs, lighter grey top-left and bottom-right:
| File | Lighter grey | Darker grey |
|---|---|---|
look/materials/floor.png | #777777 | #5b5b5b |
look/materials/dark.png | #4c4c4c | #3a3a3a |
look/materials/light.png | #d1d1d1 | #adadad |
Make the folders look and look/materials in the FileSystem dock and save the three files there. Then stop Godot from "helping" with them:
- Select all three PNGs in the FileSystem dock and open the Import dock (a tab beside Scene).
- Set Detect 3D → Compress To to Disabled, and press Reimport.
Left alone, Godot would notice these are used in 3D and re-import them compressed for the graphics card. That compression works in blocks of 4 × 4 pixels and can't keep a grey exactly grey, and the look's rule is two flat greys.
(The repo's three materials carry their four pixels inside the .tres file instead of in a PNG. A script wrote them that way when the look was copied from Wagee. The pixels are the same.)
Three materials
For each look, right-click look/materials → Create New → Resource..., choose StandardMaterial3D in Create New Resource, and save it as floor.tres, dark.tres or light.tres (the dialog offers new_standard_material_3d.tres, in that folder). The names and the folder matter: a script loads them by path. The new material opens in the Inspector. Set these on all three:
| Section | Property | Value | Why |
|---|---|---|---|
| Shading | Specular Mode | Disabled | No shine: flat greys stay flat. |
| Albedo | Texture | that look's PNG (drag it in from the FileSystem dock) | The checker. |
| UV1 | Triplanar | On | The checker is laid on from the three axes, in metres, so it's the same size on a box of any shape and never stretches. |
| Sampling | Filter | Nearest | Hard squares. |
Then the differences:
| Material | Section | Property | Value | Why |
|---|---|---|---|---|
floor.tres | UV1 | Scale | 0.5, 0.5, 0.5 | The picture is two squares across, so half a repeat a metre is a 1 m square. Type it into x: the three are linked. |
dark.tres | UV1 | Scale | 1, 1, 1 (as it is) | 0.5 m squares. |
light.tres | UV1 | Scale | 2, 2, 2 | 0.25 m squares. |
light.tres | Emission | (header checkbox) | On | It glows. |
| Texture | light.png | Glowing in its own checker. | ||
| Energy Multiplier | 0.25 | A little. |
floor.tres from start to finish: the new resource, the four values every checker has, and the floor's own Scale. The other two are made the same way.Why it's like this
The floor's squares were 0.5 m, as in Wagee. The owner asked for a sense of depth "a bit like t3ssel8r's", whose view has big tiles, so the floor went to 1 m. The dark pieces kept 0.5 m, which sets them apart from the ground.
The level kit, where code is the right tool
You could build the floor from three nodes: a StaticBody3D, a CollisionShape3D with a box, and a MeshInstance3D with a box the same size and the right material. Every platform, wall and step after it would be the same three nodes again, with two sizes to keep the same by hand.
Wagee's level kit does that part in code. A piece is one node with a few numbers. You still place it by hand and set its numbers in the Inspector; a @tool script (one that also runs inside the editor) makes the body, the shape and the box from them, and makes them again whenever a number changes. The layout stays yours, and only the piece's insides are built by code.
Make three scripts, in this order, each as the repo's file:
look/looks.gdlevel/pieces/piece.gdlevel/pieces/block.gd
looks.gd turns a look's name into its material. This is why the names and the folder mattered:
const CHECKERS := "res://look/materials/%s.tres"
static func material(role: String) -> Material:
return load(CHECKERS % role)piece.gd is what every piece has in common. Making the piece again means throwing its old parts away and building new ones:
func _rebuild() -> void:
if not is_inside_tree():
return # (_ready makes it)
for child in get_children(true):
if child.has_meta("piece_part"):
remove_child(child)
child.queue_free()
_build()Each part is added as an internal child, so it isn't listed in the Scene dock and isn't saved in the scene file. Only your numbers are saved:
func _part(node: Node) -> Node:
node.set_meta("piece_part", true)
add_child(node, false, Node.INTERNAL_MODE_BACK)
return nodeblock.gd is a box. Each of its numbers has a setter that rebuilds it, which is what makes the box change as you type in the Inspector:
@export var size := Vector3(2.0, 1.0, 2.0):
set(value):
size = value
_rebuild()And its parts are the three nodes you'd have made by hand. collider() and box() are small helpers in piece.gd that make a box-shaped CollisionShape3D and MeshInstance3D:
func _make_box() -> StaticBody3D:
var body := _body(look == "floor")
body.add_child(collider(Transform3D.IDENTITY, size))
var mesh := box(Transform3D.IDENTITY, size, look)
mesh.visible = not hidden
mesh.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_ON if shadow else GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
body.add_child(mesh)
return bodyblock.gd begins with class_name Block, so the editor now offers Block as a kind of node.
The main scene
- Scene → New Scene. Under Create Root Node: press 3D Scene. Rename the root
Mainand save the scene asres://main.tscn. - Right-click
main.tscnin the FileSystem dock → Set as Main Scene. - Add a Node3D under
Mainand name itLevel. It's only a folder for the level's pieces. - Under
Level, Add Child Node..., search forBlockand create it. Name itGroundand set:
| Section | Property | Value | Why |
|---|---|---|---|
| (the script's) | Size | 80, 1, 80 | A big slab. |
| (the script's) | Look | floor | The ground's checker. It also marks the body as "rough", for footstep sounds one day. |
| Transform | Position | 0, −0.5, 0 | A block is centred on its node. Half its height down puts its top at y = 0. |
The slab appears in the 3D view as you type. It's on collision layer 1, where a new body starts, and that matters later: layer 1 is "the level", the only layer Leela's feet look for.
The sun
Add a DirectionalLight3D under Main and name it Sun.
| Section | Property | Value | Why |
|---|---|---|---|
| Transform | Rotation | −42, −63.4, 0 | 42° above the horizon, shining from the screen's left once the camera's in place. |
| Light | Color | Color(0.95, 0.9, 0.92), #f2e6eb | A slightly warm white. |
| Energy | 1.02 | ||
| Shadow | (header checkbox) | On | |
| Blur | 0.25 | Crisp edges. | |
| Directional Shadow | Mode | Orthogonal (Fast) | One shadow map with no splits, which suits a camera with no perspective. |
| Max Distance | 46 | Shadows only as far as the fog lets you see. |
Why it's like this
Wagee's sun was high (62°) and behind the camera, which lit everything evenly and looked flat here. Low and from the left, a block's top, left face and right face get three different tones, and shadows fall long to the right where they show. At the default blur those long shadows were fuzzy blobs, and the owner asked for crisp ones. The shorter reach helps too: the shadow map's pixels are spent on what's in view.
The dusk
The environment holds the sky, the fog and the screen effects. The sky is a shader from Wagee.
- Copy
look/mood_sky.gdshaderfrom the repo into yourlookfolder. - Add a WorldEnvironment under
Main. In the Inspector, set its Environment slot to New → Environment. Then click the slot's arrow → Save As... and save it asres://look/environment.tres, so the look lives in a file of its own. - Click the environment to open it, and set the values in the table below.
| Section | Property | Value | Why |
|---|---|---|---|
| Background | Mode | Sky | Choosing it brings the Sky section. |
| Sky | Sky | New → Sky, then inside it: | |
| → Sky Material | New → ShaderMaterial, with Shader set to mood_sky.gdshader | An overcast night. | |
| → Shader Parameters → Fog Color | Color(0.16, 0.15, 0.21), #292636 | The sky's horizon, matching the fog. | |
| → Radiance Size | 32 | Nothing here reflects the sky, so the smallest will do. | |
| Ambient Light | Source | Color | A fixed colour, not the sky's. |
| Color | Color(0.48, 0.45, 0.68), #7a73ad | Dusk violet: what shade and unlit faces turn. | |
| Energy | 0.42 | ||
| Reflected Light | Source | Disabled | No reflections of the sky. |
| SSAO | (header checkbox) | On | Ambient occlusion: a soft darkening where things meet the floor. |
| Glow | (header checkbox) | On | |
| Intensity | 0.6 | ||
| Bloom | 0.05 | ||
| Fog | (header checkbox) | On | |
| Mode | Depth | Fog by distance from the camera, between two distances you choose. | |
| Light Color | Color(0.16, 0.15, 0.21), #292636 | A dark dusk violet. | |
| Density | 1 | In this mode: how thick it is at the far distance. 1 hides everything there. The editor sets it to 1 by itself when you choose Depth. | |
| Sky Affect | 0 | The sky isn't fogged; it fades into the fog's colour by itself. | |
| Depth Curve | 1.2 | It's drawn as a curve: double-click it to type the number. The three Depth rows only show once Mode is Depth. | |
| Depth Begin | 28 | ||
| Depth End | 39.5 | ||
| Adjustments | (header checkbox) | On | |
| Contrast | 1.1 | ||
| Saturation | 0.9 | A little colour taken out. |
Why 28 and 39.5
The camera you'll add next stands 30 m back from what it looks at. So the ground in the middle of the screen is 30 m away, the bottom of the screen a little nearer and the top a little further. Fog that begins at 28 m leaves the near ground clear and fades the far side of the view. That's most of the sense of depth in a view with no perspective. If you ever change the camera's distance, move both numbers with it.
The sky you won't see. mood_sky.gdshader draws slow dark clouds that bunch up towards the horizon and fade into fog_color there. A camera with no perspective looks the same way from every pixel, so in the game the sky only ever shows as one flat colour: the fog's. Tilt the editor's view up to see the clouds.
Checkpoint
Nothing runs yet (there's no camera), so look in the editor's 3D view. You should see a grey checkered floor of 1 m squares running off into dark violet haze, lit from one side, under a dark cloudy sky.
- The floor is plain white, with errors in the Output panel:
floor.tresis missing, misnamed or not inlook/materials. - The floor is a darker, finer checker: Look is still
dark. - There's no floor until you reopen the scene: a
@toolscript sometimes isn't picked up by a scene that was already open. Scene → Reload Saved Scene. - The squares are blurred: a material's Filter isn't Nearest.
- The squares are smeared along the slab's sides: Triplanar is off.
- No haze at all: the fog's Mode isn't Depth, or its Density isn't 1.