Shader Masking viewport with mouse position

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 :sweat_smile:

What is the error you get?

It keeps telling me that set_shader_param is a nonexistent function in base ShaderMaterial

I’m calling this from a SubViewportContainer gd script

Ah yes it has been renamed to the more verbose set_shader_parameter

1 Like

I can’t believe all my struggling has all been because they changed a function name and no where in the online tutorials I looked at mentioned the change -_- super frustrating that they wouldn’t put a note in the editor when you try to call it.
Thanks so much for letting me know :partying_face:

1 Like

You’re watching a tutorial for Godot3, a lot of things have changed from 3 to 4. In genberal when you watch tutorials, you should double check the version of the engine they’re in.

The way i spotted it was the export keyword: in Godot 4, it’s @export

1 Like