+12

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 : https://github.com/Beebster-UK/Godot-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 );
}
Tags
light, torch, vignette
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.
guest
6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
c-macn
c-macn
2 months ago

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

Last edited 2 months ago by c-macn
calman
calman
1 month ago

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

Beebster
Beebster
1 month ago
Reply to  calman

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.

Beebster
Beebster
1 month ago
Reply to  calman
calman
calman
1 month ago
Reply to  Beebster

thank you very much!