From 191200a21c9f865e3fd8abfff3e06729b9edc869 Mon Sep 17 00:00:00 2001 From: LUCASTUCIOUS Date: Tue, 23 Jul 2024 22:31:13 +0200 Subject: [PATCH] Add shaders --- shaders/shaderMaterial_Outline.tres | 9 ++++ shaders/shader_color_replacer.gdshader | 43 ++++++++++++++++ shaders/shader_outline.gdshader | 53 ++++++++++++++++++++ shaders/shader_outline2.gdshader | 22 ++++++++ shaders/shader_outline3.gdshader | 69 ++++++++++++++++++++++++++ shaders/shaders_glitch.gdshader | 48 ++++++++++++++++++ 6 files changed, 244 insertions(+) create mode 100644 shaders/shaderMaterial_Outline.tres create mode 100644 shaders/shader_color_replacer.gdshader create mode 100644 shaders/shader_outline.gdshader create mode 100644 shaders/shader_outline2.gdshader create mode 100644 shaders/shader_outline3.gdshader create mode 100644 shaders/shaders_glitch.gdshader diff --git a/shaders/shaderMaterial_Outline.tres b/shaders/shaderMaterial_Outline.tres new file mode 100644 index 0000000..8b9bb8b --- /dev/null +++ b/shaders/shaderMaterial_Outline.tres @@ -0,0 +1,9 @@ +[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://d311puikrpgel"] + +[ext_resource type="Shader" path="res://shaders/shader_outline.gdshader" id="1_mifsx"] + +[resource] +shader = ExtResource("1_mifsx") +shader_parameter/line_color = Color(1, 1, 1, 1) +shader_parameter/line_thickness = 10.0 +shader_parameter/add_margins = true diff --git a/shaders/shader_color_replacer.gdshader b/shaders/shader_color_replacer.gdshader new file mode 100644 index 0000000..17cca8d --- /dev/null +++ b/shaders/shader_color_replacer.gdshader @@ -0,0 +1,43 @@ +shader_type canvas_item; + +//Hat +uniform vec4 hat_color : source_color; +uniform vec4 hat_replace_color : source_color; +uniform float hat_color_threshold : hint_range(0.0, 1.0, 0.001); + +//Hair +uniform vec4 hair_color : source_color; +uniform vec4 hair_replace_color : source_color; +uniform float hair_color_threshold : hint_range(0.0, 1.0, 0.001); + +//Skin +uniform vec4 skin_color : source_color; +uniform vec4 skin_replace_color : source_color; +uniform float skin_color_threshold : hint_range(0.0, 1.0, 0.001); + +//Clothes +uniform vec4 clothes_color : source_color; +uniform vec4 clothes_replace_color : source_color; +uniform float clothes_color_threshold : hint_range(0.0, 1.0, 0.001); + +void fragment() { + // Called for every pixel the material is visible on. + vec4 tex_color = texture(TEXTURE, UV); + + float hat_distance = length(tex_color.rgb - hat_color.rgb); + float hair_distance = length(tex_color.rgb - hair_color.rgb); + float skin_distance = length(tex_color.rgb - skin_color.rgb); + float clothes_distance = length(tex_color.rgb - clothes_color.rgb); + + if(hat_distance < hat_color_threshold){ + tex_color = hat_replace_color; + }else if(hair_distance < hair_color_threshold){ + tex_color = hair_replace_color; + }else if(skin_distance < skin_color_threshold){ + tex_color = skin_replace_color; + }else if(clothes_distance < clothes_color_threshold){ + tex_color = clothes_replace_color; + } + + COLOR = tex_color; +} \ No newline at end of file diff --git a/shaders/shader_outline.gdshader b/shaders/shader_outline.gdshader new file mode 100644 index 0000000..5372eca --- /dev/null +++ b/shaders/shader_outline.gdshader @@ -0,0 +1,53 @@ +shader_type canvas_item; + +uniform vec4 line_color : source_color = vec4(1); +uniform float line_thickness : hint_range(0, 20) = 0.0; +uniform bool add_margins = true; + +void vertex() { + if (add_margins) { + VERTEX += (UV * 2.0 - 1.0) * line_thickness; + } +} + +void fragment() { + vec2 uv = UV; + + if (add_margins) { + vec2 texture_pixel_size = vec2(1.0) / (vec2(1.0) / TEXTURE_PIXEL_SIZE + vec2(line_thickness * 2.0)); + + uv = (uv - texture_pixel_size * line_thickness) * TEXTURE_PIXEL_SIZE / texture_pixel_size; + + if (uv != clamp(uv, vec2(0.0), vec2(1.0))) { + COLOR.a = 0.0; + } else { + COLOR = texture(TEXTURE, uv); + } + } else { + COLOR = texture(TEXTURE, uv); + } + + vec2 size = TEXTURE_PIXEL_SIZE * line_thickness; + + if (line_thickness < 0.1) { + vec4 color = texture(TEXTURE, uv); + COLOR = color; + } else { + float outline = texture(TEXTURE, uv + vec2(-size.x, 0)).a; + outline += texture(TEXTURE, uv + vec2(0, size.y)).a; + outline += texture(TEXTURE, uv + vec2(size.x, 0)).a; + outline += texture(TEXTURE, uv + vec2(0, -size.y)).a; + outline += texture(TEXTURE, uv + vec2(-size.x * 0.866, size.y * 0.5)).a; + outline += texture(TEXTURE, uv + vec2(-size.x * 0.5, size.y * 0.866)).a; + outline += texture(TEXTURE, uv + vec2(size.x * 0.866, size.y * 0.5)).a; + outline += texture(TEXTURE, uv + vec2(size.x * 0.5, size.y * 0.866)).a; + outline += texture(TEXTURE, uv + vec2(-size.x * 0.866, -size.y * 0.5)).a; + outline += texture(TEXTURE, uv + vec2(-size.x * 0.5, -size.y * 0.866)).a; + outline += texture(TEXTURE, uv + vec2(size.x * 0.866, -size.y * 0.5)).a; + outline += texture(TEXTURE, uv + vec2(size.x * 0.5, -size.y * 0.866)).a; + outline = min(outline, 1.0); + + vec4 color = texture(TEXTURE, uv); + COLOR = mix(color, line_color, outline - color.a); + } +} \ No newline at end of file diff --git a/shaders/shader_outline2.gdshader b/shaders/shader_outline2.gdshader new file mode 100644 index 0000000..303826a --- /dev/null +++ b/shaders/shader_outline2.gdshader @@ -0,0 +1,22 @@ +shader_type canvas_item; + +uniform vec4 line_color : source_color = vec4(1.0); +uniform float line_thickness : hint_range(0, 10) = 1.0; + +const vec2 OFFSETS[8] = { + vec2(-1, -1), vec2(-1, 0), vec2(-1, 1), vec2(0, -1), vec2(0, 1), + vec2(1, -1), vec2(1, 0), vec2(1, 1) +}; + +void fragment() { + vec2 size = TEXTURE_PIXEL_SIZE * line_thickness; + float outline = 0.0; + + for (int i = 0; i < OFFSETS.length(); i++) { + outline += texture(TEXTURE, UV + size * OFFSETS[i]).a; + } + outline = min(outline, 1.0); + + vec4 color = texture(TEXTURE, UV); + COLOR = mix(color, line_color, outline - color.a); +} \ No newline at end of file diff --git a/shaders/shader_outline3.gdshader b/shaders/shader_outline3.gdshader new file mode 100644 index 0000000..d8ac7b9 --- /dev/null +++ b/shaders/shader_outline3.gdshader @@ -0,0 +1,69 @@ +shader_type canvas_item; +render_mode unshaded; + +uniform float thickness : hint_range(0.0, 100.0); +uniform int ring_count : hint_range(1,128) = 16; +uniform float ring_offset : hint_range(0.0, 1.0, 0.01); +uniform vec4 outline_color : source_color; +uniform bool border_clipping_fix = true; +uniform float aspect_ratio : hint_range(0.1, 10.0, 0.01) = 1.0; +uniform bool square_border = false; +uniform vec2 offset; +uniform bool max_or_add = false; + +void vertex(){ + if (border_clipping_fix){ + vec2 o = (UV * 2.0 - 1.0); + VERTEX += o * thickness - offset; + VERTEX.x *= 1.0 + (aspect_ratio-1.0) * (thickness * TEXTURE_PIXEL_SIZE.x) * 2.0; + } +} + +vec2 square(float i){ // samples a square pattern + i *= 2.0; + return (vec2( + clamp(abs(mod(i,2.0)-1.0),0.25,0.75), + clamp(abs(mod(i+0.5,2.0)-1.0),0.25,0.75) + )-0.5)*4.0; +} + +vec4 tex(sampler2D sampler, vec2 uv){ + vec4 clr; + if (uv.x > 0.0 && uv.y > 0.0 && uv.x < 1.0 && uv.y < 1.0){ // bleeding texture sampling fix + clr = texture(sampler, uv); + }else{clr = vec4(0.0);} + return clr; +} + +void fragment(){ + vec2 o = offset / vec2(textureSize(TEXTURE, 0)); + vec2 uv = UV; + uv -= vec2(0.5); + if (border_clipping_fix){ + uv.x *= 1.0 + (aspect_ratio-1.0) * thickness * TEXTURE_PIXEL_SIZE.x * 2.0; + uv *= (1.0 + (thickness * TEXTURE_PIXEL_SIZE * 2.0)); + uv -= o; + } + uv += vec2(0.5); + vec2 size = vec2(thickness) / vec2(textureSize(TEXTURE, 0)); + + vec4 sprite_color = tex(TEXTURE, uv); + + float alpha = sprite_color.a; + if (square_border){ + for(int i=0;i