Advertisement
dan-masek

Fixed shader for StackOverflow question.

Jul 18th, 2023
2,374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. vec2 rotate_uv(vec2 uv, float rotation) {
  2.     return vec2(
  3.         cos(rotation) * (uv.x) + sin(rotation) * (uv.y),
  4.         cos(rotation) * (uv.y) - sin(rotation) * (uv.x)
  5.     );
  6. }
  7.  
  8. void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  9.     vec2 uv = fragCoord / iResolution.xy;
  10.     vec2 fade_uv = uv;
  11.  
  12.     float time = abs(sin(iTime)) * 36.00 / 36.00;
  13.     float angle = 70.00;
  14.     float angle_1q = mod(angle, 90.0);
  15.     float angle_rad = radians(angle);
  16.     float angle_1q_rad = radians(angle_1q);
  17.  
  18.     float tan_1q_rad = tan(angle_1q_rad);
  19.     float a = tan_1q_rad / (tan_1q_rad + 1.0);
  20.     float scale = sqrt(2.0*a*a - 2.0*a + 1.0);
  21.    
  22.     fade_uv = fade_uv - 0.5;
  23.     fade_uv = rotate_uv(fade_uv, angle_rad);
  24.     fade_uv = fade_uv * scale;
  25.     fade_uv = fade_uv + 0.5;
  26.  
  27.     float alpha = step(
  28.         1.0 - time,
  29.         1.0 - fade_uv.x
  30.     );
  31.  
  32.  
  33.     fragColor.xyz = mix(
  34.         texture(iChannel0, uv).xyz,
  35.         vec3(0.00),
  36.         alpha
  37.    );
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement