TExcelTAD
Home › Godot 4 with GDScript › StandardMaterial3D & Lighting

StandardMaterial3D & Lighting

A MeshInstance3D draws a mesh (the shape) with one or more materials (how its surface reacts to light). For most surfaces you use StandardMaterial3D, Godot's physically based (PBR) material with the usual metallic/roughness workflow. When you need something it cannot do, you write a shader (The Godot Shading Language) or convert the material to one (right-click > Convert to ShaderMaterial in the inspector) and edit the generated code.

The important StandardMaterial3D properties

Inspector group Property Meaning
Albedo albedo_color, albedo_texture base colour; the texture is multiplied by the colour
Metallic metallic (0–1), metallic_texture 0 for paint, plastic, wood, skin; 1 for bare metal. Rarely in between
Roughness roughness (0–1), roughness_texture 0 is a mirror-like gloss, 1 fully matte
Normal Map normal_enabled, normal_texture fake surface detail; import the texture as a normal map
Emission emission_enabled, emission, emission_energy_multiplier self-lit surfaces (screens, lava). With Glow in the environment, they bloom
Transparency transparency DISABLED, ALPHA (sorted, more expensive), ALPHA_SCISSOR (cut-outs such as leaves), ALPHA_HASH, ALPHA_DEPTH_PRE_PASS
Shading shading_mode PER_PIXEL (default) or UNSHADED (ignores lights; UI-like or stylised)
ORM ORMMaterial3D a sibling class that reads occlusion, roughness and metallic from one packed texture

Glossy, well-lit results need reflections to reflect something: a sky or a ReflectionProbe. A metallic sphere in an empty black world looks black.

Materials are shared resources

Materials are resources: assigning the same material to two meshes shares one object. Changing it from code changes every mesh that uses it. That is efficient (one material, fewer state changes for the renderer) and a classic surprise:

gdscript · try it yourself
extends Node3D

# frames: 0
func _ready():
	var mat := StandardMaterial3D.new()
	mat.albedo_color = Color("3a7bd5")
	mat.roughness = 0.4
	var mesh := BoxMesh.new()
	var a := MeshInstance3D.new()
	a.name = "CrateA"
	a.mesh = mesh
	a.material_override = mat
	var b := MeshInstance3D.new()
	b.name = "CrateB"
	b.mesh = mesh
	b.material_override = mat
	add_child(a)
	add_child(b)
	# Flash crate A red ... but both crates share one material
	a.material_override.albedo_color = Color.RED
	print("B is now ", b.material_override.albedo_color.to_html(false))
	# Fix: give A its own copy
	a.material_override = mat.duplicate()
	a.material_override.albedo_color = Color.WHITE
	print("A ", a.material_override.albedo_color.to_html(false), ", B ", b.material_override.albedo_color.to_html(false))
	var glass := StandardMaterial3D.new()
	glass.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
	glass.albedo_color = Color(0.6, 0.8, 1.0, 0.3)
	glass.emission_enabled = true
	glass.emission = Color.CYAN
	print("glass alpha ", snappedf(glass.albedo_color.a, 0.01), ", transparency mode ", glass.transparency)
B is now ff0000
A ffffff, B ff0000
glass alpha 0.3, transparency mode 1

Three ways to give one object a different look:

  1. material.duplicate() (as above), or tick Local to Scene on the material so each instanced scene gets its own copy. Each copy costs a little memory and breaks batching.
  2. Per-instance shader uniforms (instance uniform vec4 tint; in a shader, then set_instance_shader_parameter("tint", Color.RED)): one material, different values per object. Best for many objects.
  3. The material slots: MeshInstance3D.material_override (whole mesh), set_surface_override_material(i, m) (one surface), material_overlay (a second pass on top, e.g. a hit flash or outline), and the material stored in the mesh itself. Override beats surface override beats the mesh's own material.

Lights

Node Like Notes
DirectionalLight3D the sun position doesn't matter, only rotation. Shadows use cascaded shadow maps (directional_shadow_mode, directional_shadow_max_distance)
OmniLight3D a bulb omni_range, omni_attenuation
SpotLight3D a torch spot_range, spot_angle

Turn on shadow_enabled only for lights that need it; shadows are one of the biggest costs in a 3D frame. Lights also have light_bake_mode (Disabled, Static, Dynamic) which tells the GI systems below whether to include them.

The WorldEnvironment node holds an Environment resource: background and sky, ambient light, tonemapping (Filmic, ACES, AgX in recent versions), glow, fog and volumetric fog, SSAO, SSR, SSIL, and the switch for SDFGI. A new 3D scene in the editor shows a preview sun and environment; click Add Sun to Scene and Add Environment to Scene in the toolbar's preview menu so they exist in the game too.

Global illumination: which one?

Direct light alone looks flat: real light bounces. Godot 4 offers several global illumination (GI) techniques:

Technique How it works Dynamic objects/lights Cost Renderer
SDFGI builds a signed-distance-field version of the scene around the camera at runtime; one checkbox in Environment lights can move; geometry should mostly be static medium-high Forward+ only
VoxelGI a VoxelGI node bakes the geometry inside its box to voxels; press Bake lights can move, objects receive GI medium Forward+ only
LightmapGI bakes light into textures in the editor; meshes need UV2 (enable Light Baking in the import settings) static only; dynamic objects use probes cheapest at runtime, slow bake all renderers, the choice for Mobile and Compatibility
ReflectionProbe captures reflections (and optionally ambient) in a box updates once or always low-medium all

Rules of thumb: large open outdoor worlds → SDFGI; indoor rooms on desktop → VoxelGI or LightmapGI; mobile, web and low-end hardware → LightmapGI plus probes, or no GI and a good ambient colour. Recent 4.x versions keep improving GI; check the "Introduction to global illumination" page of the docs for your exact version.

Setting up a lit test scene (editor)

  1. Create a 3D scene with a Node3D root. Add a MeshInstance3D, set its Mesh to a new PlaneMesh (size 20×20) for the floor and another with a SphereMesh.
  2. Select the sphere, open Surface Material Override > 0, choose New StandardMaterial3D, then set Metallic 1, Roughness 0.2.
  3. In the 3D viewport toolbar, open the three-dots menu next to the preview sun/environment buttons and click Add Sun to Scene and Add Environment to Scene.
  4. Select the new WorldEnvironment, open its Environment, and enable SDFGI and Glow. Rotate the DirectionalLight3D to see the bounce light change.
  5. Press F6 (Run Current Scene).

The same material written as a .tres file:

ini
[gd_resource type="StandardMaterial3D" format=3]

[resource]
albedo_color = Color(0.85, 0.3, 0.2, 1)
metallic = 1.0
roughness = 0.2
emission_enabled = true
emission = Color(1, 0.4, 0.1, 1)
emission_energy_multiplier = 0.5

Test yourself

You change albedo_color on one crate's material from code and every crate turns red. Why?

  1. A rendering bug
  2. All crates share the same material resource; duplicate it or make it Local to Scene
  3. albedo_color is a global setting
  4. MeshInstance3D can only hold one colour

Which GI technique works on the Mobile and Compatibility renderers?

  1. SDFGI
  2. VoxelGI
  3. LightmapGI (baked)
  4. None

A metal sphere with metallic = 1 looks almost black. What is most likely missing?

  1. A normal map
  2. Something to reflect: a sky in the Environment or a ReflectionProbe
  3. Higher roughness
  4. Shadows