please make a shadertoy shader that displays a red spiral that slow forms at the cursors…
- User
please make a shadertoy shader that displays a red spiral that slow forms at the cursors position every 5 seconds
Assistant
// Shadertoy shader: Red Spiral Forming Every 5 Seconds at Cursor Position void mainImage(out vec4 fragColor, in vec2 fragCoord) { const float PI = 3.141592653589793; float phase = mod(iTime, 5.0); // Time within 5-second intervals // Normalize coordinates for consistent scaling vec2 res = iResolution.xy; vec2 uv = (fragCoord.xy - 0.5 * res.xy) / res.y; vec2 mouse = (iMouse.xy - 0.5 * res.xy) / res.y; vec2 coords = uv - mouse; // Calculate polar coordinates float r = length(coords); float theta = atan(coords.y, coords.x); if (theta < 0.0) theta += 2.0 * PI; // Ensure theta is in [0, 2PI) // Parameters for spiral formation float k = 0.15; // Controls spiral tightness float thickness = 0.05; // Thickness of spiral line float speedR = 0.2; // Expansion speed float rMax = speedR * phase; // Compute spiral mask (where theta ≈ r/k) float spiral_diff = abs(theta - r / k); float spiral_mask = 1.0 - smoothstep(0.0, thickness, spiral_diff); // Compute radial mask (only show spiral up to current rMax) float r_mask = smoothstep(rMax, rMax - 0.03, r); // Final alpha value float alpha = spiral_mask * r_mask; // Output red spiral color fragColor = vec4(alpha, 0.0, 0.0, 1.0); }
Explanation
This shader displays a red spiral that forms every 5 seconds at the current cursor position. Here's how it works:
1. Coordinate System Setup
uvandmouseare normalized to a coordinate system centered at the screen's middle, ensuring consistent behavior across resolutions.- The spiral originates from
mouse, which is the current position of the cursor.
2. Spiral Formation Logic
- Polar Coordinates: For each pixel, we calculate its distance
rand anglethetafrom the spiral's center (the cursor). - Spiral Equation: The spiral is defined by the relationship
r = k * theta. This creates an Archimedean spiral where the distance between successive turns is constant. - Time-Based Growth: The spiral grows outward as time increases. The maximum radius at any given moment is
rMax = speedR * phase, wherephase = iTime % 5.0. This causes the spiral to reset and begin forming again every 5 seconds.
3. Masking the Spiral
- Spiral Mask: We compute how close a pixel is to the spiral path using
abs(theta - r / k). If this value is below a threshold (thickness), the pixel is part of the spiral. - Radial Mask: We also limit the spiral to only appear within the current
rMax, so it appears to be forming over time.
4. Color Output
- The final color is red (
vec4(alpha, 0.0, 0.0, 1.0)) with an alpha value that depends on whether the pixel lies on the spiral path and within the expanding radius.
Visual Behavior
- Every 5 seconds, the spiral resets and begins forming again from the center at the current cursor position.
- The spiral expands outward in a smooth, continuous manner.
- The spiral is red, thin, and clearly visible due to anti-aliasing via
smoothstep.
Adjustments
You can tweak the following parameters for different effects:
k: Controls the tightness of the spiral (larger = tighter).speedR: Speed of spiral expansion.thickness: Thickness of the spiral line.res: Adjust normalization if needed for different aspect ratios or resolutions.
This shader provides a clean and visually appealing spiral that meets the requirement of forming every 5 seconds at the cursor's position.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.