Added platform shader
This commit is contained in:
@@ -1,52 +1,7 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
uniform vec4 black_color : source_color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
uniform vec4 white_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
uniform bool switch_colors = false;
|
||||
uniform float threshold : hint_range(0.0, 1.0) = 0.5;
|
||||
uniform float speed : hint_range(0.0, 10.0) = 0.5;
|
||||
uniform float intensity : hint_range(0.0, 1.0) = 1.0;
|
||||
uniform float scale : hint_range(0.0, 100.0) = 20.0;
|
||||
|
||||
vec2 random(vec2 uv){
|
||||
uv = vec2( dot(uv, vec2(127.1,311.7) ),
|
||||
dot(uv, vec2(269.5,183.3) ) );
|
||||
return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123);
|
||||
}
|
||||
|
||||
float noise(vec2 uv) {
|
||||
vec2 uv_index = floor(uv);
|
||||
vec2 uv_fract = fract(uv);
|
||||
|
||||
vec2 blur = smoothstep(0.0, 1.0, uv_fract);
|
||||
|
||||
return mix( mix( dot( random(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ),
|
||||
dot( random(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x),
|
||||
mix( dot( random(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ),
|
||||
dot( random(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) + 0.5;
|
||||
}
|
||||
|
||||
#include "get_black_n_white.gdshaderinc"
|
||||
|
||||
void fragment() {
|
||||
if (COLOR.a > 0.01) {
|
||||
float l = dot(COLOR.rgb, vec3(0.2126, 0.7152, 0.0722));
|
||||
|
||||
bool is_black = l < threshold;
|
||||
if (switch_colors) {
|
||||
is_black = !is_black;
|
||||
}
|
||||
if (intensity < 1.0) {
|
||||
vec2 coord = UV * scale + TIME * speed;
|
||||
if (noise(coord) > intensity) {
|
||||
is_black = !is_black;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_black) {
|
||||
COLOR = black_color;
|
||||
}
|
||||
else {
|
||||
COLOR = white_color;
|
||||
}
|
||||
}
|
||||
COLOR = get_black_and_white(COLOR, UV, TIME);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
uniform vec4 black_color : source_color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
uniform vec4 white_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
uniform bool switch_colors = false;
|
||||
uniform float threshold : hint_range(0.0, 1.0) = 0.5;
|
||||
uniform float speed : hint_range(0.0, 10.0) = 0.5;
|
||||
uniform float intensity : hint_range(0.0, 1.0) = 1.0;
|
||||
uniform float scale : hint_range(0.0, 100.0) = 20.0;
|
||||
|
||||
vec2 random(vec2 uv){
|
||||
uv = vec2( dot(uv, vec2(127.1,311.7) ),
|
||||
dot(uv, vec2(269.5,183.3) ) );
|
||||
return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123);
|
||||
}
|
||||
|
||||
float noise(vec2 uv) {
|
||||
vec2 uv_index = floor(uv);
|
||||
vec2 uv_fract = fract(uv);
|
||||
|
||||
vec2 blur = smoothstep(0.0, 1.0, uv_fract);
|
||||
|
||||
return mix( mix( dot( random(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ),
|
||||
dot( random(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x),
|
||||
mix( dot( random(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ),
|
||||
dot( random(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) + 0.5;
|
||||
}
|
||||
|
||||
vec4 get_black_and_white(vec4 color, vec2 uv, float time) {
|
||||
if (color.a < 0.01) return color;
|
||||
|
||||
float l = dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));
|
||||
|
||||
bool is_black = l < threshold;
|
||||
if (switch_colors) {
|
||||
is_black = !is_black;
|
||||
}
|
||||
if (intensity < 1.0) {
|
||||
vec2 coord = uv * scale + time * speed;
|
||||
if (noise(coord) > intensity) {
|
||||
is_black = !is_black;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_black) {
|
||||
return black_color;
|
||||
}
|
||||
return white_color;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bvklme5ww0g2f
|
||||
@@ -1,10 +1,38 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
|
||||
uniform float tile_size = 8.0;
|
||||
uniform float platform_width = 16.0;
|
||||
uniform float platform_width = 24.0;
|
||||
uniform sampler2D atlas : filter_nearest;
|
||||
uniform float seed : hint_range(0.0, 1.0) = 0.0;
|
||||
|
||||
const float left_cap_count = 2.0;
|
||||
const float gap_count = 8.0;
|
||||
const float right_cap_count = 2.0;
|
||||
|
||||
float random(float v, float s) {
|
||||
return fract(sin(v * 127.1 + s * 100.0) * 43758.5453);
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
|
||||
vec2 platform_pixel = UV * vec2(platform_width, tile_size);
|
||||
vec2 atlas_pixel = platform_pixel;
|
||||
|
||||
float column = floor(platform_pixel.x / tile_size);
|
||||
float rand_val = random(column, seed);
|
||||
float tile_offset_x = mod(platform_pixel.x, tile_size);
|
||||
|
||||
if (platform_pixel.x < tile_size) {
|
||||
float cap_index = floor(rand_val * left_cap_count);
|
||||
atlas_pixel.x = cap_index * tile_size + tile_offset_x;
|
||||
} else if (platform_pixel.x < platform_width - tile_size) {
|
||||
float gap_index = floor(rand_val * gap_count);
|
||||
atlas_pixel.x = left_cap_count * tile_size + gap_index * tile_size + tile_offset_x;
|
||||
} else {
|
||||
float cap_index = floor(rand_val * right_cap_count);
|
||||
atlas_pixel.x = (left_cap_count + gap_count) * tile_size + cap_index * tile_size + tile_offset_x;
|
||||
}
|
||||
|
||||
vec2 atlas_size = vec2(textureSize(atlas, 0));
|
||||
vec2 atlas_uv = atlas_pixel / atlas_size;
|
||||
COLOR = texture(atlas, atlas_uv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user