Shader not updating

Godot Version

4.5.1

Question

Essentially I have a ColorRect node that calculates some data and pass it to its shader, everything works, like it’s a recreation of snes mode7 and it works in the editor by setting the values by hand however the shader doesn’t update on runtime

the color rect code is this:

func _calc_frustrum():
	var KartPos = Vector2(Kart.global_position.x, Kart.global_position.y) - Vector2.UP.rotated(Kart.rotation) * 80 
	var KartA = Kart.rotation -PI/2
	
	var FarX1:float = KartPos.x + cos(KartA - FOVHalf) * Far
	var FarY1:float = KartPos.y + sin(KartA - FOVHalf) * Far
	
	var FarX2:float = KartPos.x + cos(KartA + FOVHalf) * Far
	var FarY2:float = KartPos.y + sin(KartA + FOVHalf) * Far
	
	var NearX1:float = KartPos.x + cos(KartA - FOVHalf) * Near
	var NearY1:float = KartPos.y + sin(KartA - FOVHalf) * Near
	
	var NearX2:float = KartPos.x + cos(KartA + FOVHalf) * Near
	var NearY2:float = KartPos.y + sin(KartA + FOVHalf) * Near
	
	Polygon.polygon[0] = Vector2(FarX1, FarY1)
	Polygon.polygon[1] = Vector2(FarX2, FarY2)
	Polygon.polygon[2] = Vector2(NearX2, NearY2)
	Polygon.polygon[3] = Vector2(NearX1, NearY1)
	
	Camera.set_shader_parameter("vFar1", Vector2(FarX1, FarY1)/1024)
	Camera.set_shader_parameter("vFar2", Vector2(FarX2, FarY2)/1024)
	Camera.set_shader_parameter("vNear1", Vector2(NearX1, NearY1)/1024)
	Camera.set_shader_parameter("vNear2", Vector2(NearX2, NearY2)/1024)
	
	await get_tree().process_frame
	
	_calc_frustrum()
	print("Points:")
	print("Far : ", Camera.get_shader_parameter("vFar1")," ", Camera.get_shader_parameter("vFar2"))
	print("Near: ", Camera.get_shader_parameter("vNear1")," ", Camera.get_shader_parameter("vNear2"))

and the prints output logical data, like as I say I take the data out of those prints statements and I put it in the editor and I get sensible things. however on runtime nothing updates

here’s the shader if anyone needs it but as I said the shader works so I would be very surprise if that’s the issue:

shader_type canvas_item;

uniform vec2 vFar1 = vec2(0.0,0.0);
uniform vec2 vFar2 = vec2(0.0,0.0);
uniform vec2 vNear1 = vec2(0.0,0.0);
uniform vec2 vNear2 = vec2(0.0,0.0);


uniform sampler2D source_texture;

void fragment() {
	
	float StartX = (vFar1.x - vNear1.x) / UV.y + vNear1.x;
	float StartY = (vFar1.y - vNear1.y) / UV.y + vNear1.y;
	float EndX = (vFar2.x - vNear2.x) / UV.y + vNear2.x;
	float EndY = (vFar2.y - vNear2.y) / UV.y + vNear2.y;
	
	float SampleX = (EndX - StartX) * UV.x + StartX;
	float SampleY = (EndY - StartY) * UV.x + StartY;
	
	COLOR = texture(source_texture, vec2(SampleX,SampleY));
}

What is your Camera object? Camera2D doesn’t have set_shader_parameter. I think you’re applying the shader on the wrong thing?

Sorry I’m a bit quirky with nomenclature, Camera is the own shader.

idk if it’s the material that has the shader or the shader itself. I should have named it something more descriptive like Renderer or mode7display but i’m on the testing phase so I’m a bit all over the place

edit: it’s the material:

@onready var Camera:ShaderMaterial = self.material

Hmm get_shader_parameter doesn’t read anything back from the shader or GPU, it just returns whatever you last stored with set_shader_parameter

Either the material you’re poking isn’t the one being drawn, or that ColorRect isn’t actually visible at runtime.

Try ignoring your uniforms and output a flat animated color:

  void fragment() {
        COLOR = vec4(fract(TIME), 0.0, 0.0, 1.0);
  }

If that does NOT pulse red → the ColorRect isn’t even on screen at runtime

If it DOES pulse but your real uniforms don’t → name/instance mismatch or something