Referring to the Shader of Material Overlay of GeometryInstance3D of MeshInstance3D

Godot Version

4.3

Question

How to refer to the Shader of Material Overlay of GeometryInstance3D of MeshInstance3D in gdscript? My .gdshader has some parameters and it is being used in the Material Overlay of the aforementioned GeometryInstance3D. I would like to refer to it. How to do that?

func get_shater_resource(This : MeshInstance3D) -> ShaderMaterial:
	var Mat : Material = This.get_active_material() # or get_surface_override_material() if its an ovveride
	if Mat is ShaderMaterial:
		return Mat
	else:
		print("woops, that material wasnt a shader")
		return null
	

you can use ShaderMaterial.set_shader_parameter(name, value) if you want to set the paramter in code. if you wanted to return the parameters or get the actual shader file itself, you can return ShaderMaterial.shader (as long as the return type is correct) and call get_shader_uniform_list() and it will return you some values you can use

@h3lly3r I am looking for the Material Overlay. I don’t think those functions refer to Material Overlay?

ah, sorry for the misunderstanding. Material overlay is a property of geometryinstance3d, which your meshinstance3d inherits from, so you can use:

func get_material_overlay(This : Meshinstance3D) -> ShaderMaterial:
	var Overlay : Material = This.material_overlay
	if Overlay is ShaderMaterial:
		return Overlay
	else:
		return null

and you can use the same shadermaterial properties and methods on that

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.