Add project files

This commit is contained in:
ChaoticByte 2024-09-25 21:18:58 +02:00
commit ab339c8a2c
No known key found for this signature in database
81 changed files with 2567 additions and 0 deletions

10
core/DynamicPolygon.tscn Normal file
View file

@ -0,0 +1,10 @@
[gd_scene load_steps=2 format=3 uid="uid://cbynoofsjcl45"]
[ext_resource type="Script" path="res://core/dynamic_polygon.gd" id="1_2pai0"]
[node name="DynamicPolygon" type="CollisionPolygon2D"]
script = ExtResource("1_2pai0")
update = null
[node name="Polygon2D" type="Polygon2D" parent="."]
color = Color(0, 0, 0, 1)

20
core/dynamic_polygon.gd Normal file
View file

@ -0,0 +1,20 @@
@tool
extends CollisionPolygon2D
@export var color: Color = Color.WHITE:
set(v):
color = v
update_polygon()
get():
return color
@export var update: bool:
set(v):
update_polygon()
func update_polygon():
$Polygon2D.polygon = polygon
$Polygon2D.color = color
func _ready() -> void:
update_polygon()

View file

@ -0,0 +1,41 @@
shader_type canvas_item;
render_mode unshaded;
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_linear_mipmap;
// simple edge detection
bool is_edge(int radius, vec2 screen_uv, vec2 screen_pixel_size) {
bool ed_found_black = false;
bool ed_found_color = false;
// check neighbor pixels
for (int x = -radius; x < radius+1; x++) {
for (int y = -radius; y < radius+1; y++) {
vec4 p = texture(screen_texture, screen_uv + (vec2(float(x), float(y)) * screen_pixel_size));
if (p.rgb == vec3(0.0)) {
ed_found_black = true;
} else {
ed_found_color = true;
}
}
}
return ed_found_black && ed_found_color;
}
void fragment() {
// get screen texture
vec4 screen = texture(screen_texture, SCREEN_UV);
// apply edge detection
int radius = max(int(0.003 * (1.0/SCREEN_PIXEL_SIZE.y)), 1); // with a relative radius
if (is_edge(radius, SCREEN_UV, SCREEN_PIXEL_SIZE)) {
COLOR = screen;
} else {
COLOR = vec4(0, 0, 0, 1);
}
// apply glow
// blur a relative radius -> x * log(1.0/SCREEN_PIXEL_SIZE.y)
// using log, because the LOD value seems to affect the blur radius exponentially
vec4 glow = textureLod(screen_texture, SCREEN_UV, 0.5 * log(1.0/SCREEN_PIXEL_SIZE.y));
if (screen.rgb == vec3(0.0)) {
COLOR = mix(COLOR, glow, 0.4) + (glow * 0.3);
}
}