Last active
December 16, 2024 21:06
-
-
Save partybusiness/989f13eb4b1f97ea250123afcf825303 to your computer and use it in GitHub Desktop.
Scrolling and spinning shader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| shader_type canvas_item; | |
| render_mode unshaded; | |
| uniform sampler2D image:source_color, repeat_enable; | |
| // size you'd like to display image on-screen, in pixels | |
| uniform float tile_size = 200.0; | |
| // speed of rotation in radians per second | |
| uniform float rotation_speed = 1.0; | |
| // speed and direction of scrolling | |
| uniform vec2 scrolling_velocity = vec2(0.6, 0.8); | |
| void fragment() { | |
| vec2 total_uv = SCREEN_UV / SCREEN_PIXEL_SIZE / tile_size + scrolling_velocity * TIME; | |
| // offsets tiles diagonally | |
| total_uv.y += 0.5 * floor(total_uv.x); | |
| // uv of the overall tile, can be used for per-tile modifications | |
| vec2 floored_uv = floor(total_uv); | |
| // UV within an individual tile | |
| vec2 tile_uv = fract(total_uv) - vec2(0.5); | |
| // rotation of individual tiles | |
| float rotation = TIME * rotation_speed + floored_uv.x * 0.8 + floored_uv.y * 0.5; | |
| mat2 rot_mat = mat2(vec2(cos(rotation), sin(rotation)), vec2(-sin(rotation), cos(rotation))); | |
| vec2 uv = rot_mat * tile_uv + vec2(0.5); | |
| COLOR = texture(image, uv); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| shader_type canvas_item; | |
| render_mode unshaded; | |
| uniform sampler2D image:source_color, repeat_enable; | |
| // size you'd like to display image on-screen, in pixels | |
| uniform float tile_size = 200.0; | |
| // speed of rotation in radians per second | |
| uniform float rotation_speed = 1.0; | |
| // speed and direction of scrolling | |
| uniform vec2 scrolling_velocity = vec2(0.6, 0.8); | |
| const float triangle_ratio = 2.0 / sqrt(3.0); | |
| void fragment() { | |
| vec2 total_uv = vec2(triangle_ratio, 1.0) * SCREEN_UV / SCREEN_PIXEL_SIZE / tile_size + scrolling_velocity * TIME; | |
| // offsets tiles diagonally | |
| total_uv.y += 0.5 * floor(total_uv.x); | |
| // uv of the overall tile, can be used for per-tile modifications | |
| vec2 floored_uv = floor(total_uv); | |
| // UV within an individual tile | |
| vec2 tile_uv = fract(total_uv) - vec2(0.5); | |
| // rotation of individual tiles | |
| float rotation = TIME * rotation_speed + floored_uv.x * 0.8 + floored_uv.y * 0.5; | |
| mat2 rot_mat = mat2(vec2(cos(rotation), sin(rotation)), vec2(-sin(rotation), cos(rotation))); | |
| vec2 uv = rot_mat * tile_uv + vec2(0.5); | |
| COLOR = texture(image, uv); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| shader_type canvas_item; | |
| render_mode unshaded; | |
| uniform sampler2D image:source_color, repeat_disable; | |
| // size you'd like to display image on-screen, in pixels | |
| uniform float tile_size = 200.0; | |
| // speed of rotation in radians per second | |
| uniform float rotation_speed = 1.0; | |
| // speed and direction of scrolling | |
| uniform vec2 scrolling_velocity = vec2(0.6, 0.8); | |
| uniform float lr_wipe_threshold:hint_range(0.0, 1.0, 0.01) = 0.5; | |
| uniform float rl_wipe_threshold:hint_range(0.0, 1.0, 0.01) = 0.5; | |
| uniform float wipe_fuzz:hint_range(0.0, 1.0, 0.01) = 0.05; | |
| void fragment() { | |
| vec2 time_offset = scrolling_velocity * TIME; | |
| vec2 total_uv = SCREEN_UV / SCREEN_PIXEL_SIZE / tile_size + time_offset; | |
| // offsets tiles diagonally | |
| total_uv.y += 0.5 * floor(total_uv.x); | |
| // uv of the overall tile, can be used for per-tile modifications | |
| vec2 floored_uv = floor(total_uv); | |
| float wipe_gradient = (floored_uv.x - time_offset.x) * tile_size * SCREEN_PIXEL_SIZE.x; | |
| float lr_wipe_value = smoothstep(wipe_gradient - wipe_fuzz, wipe_gradient + wipe_fuzz, lr_wipe_threshold); | |
| float rl_wipe_value = smoothstep(wipe_gradient + wipe_fuzz, wipe_gradient - wipe_fuzz, rl_wipe_threshold); | |
| float wipe_value = min(lr_wipe_value, rl_wipe_value); | |
| // UV within an individual tile | |
| vec2 tile_uv = (fract(total_uv) - vec2(0.5)) / wipe_value; | |
| // rotation of individual tiles | |
| float rotation = TIME * rotation_speed + floored_uv.x * 0.8 + floored_uv.y * 0.5; | |
| mat2 rot_mat = mat2(vec2(cos(rotation), sin(rotation)), vec2(-sin(rotation), cos(rotation))); | |
| vec2 uv = rot_mat * tile_uv + vec2(0.5); | |
| COLOR = texture(image, uv); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment