Zunesha

Shaders com 4 tipos de transições de tela ( Godot 4)

Dec 23rd, 2023 (edited)
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shaders com 4 tipos de transições de tela ( Godot 4)
  2.  
  3. shader_type canvas_item;
  4.  
  5. // Tamanho da tela em pixels — atualize isso no GDScript sempre!
  6. uniform vec2 screen_size = vec2(1280.0, 720.0);
  7.  
  8. // Posição em PIXELS na tela onde o círculo vai fechar (ex: Vector2(880.0, 368.0))
  9. uniform vec2 pixel_target = vec2(960.0, 540.0);  // padrão = centro de 1920x1080
  10.  
  11. uniform vec2 center = vec2(0.5);
  12.  
  13. uniform float progress : hint_range(0.0, 1.0) = 0.0;
  14. uniform float pixel_size : hint_range(1.0, 50.0) = 15.0;
  15. uniform float circle_size : hint_range(0.0, 3.0) = 1.5;
  16. uniform float curtains : hint_range(0.0, 1.0) = 1.0;
  17.  
  18. uniform int type : hint_range(0, 4) = 0;
  19.  
  20. void fragment() {
  21.     // Converte posição em pixels para UV (0-1)
  22.     vec2 target_uv = pixel_target / screen_size;
  23.    
  24.     // Seleciona o centro dependendo do tipo
  25.     vec2 final_target = (type == 1) ? target_uv : center;
  26.    
  27.     // Corrige aspect ratio para círculo perfeito
  28.     vec2 uv = UV - final_target;
  29.     uv.x *= screen_size.x / screen_size.y;  // escala X pelo aspect ratio
  30.    
  31.     float dist = length(uv);
  32.  
  33.     // Tipo 0 - Diamante Pixelado
  34.     if (type == 0) {
  35.         float xFraction = fract(FRAGCOORD.x / pixel_size);
  36.         float yFraction = fract(FRAGCOORD.y / pixel_size);
  37.         float xDistance = abs(xFraction - 0.5);
  38.         float yDistance = abs(yFraction - 0.5);
  39.  
  40.         if (xDistance + yDistance + UV.x + UV.y > progress * 4.0) {
  41.             discard;
  42.         }
  43.     }
  44.     // Tipo 1 - Círculo fechando no ponto (em pixels → UV)
  45.     else if (type == 1 || type == 2) {
  46.         if (dist < circle_size * (1.0 - progress)) {
  47.             COLOR.a = 0.0;
  48.         }
  49.     }
  50.     // Tipo 3 - Cortina Vertical
  51.     else if (type == 3) {
  52.         if (abs(UV.x - 0.5) < curtains * (1.0 - progress) * 0.5) {
  53.             COLOR.a = 0.0;
  54.         }
  55.     }
  56.     // Tipo 4 - Cortina Horizontal
  57.     else if (type == 4) {
  58.         if (abs(UV.y - 0.5) < curtains * (1.0 - progress) * 0.5) {
  59.             COLOR.a = 0.0;
  60.         }
  61.     }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment