Shader discrepancy between viewport and game window

Godot Version

4.3 Beta 1


I have this problem: In the 2D viewport, the sprites are all red. But, when I press play, they turn into the colors I set them to be (blue and green). Is there something wrong or is this normal?

Material resource is set to local.
Shader resource is not set to local

extends Area2D

enum ColorOptions { RED, GREEN, BLUE }
@export var selected_color: ColorOptions

func _ready():
	var shader =
	shader.set_code("res://Shader Test/RGB.gdshader")
	var shaderMaterial =
	shaderMaterial.shader = shader

func ShaderSetter():
	var shaderMaterial = $Sprite2D.material
	match selected_color:
			shaderMaterial.set_shader_parameter("customColor", Vector3(1.0, 0.0, 0.0))
			print("red selected")
			shaderMaterial.set_shader_parameter("customColor", Vector3(0.0, 1.0, 0.0))
			print("green selected")
			shaderMaterial.set_shader_parameter("customColor", Vector3(0.0, 0.0, 1.0))
			print("blue selected")
shader_type canvas_item;
uniform sampler2D existingScreenTexture: hint_screen_texture, filter_linear_mipmap;
uniform vec3 customColor = vec3(0.0, 1.0, 0.0);

void fragment() 
	vec3 newColor = texture(existingScreenTexture, SCREEN_UV).rgb;
	newColor = customColor;
	COLOR.rgb = newColor;

What you need i guess is @ tool:

It is normal that code is not executed in editor until you mark it

in your case:

extends Area2D
1 Like