Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shader_type canvas_item;
- render_mode unshaded;
- // translated to Godot shader language and improved for readability
- // useful params moved to uniforms
- // based on https://www.shadertoy.com/view/XlGfRz
- uniform float M_PI = 3.1415926535897932384626433832795;
- uniform float cell_size = 35.523;
- uniform float wave_radius = 69.420;
- uniform vec2 moving_speed = vec2(0, -10);
- uniform float wave_speed = 1;
- uniform float sparse = 2.9;
- float wave(vec2 pixel, float t) {
- float rad_squared = wave_radius*wave_radius;
- vec2 delta = pixel;
- float delta_squared = delta.x*delta.x + delta.y*delta.y;
- float val = M_PI/2.0*delta_squared/rad_squared + t/2.;
- return pow(sin(val + cos(pixel.y)), sparse);
- }
- // hex bullshit, pls ignore [1]
- vec3 axial_to_cube(vec2 hex) {
- float x = hex.x;
- float z = hex.y;
- float y = -x-z;
- return vec3(x,y,z);
- }
- vec2 cube_to_axial(vec3 cube) {
- return vec2(cube.x, cube.z);
- }
- vec3 cube_round(vec3 cube) {
- float rx = round(cube.x);
- float ry = round(cube.y);
- float rz = round(cube.z);
- float x_diff = abs(rx - cube.x);
- float y_diff = abs(ry - cube.y);
- float z_diff = abs(rz - cube.z);
- if (x_diff > y_diff && x_diff > z_diff)
- rx = -ry-rz;
- else if (y_diff > z_diff)
- ry = -rx-rz;
- else
- rz = -rx-ry;
- return vec3(rx, ry, rz);
- }
- vec2 hex_round(vec2 hex) {
- return cube_to_axial(cube_round(axial_to_cube(hex)));
- }
- vec2 pixel_to_axial(vec2 pixel, float size) {
- float q = (2./3. * pixel.x) / size;
- float r = (-1./3. * pixel.x + sqrt(3.)/3. * pixel.y) / size;
- return vec2(q,r);
- }
- vec2 axial_to_pixel(vec2 hex, float size) {
- float x = size * 3./2. * hex.x;
- float y = size * (sqrt(3.)/2. * hex.x + sqrt(3.) * hex.y);
- return vec2(x,y);
- }
- vec2 hex_center(vec2 pixel, float size) {
- vec2 center = axial_to_pixel(hex_round(pixel_to_axial(pixel, size)), size);
- return center;
- }
- void fragment()
- {
- vec2 pixel_size = SCREEN_PIXEL_SIZE;
- vec2 pixel = FRAGCOORD.xy;
- pixel += TIME * moving_speed;
- vec2 center = hex_center(pixel, cell_size);
- float wave_value = wave(center, TIME * wave_speed);
- COLOR = vec4(vec3(wave_value), wave_value);
- if (length(center - pixel) > wave_value/0.02) {
- discard;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement