Shader discrepancy between viewport and game window

Godot Version

4.3 Beta 1

Question

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.new()
	shader.set_code("res://Shader Test/RGB.gdshader")
	var shaderMaterial = ShaderMaterial.new()
	shaderMaterial.shader = shader
	ShaderSetter()

func ShaderSetter():
	var shaderMaterial = $Sprite2D.material
	match selected_color:
		ColorOptions.RED:
			shaderMaterial.set_shader_parameter("customColor", Vector3(1.0, 0.0, 0.0))
			print("red selected")
		ColorOptions.GREEN:
			shaderMaterial.set_shader_parameter("customColor", Vector3(0.0, 1.0, 0.0))
			print("green selected")
		ColorOptions.BLUE:
			shaderMaterial.set_shader_parameter("customColor", Vector3(0.0, 0.0, 1.0))
			print("blue selected")
	print(selected_color)
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:

@tool
extends Area2D
1 Like