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 );
}
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.

Related shaders

SELECT PLAYER STYLE 80S GAME

Vignette with reduced banding artifacts

pixelated horror vignette dot-matrix downres

Subscribe
Notify of
guest

8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
c-macn
c-macn
3 years 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 3 years ago by c-macn
calman
calman
3 years 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
3 years 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
3 years ago
Reply to  calman
calman
calman
3 years ago
Reply to  Beebster

thank you very much!

ishmam
ishmam
3 years ago

how to define the player position?