#Apply Shader to one player only

1 messages · Page 1 of 1 (latest)

errant forge
#

Well, i want my shader to be applied to just the player that is not the leader of the group, so that way, the player you are not controlling is on B&W color. But it just applies to both players and i don't know what im doing wrong :/

I have a Player class with the node tree shown in the screenshot and this code in the _process() function:

func _process(delta):
# DEBUG
var leader = MainScene.current_player
if !self.is_leader:
debug.text = " --- DEBUG ---\n" + "leader: " + str(self.player_name) + "\n" + "team: " + str(self.team) +" \n" + "can_team: " + str(self.can_team) +" \n" + "distance: " + str(round(self.global_position.distance_to(leader.global_position))) + " <= " + str(distance_between) + " : " + str(self.global_position.distance_to(leader.global_position) <= distance_between)
animacion.material.set_shader_parameter("saturation", 0)
else:
animacion.material.set_shader_parameter("saturation", 1)
debug.text = " --- DEBUG ---\n" + "leader: " + str(leader.player_name) + "\n" + "team: " + str(leader.team) +" \n" + "can_team: " + str(leader.can_team) +" \n" + "distance: " + str(round(MainScene.other_player.global_position.distance_to(leader.global_position))) + " <= " + str(distance_between) + " : " + str(MainScene.other_player.global_position.distance_to(leader.global_position) <= distance_between)

The shader is working fine, its this one i found on Internet:
https://godotshaders.com/shader/color-manipulator/

This is a simple color manipulator, it support brightness, contrast,...

twilit briar
#

Setting a shader parameter will modify the material itself, so if your players all share the same material it will modify all of the players

#

In the case of 2D nodes instanced shader uniforms are not implemented yet so you will have to make a second material you can swap out the normal one with

#

So something like

@export var bw_material : Material
@export var color_material : Material

func _process(delta):
  if not self.is_leader:
    player.material = bw_material
  else:
    player.material = color_material
#

although I would recommend trying not to swap the material in the process function, as that gets called every frame

#

you could make a signal for when is_leader changes or use a setter function for it

errant forge
#

Hi

#

Thanks for the reply

twilit briar
#

lovely

errant forge
#

Hahaha, thank you!

#

Thanks for your help! I put the shader change out of the process too, thanks for the advice

twilit briar
calm spruce
#

put on the solved tag