Randomize noise seed in a "Material Override"

Godot Version



I would like to randomize a noise seed that is in a material , there is a post on reddit about it, https://www.reddit.com/r/godot/comments/cplmxt/random_seed_generation_on_noise_texture/, but it was 5 years ago…

If you would like any more details, feel free to ask. :grinning:

You will need to get the parameter from the ShaderMaterial with ShaderMaterial.get_shader_parameter() and then access the Noise of the NoiseTexture2D with NoiseTexture2D.noise. You will be able to finally randomize the FastNoiseLite.seed property.

Something like:

var heightmap = material.get_shader_parameter("heightmap") as NoiseTexture2D
var noise = heightmap.noise as FastNoiseLite
noise.seed = randi()

But remember that ShaderMaterial, FastNoiseLite and NoiseTexture2D are Resources. Resources are shared by default. You’ll need to make them unique doing one of the following:

  • Enable Local to Scene in the Resource. This will make unique the resource when instantiating the scene (if the resource is shared between nodes in the same scene the copies won’t be made unique)
  • Calling Resource.duplicate() in code.

Sorry, I might sound dumb.

How to fix:
“Error at (10, 17): Identifier “material” not declared in the current scope.”


You need to get the ShaderMaterial you want to access from your MeshInstance3D or Mesh. It looks like you are using the GeometryInstance3D.material_override property so use that.

Invalid get index ‘material_override’ (on base: ‘GeometryInstance3D’).

GeometryInstance3D.material_override.get_shader_parameter("heightmap") as NoiseTexture2D

Am I doing this right?

extends MeshInstance3D

func _ready():
	var heightmap = material_override.get_shader_parameter("heightmap") as NoiseTexture2D
	var noise = heightmap.noise as FastNoiseLite
	noise.seed = randi()
1 Like

Thanks mate!