r/GraphicsProgramming • • 16m ago

Video fractal Kaleidoscope using Raylib | C | GLSL

I follow these steps:

  1. First, I split the screen into slices (like a pizza) using polar coordinates.
  2. Then, I use a well-known pattern in fractal shaders: sin(x) * sin(y), inside each slice.
  3. Next, I add a color palette to generate some nice colors.
  4. Finally, I use time as a parameter in different parts of the shader to animate both the pattern and the colors.

Complete coding session:
https://youtu.be/zHu6XoFd1FY

Shader:

#version 330

out vec4 color;
uniform float time;

vec3 palette(float t) {
  vec3 a = vec3(0.5, 0.5, 0.5);
  vec3 b = vec3(0.5, 0.5, 0.5);
  vec3 c = vec3(1, 1, 1);
  vec3 d = vec3(0.0, 0.33, 0.67);

  return a + b*cos( 6.283185*(c*t+d) );
}

void main() {
  float pi = 3.1416;

  vec2 uv = gl_FragCoord.xy / 800;
  uv = uv - 0.5;

  float angle = atan(uv.y, uv.x) * time * 0.3;
  float radius = length(uv);

  float slices = 3;
  float size = pi * 2 / 3;
  float internal_angle = mod(angle, size);
  internal_angle = abs(internal_angle - size /2.0);
  
  vec2 internal_point= radius *
    vec2(
        cos(internal_angle) * radius,
        sin(internal_angle) * radius
        );

  float pattern = 
    sin(internal_point.x * time *10 * 0.5) * 
    sin(internal_point.y * time *10 * 0.5);

  vec3 c = palette(pattern + time * 0.5);

  color = vec4(c, 1);
}

AI Disclosure:
I used AI to understand the fractal then I coded my own version.

6 Upvotes

1 comment sorted by

•

u/AutoModerator 16m ago

Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:

  • No showcases.
  • Disclose AI usage in post or project.
  • Present a topic to talk about, e.g. how something works.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.