Skip to reading
GDScript Programming & Godot

44. Materials, shaders, animation and resource sharing

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Code example
func make_material() -> StandardMaterial3D:
    var material := StandardMaterial3D.new()
    material.albedo_color = Color("caa46d")
    material.roughness = 0.2
    material.metallic = 0.8
    return material
Code example
func run() -> float:
    return make_material().metallic

A loaded material/resource can be shared by multiple instances. Duplicate it before a local edit when other objects must keep their original appearance. material_override applies to the whole MeshInstance3D; per-surface overrides target a particular surface.

For ShaderMaterial, use set_shader_parameter with the exact uniform name from the shader. For AnimationPlayer, check has_animation before play; animation_finished is useful for a finite clip. A looping animation does not naturally emit a final completion you can wait for.

PCA can manage actor animation state, lip-sync, glow and materials itself. Direct writes can be overwritten by that system. Choose the PCA route for ordinary actor behavior; reserve direct Godot edits for a feature that owns that portion of the model.

Metallic/low roughness makes a reflective material response. A recognizable live character reflection needs the relevant rendering/reflection system; a material number alone does not construct a mirror camera.

Page 53 of 378Permalink
Go to page