In a VR application, it's common to hilight an object in reach of the user's hand, to let him know that he can iteract with. The way I am doing this right now is by just setting the material like this : mesh.material = material_hilighted
However, when there are lots of objects quickly getting in and out of player's reach, the game basically becomes a slide show. Any way to fix this?
No, you don't want to change materials like this. It will be very slow. Usually you can change parameters and it doesn't need to switch/recompile the shader and that is instant. If you are using a SpatialMaterial, for example, just change the albedo color and that should be enough of feedback and instant.
There's also the multiple material pass system to consider.
@cybereality said: No, you don't want to change materials like this. It will be very slow. Usually you can change parameters and it doesn't need to switch/recompile the shader and that is instant. If you are using a SpatialMaterial, for example, just change the albedo color and that should be enough of feedback and instant.
Thanks
@Megalomaniak said: There's also the multiple material pass system to consider.
What do you mean?
Rather than switching materials have the highlight material as the next pass. Then as cybereality said, just change parameters on the highlight material to make it visible or not.
extends Spatial
func _ready():
var poles = get_node("World/Poles")
var pole_mat = poles.get_surface_material(0)
pole_mat.albedo_color = Color.white
In my experience material switching is not very expensive if you can make sure that shader in not recompiled.
@Megalomaniak said: Rather than switching materials have the highlight material as the next pass. Then as cybereality said, just change parameters on the highlight material to make it visible or not.
How would you make it visible or not? Do you use alpha? or is there another way to make the material turn on and off from within the shader?
@xyz said: In my experience material switching is not very expensive if you can make sure that shader in not recompiled.
How do you make sure a shader doesn't get recompiled?
@pigna said:
@Megalomaniak said: Rather than switching materials have the highlight material as the next pass. Then as cybereality said, just change parameters on the highlight material to make it visible or not.
How would you make it visible or not? Do you use alpha? or is there another way to make the material turn on and off from within the shader?
var material = (your MeshInstance).get_surface_material(0)
material.set("shaderVarName", value)
Hope that helps
@pigna said:
@xyz said: In my experience material switching is not very expensive if you can make sure that shader in not recompiled.
How do you make sure a shader doesn't get recompiled?
Don't duplicate it or create new ones. Disable shader's "local to scene" flag in instanced scenes.
@pigna said:
@Megalomaniak said: Rather than switching materials have the highlight material as the next pass. Then as cybereality said, just change parameters on the highlight material to make it visible or not.
How would you make it visible or not? Do you use alpha? or is there another way to make the material turn on and off from within the shader?
Make the next material pass blend mode add and just change the albedo value between white and black.
© 2022 - 2024 — McMap. All rights reserved.