Switching material is slow
Asked Answered
H

12

0

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?

Hawkweed answered 17/1, 2022 at 1:31 Comment(0)
A
0

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.

Aintab answered 17/1, 2022 at 2:6 Comment(0)
F
0

There's also the multiple material pass system to consider.

Fulvi answered 17/1, 2022 at 3:15 Comment(0)
H
0

@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

Hawkweed answered 17/1, 2022 at 3:19 Comment(0)
H
0

@Megalomaniak said: There's also the multiple material pass system to consider.

What do you mean?

Hawkweed answered 17/1, 2022 at 3:19 Comment(0)
F
0

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.

Fulvi answered 17/1, 2022 at 3:58 Comment(0)
A
0
extends Spatial

func _ready():
	var poles = get_node("World/Poles")
	var pole_mat = poles.get_surface_material(0)
	pole_mat.albedo_color = Color.white
Aintab answered 17/1, 2022 at 4:22 Comment(0)
G
0

In my experience material switching is not very expensive if you can make sure that shader in not recompiled.

Glad answered 17/1, 2022 at 12:0 Comment(0)
H
0

@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?

Hawkweed answered 17/1, 2022 at 14:30 Comment(0)
H
0

@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?

Hawkweed answered 17/1, 2022 at 14:30 Comment(0)
M
0

@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

Muslim answered 17/1, 2022 at 14:58 Comment(0)
G
0

@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.

Glad answered 17/1, 2022 at 14:59 Comment(0)
F
0

@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.

Fulvi answered 17/1, 2022 at 15:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.