Player Vignette
Just supply player position (doesn’t have to be player) and set colour, softness and scale to your tastes.
Here’s a very basic usage example :
Godot 3.x
https://github.com/Beebster-UK/Godot-Player-Vignette-Shader-Example
Godot 4.0+
https://github.com/Beebster-UK/Godot4-Player-Vignette-Shader-Example
Shader code
shader_type canvas_item;
uniform vec2 player_position;
uniform vec4 color : hint_color = vec4(0.305, 0.298, 0.341,1);
uniform float MULTIPLIER = 0.56;
uniform float SCALE = 0.5;
uniform float SOFTNESS = 0.45;
void fragment(){
float val = distance(vec2(UV.x , UV.y * MULTIPLIER), vec2(player_position.x , player_position.y * MULTIPLIER));
val = val / SCALE;
float vignette = smoothstep(0.2, SOFTNESS, val);
COLOR = vec4(color.rgb , vignette );
}
What type of node should this be applied to? I’ve applied it to a kinematic body, camera and sprite but it doesn’t seem to work for me
Simplest is the ‘ColorRect’ node.
this looks fun, thanks! i made a color rect node child of my player for this but how do i supply the player position in the shader? sorry for being a total noob
No problem. I added the color rect node as a child of a canvas node. Then in the player script I feed the shader uniform “player_position” the players current position, bear in mind the you will need to divide the players global position by the viewport dimensions. This gives you values the shaders UV can work with i.e. between 0.0 and 1.0. Hope that helps.
Here’s a very basic example.
https://github.com/Beebster-UK/Godot-Player-Vignette-Shader-Example
thank you very much!
how to define the player position?
https://github.com/Beebster-UK/Godot-Player-Vignette-Shader-Example