From ba882ab8d469bd3afd58602a7cf9d3a765b0ffee Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 10 Feb 2024 03:53:57 +0100 Subject: [PATCH] Experiment with creating a glow shader --- main.tscn | 23 ++++++++++++++++++++++- shaders/postprocess.gdshader | 14 ++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 shaders/postprocess.gdshader diff --git a/main.tscn b/main.tscn index 163dd3a..d173f11 100644 --- a/main.tscn +++ b/main.tscn @@ -1,3 +1,24 @@ -[gd_scene format=3 uid="uid://b8f5t76nfdu5h"] +[gd_scene load_steps=5 format=3 uid="uid://b8f5t76nfdu5h"] + +[ext_resource type="Texture2D" uid="uid://bxyy3bwt7a5l2" path="res://sprites/circle.svg" id="1_70edj"] +[ext_resource type="Shader" path="res://shaders/postprocess.gdshader" id="1_gpsy1"] +[ext_resource type="Texture2D" uid="uid://dvr4j6164rphg" path="res://sprites/square.svg" id="2_xiv3x"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_rnibu"] +shader = ExtResource("1_gpsy1") +shader_parameter/radius = 16 [node name="Main" type="Node"] + +[node name="Circle" type="Sprite2D" parent="."] +modulate = Color(1, 1, 1, 0.498039) +texture_filter = 2 +position = Vector2(68, 44) +texture = ExtResource("1_70edj") + +[node name="Square" type="Sprite2D" parent="."] +material = SubResource("ShaderMaterial_rnibu") +scale = Vector2(72, 40) +texture = ExtResource("2_xiv3x") +centered = false +metadata/_edit_lock_ = true diff --git a/shaders/postprocess.gdshader b/shaders/postprocess.gdshader new file mode 100644 index 0000000..231b2fe --- /dev/null +++ b/shaders/postprocess.gdshader @@ -0,0 +1,14 @@ +shader_type canvas_item; + +uniform sampler2D screen: hint_screen_texture, repeat_disable, filter_nearest; +uniform int radius = 16; + +void fragment() { + float u = SCREEN_UV.x; + float v = SCREEN_UV.y; + + COLOR.rgb = texture(screen, vec2(u, v)).rgb; + + // This is affected by editor zoom! + COLOR.r += texture(screen, vec2(u + (SCREEN_PIXEL_SIZE.x * 4.0), v + (SCREEN_PIXEL_SIZE.y * 4.0))).r; +}