The prompt that made it
as published# SHADER ANIMATION — COMPONENT INTEGRATION
USE CATEGORY: "SHADERS"
YOU ARE GIVEN A TASK TO INTEGRATE AN EXISTING REACT COMPONENT IN THE CODEBASE
THE CODEBASE SHOULD SUPPORT:
- SHADCN PROJECT STRUCTURE
- TAILWIND CSS
- TYPESCRIPT
IF IT DOESN'T, PROVIDE INSTRUCTIONS ON HOW TO SETUP PROJECT VIA SHADCN CLI, INSTALL TAILWIND OR TYPESCRIPT.
DETERMINE THE DEFAULT PATH FOR COMPONENTS AND STYLES.
IF DEFAULT PATH FOR COMPONENTS IS NOT /COMPONENTS/UI, PROVIDE INSTRUCTIONS ON WHY IT'S IMPORTANT TO CREATE THIS FOLDER
COPY-PASTE THIS COMPONENT TO /COMPONENTS/UI FOLDER:
```tsx
shader-animation.tsx
"use client"
import { useEffect, useRef } from "react"
import * as THREE from "three"
export function ShaderAnimation() {
const containerRef = useRef<HTMLDivElement>(null)
const sceneRef = useRef<{
camera: THREE.Camera
scene: THREE.Scene
renderer: THREE.WebGLRenderer
uniforms: any
animationId: number
} | null>(null)
useEffect(() => {
if (!containerRef.current) return
const container = containerRef.current
// Vertex shader
const vertexShader = `
void main() {
gl_Position = vec4( position, 1.0 );
}
`
// Fragment shader
const fragmentShader = `
#define TWO_PI 6.2831853072
#define PI 3.14159265359
precision highp float;
uniform vec2 resolution;
uniform float time;
void main(void) {
vec2 uv = (gl_FragCoord.xy * 2.0 - resolution.xy) / min(resolution.x, resolution.y);
float t = time*0.05;
float lineWidth = 0.002;
vec3 color = vec3(0.0);
for(int j = 0; j < 3; j++){
for(int i=0; i < 5; i++){
color[j] += lineWidth*float(i*i) / abs(fract(t - 0.01*float(j)+float(i)*0.01)*5.0 - length(uv) + mod(uv.x+uv.y, 0.2));
}
}
gl_FragColor = vec4(color[0],color[1],color[2],1.0);
}
`
// Initialize Three.js scene
const camera = new THREE.Camera()
camera.position.z = 1
const scene = new THREE.Scene()
const geometry = new THREE.PlaneGeometry(2, 2)
const uniforms = {
time: { type: "f", value: 1.0 },
resolution: { type: "v2", value: new THREE.Vector2() },
}
const material = new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: vertexShader,
fragmentShader: fragmentShader,
})
const mesh = new THREE.Mesh(geometry, material)
scene.add(mesh)
const renderer = new THREE.WebGLRenderer({ antialias: true })
renderer.setPixelRatio(window.devicePixelRatio)
container.appendChild(renderer.domElement)
// Handle window resize
const onWindowResize = () => {
const width = container.clientWidth
const height = container.clientHeight
renderer.setSize(width, height)
uniforms.resolution.value.x = renderer.domElement.width
uniforms.resolution.value.y = renderer.domElement.height
}
// Initial resize
onWindowResize()
window.addEventListener("resize", onWindowResize, false)
// Animation loop
const animate = () => {
const animationId = requestAnimationFrame(animate)
uniforms.time.value += 0.05
renderer.render(scene, camera)
if (sceneRef.current) {
sceneRef.current.animationId = animationId
}
}
// Store scene references for cleanup
sceneRef.current = {
camera,
scene,
renderer,
uniforms,
animationId: 0,
}
// Start animation
animate()
// Cleanup function
return () => {
window.removeEventListener("resize", onWindowResize)
if (sceneRef.current) {
cancelAnimationFrame(sceneRef.current.animationId)
if (container && sceneRef.current.renderer.domElement) {
container.removeChild(sceneRef.current.renderer.domElement)
}
sceneRef.current.renderer.dispose()
geometry.dispose()
material.dispose()
}
}
}, [])
return (
<div
ref={containerRef}
className="w-full h-screen"
style={{
background: "#000",
overflow: "hidden",
}}
/>
)
}
demo.tsx
import { ShaderAnimation } from "@/components/ui/shader-animation";
export default function DemoOne() {
return (
<div className="relative flex h-[650px] w-full flex-col items-center justify-center overflow-hidden rounded-xl border bg-blue-700">
<ShaderAnimation/>
<span className="absolute pointer-events-none z-10 text-center text-7xl leading-none font-semibold tracking-tighter whitespace-pre-wrap text-white">
Shader Animation
</span>
</div>
)
}
```
INSTALL NPM DEPENDENCIES:
```bash
three
```
## IMPLEMENTATION GUIDELINES
1. ANALYZE THE COMPONENT STRUCTURE AND IDENTIFY ALL REQUIRED DEPENDENCIES
2. REVIEW THE COMPONENT'S ARGUMENS AND STATE
3. IDENTIFY ANY REQUIRED CONTEXT PROVIDERS OR HOOKS AND INSTALL THEM
4. QUESTIONS TO ASK
- WHAT DATA/PROPS WILL BE PASSED TO THIS COMPONENT?
- ARE THERE ANY SPECIFIC STATE MANAGEMENT REQUIREMENTS?
- ARE THERE ANY REQUIRED ASSETS (IMAGES, ICONS, ETC.)?
- WHAT IS THE EXPECTED RESPONSIVE BEHAVIOR?
- WHAT IS THE BEST PLACE TO USE THIS COMPONENT IN THE APP?
## STEPS TO INTEGRATE
0. COPY PASTE ALL THE CODE ABOVE IN THE CORRECT DIRECTORIES
1. INSTALL EXTERNAL DEPENDENCIES
2. FILL IMAGE ASSETS WITH UNSPLASH STOCK IMAGES YOU KNOW EXIST
3. USE LUCIDE-REACT ICONS FOR SVGS OR LOGOS IF COMPONENT REQUIRES THEMAdds a render step. Works best with the HyperFrames or Remotion skills installed. Free, no sign-up.
Prompt by @pulkitxm. Prompts belong to their creators.