Add shaders
This commit is contained in:
parent
f27a3c9b6f
commit
191200a21c
6 changed files with 244 additions and 0 deletions
9
shaders/shaderMaterial_Outline.tres
Normal file
9
shaders/shaderMaterial_Outline.tres
Normal file
|
@ -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
|
43
shaders/shader_color_replacer.gdshader
Normal file
43
shaders/shader_color_replacer.gdshader
Normal file
|
@ -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;
|
||||||
|
}
|
53
shaders/shader_outline.gdshader
Normal file
53
shaders/shader_outline.gdshader
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
22
shaders/shader_outline2.gdshader
Normal file
22
shaders/shader_outline2.gdshader
Normal file
|
@ -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);
|
||||||
|
}
|
69
shaders/shader_outline3.gdshader
Normal file
69
shaders/shader_outline3.gdshader
Normal file
|
@ -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<ring_count;++i){
|
||||||
|
float r = float(i) / float(ring_count) + ring_offset;
|
||||||
|
alpha = max(alpha,texture(TEXTURE, uv + o + size * square(r) * vec2(aspect_ratio,1.0)).a * outline_color.a);}// texture sampling fix is disabled because both with and without give the same result
|
||||||
|
}else{
|
||||||
|
for(int i=0;i<ring_count;++i){
|
||||||
|
float r = float(i) * 3.14159 / float(ring_count) * 2.0 + ring_offset;
|
||||||
|
if (max_or_add){
|
||||||
|
alpha = alpha+tex(TEXTURE, uv + o + vec2(size.x * sin(r) * aspect_ratio, size.y * cos(r))).a * outline_color.a;
|
||||||
|
}else{
|
||||||
|
alpha = max(alpha,tex(TEXTURE, uv + o + vec2(size.x * sin(r) * aspect_ratio, size.y * cos(r))).a * outline_color.a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vec3 final_color = mix(outline_color.rgb, sprite_color.rgb, sprite_color.a);
|
||||||
|
COLOR = vec4(final_color, clamp(alpha, 0.0, 1.0));
|
||||||
|
}
|
48
shaders/shaders_glitch.gdshader
Normal file
48
shaders/shaders_glitch.gdshader
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
Glitch Effect Shader by Yui Kinomoto @arlez80
|
||||||
|
|
||||||
|
MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
shader_type canvas_item;
|
||||||
|
|
||||||
|
uniform float shake_power = 0.03;
|
||||||
|
uniform float shake_rate : hint_range( 0.0, 1.0 ) = 0.2;
|
||||||
|
uniform float shake_speed = 5.0;
|
||||||
|
uniform float shake_block_size = 30.5;
|
||||||
|
uniform float shake_color_rate : hint_range( 0.0, 1.0 ) = 0.01;
|
||||||
|
uniform sampler2D screen_texture : hint_screen_texture;
|
||||||
|
|
||||||
|
float random( float seed )
|
||||||
|
{
|
||||||
|
return fract( 543.2543 * sin( dot( vec2( seed, seed ), vec2( 3525.46, -54.3415 ) ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void fragment( )
|
||||||
|
{
|
||||||
|
float enable_shift = float(
|
||||||
|
random( trunc( TIME * shake_speed ) )
|
||||||
|
< shake_rate
|
||||||
|
);
|
||||||
|
|
||||||
|
vec2 fixed_uv = SCREEN_UV;
|
||||||
|
fixed_uv.x += (
|
||||||
|
random(
|
||||||
|
( trunc( SCREEN_UV.y * shake_block_size ) / shake_block_size )
|
||||||
|
+ TIME
|
||||||
|
) - 0.5
|
||||||
|
) * shake_power * enable_shift;
|
||||||
|
|
||||||
|
vec4 pixel_color = textureLod( screen_texture, fixed_uv, 0.0 );
|
||||||
|
pixel_color.r = mix(
|
||||||
|
pixel_color.r
|
||||||
|
, textureLod( screen_texture, fixed_uv + vec2( shake_color_rate, 0.0 ), 0.0 ).r
|
||||||
|
, enable_shift
|
||||||
|
);
|
||||||
|
pixel_color.b = mix(
|
||||||
|
pixel_color.b
|
||||||
|
, textureLod( screen_texture, fixed_uv + vec2( -shake_color_rate, 0.0 ), 0.0 ).b
|
||||||
|
, enable_shift
|
||||||
|
);
|
||||||
|
COLOR = pixel_color;
|
||||||
|
}
|
Loading…
Reference in a new issue