Advertisement
Zunesha

Shader Glitch Godot 4 (ColorRect)

Sep 11th, 2024
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 1.25 KB | Gaming | 0 0
  1. Shader Glitch  Godot 4 (ColorRect)
  2.  
  3. shader_type canvas_item;
  4.  
  5. uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
  6. // 振動の強さ
  7. uniform float shake_power = 0.03;
  8. // 振動率
  9. uniform float shake_rate : hint_range( 0.0, 1.0 ) = 0.2;
  10. // 振動速度
  11. uniform float shake_speed = 5.0;
  12. // 振動ブロックサイズ
  13. uniform float shake_block_size = 30.5;
  14. // 色の分離率
  15. uniform float shake_color_rate : hint_range( 0.0, 1.0 ) = 0.01;
  16.  
  17. float random( float seed )
  18. {
  19.     return fract( 543.2543 * sin( dot( vec2( seed, seed ), vec2( 3525.46, -54.3415 ) ) ) );
  20. }
  21.  
  22. void fragment( )
  23. {
  24.     float enable_shift = float(
  25.         random( trunc( TIME * shake_speed ) )
  26.     <   shake_rate
  27.     );
  28.  
  29.     vec2 fixed_uv = SCREEN_UV;
  30.     fixed_uv.x += (
  31.         random(
  32.             ( trunc( SCREEN_UV.y * shake_block_size ) / shake_block_size )
  33.         +   TIME
  34.         ) - 0.5
  35.     ) * shake_power * enable_shift;
  36.  
  37.     vec4 pixel_color = textureLod( SCREEN_TEXTURE, fixed_uv, 0.0 );
  38.     pixel_color.r = mix(
  39.         pixel_color.r
  40.     ,   textureLod( SCREEN_TEXTURE, fixed_uv + vec2( shake_color_rate, 0.0 ), 0.0 ).r
  41.     ,   enable_shift
  42.     );
  43.     pixel_color.b = mix(
  44.         pixel_color.b
  45.     ,   textureLod( SCREEN_TEXTURE, fixed_uv + vec2( -shake_color_rate, 0.0 ), 0.0 ).b
  46.     ,   enable_shift
  47.     );
  48.     COLOR = pixel_color;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement