Godot Version 4.3
Goal: To mask around the mouse all of a viewports contents.
Current Issue: I get an error every time trying to set the “target” shader param
I’m trying to combine two tutorials online:
The shader for the sub viewport container:
shader_type canvas_item;
uniform sampler2D mask;
uniform vec2 target = vec2 (0.5f);
void fragment(){
COLOR = texture(TEXTURE, UV);
float x = SCREEN_PIXEL_SIZE.x / distance(vec2(target.x,UV.y),UV);
float y = SCREEN_PIXEL_SIZE.y / distance (vec2(UV.x,target.y),UV);
COLOR.a = texture(mask,vec2(x,y)).r;
}
The gdscript for the subviewport container:
extends SubViewportContainer
func _process(_delta: float) -> void:
var t = get_viewport().get_mouse_position()
t.x /= get_viewport_rect().size.x
t.y /= get_viewport_rect().size.y
get_material().set_shader_param("target", t)
Please help