Asset Library / ui component
Shader Lines UI Component
Copy-paste animated shader lines UI component. Integrates seamlessly with Cursor, Lovable, and other AI code generators for instant gradient mesh effects.
Prompt
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-lines.tsx
"use client"
import { useEffect, useRef } from "react"
declare global {
interface Window {
THREE: any
}
}
export function ShaderAnimation() {
const containerRef = useRef<HTMLDivElement>(null)
const sceneRef = useRef<{
camera: any
scene: any
renderer: any
uniforms: any
animationId: number | null
}>({
camera: null,
scene: null,
renderer: null,
uniforms: null,
animationId: null,
})
useEffect(() => {
// Load Three.js dynamically
const script = document.createElement("script")
script.src = "https://cdnjs.cloudflare.com/ajax/libs/three.js/89/three.min.js"
script.onload = () => {
if (containerRef.current && window.THREE) {
initThreeJS()
}
}
document.head.appendChild(script)
return () => {
// Cleanup
if (sceneRef.current.animationId) {
cancelAnimationFrame(sceneRef.current.animationId)
}
if (sceneRef.current.renderer) {
sceneRef.current.renderer.dispose()
}
document.head.removeChild(script)
}
}, [])
const initThreeJS = () => {
if (!containerRef.current || !window.THREE) return
const THREE = window.THREE
const container = containerRef.current
// Clear any existing content
container.innerHTML = ""
// Initialize camera
const camera = new THREE.Camera()
camera.position.z = 1
// Initialize scene
const scene = new THREE.Scene()
// Create geometry
const geometry = new THREE.PlaneBufferGeometry(2, 2)
// Define uniforms
const uniforms = {
time: { type: "f", value: 1.0 },
resolution: { type: "v2", value: new THREE.Vector2() },
}
// 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;
float random (in float x) {
return fract(sin(x)*1e4);
}
float random (vec2 st) {
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
varying vec2 vUv;
void main(void) {
vec2 uv = (gl_FragCoord.xy * 2.0 - resolution.xy) / min(resolution.x, resolution.y);
vec2 fMosaicScal = vec2(4.0, 2.0);
vec2 vScreenSize = vec2(256,256);
uv.x = floor(uv.x * vScreenSize.x / fMosaicScal.x) / (vScreenSize.x / fMosaicScal.x);
uv.y = floor(uv.y * vScreenSize.y / fMosaicScal.y) / (vScreenSize.y / fMosaicScal.y);
float t = time*0.06+random(uv.x)*0.4;
float lineWidth = 0.0008;
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)*1.0 - length(uv));
}
}
gl_FragColor = vec4(color[2],color[1],color[0],1.0);
}
`
// Create material
const material = new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: vertexShader,
fragmentShader: fragmentShader,
})
// Create mesh and add to scene
const mesh = new THREE.Mesh(geometry, material)
scene.add(mesh)
// Initialize renderer
const renderer = new THREE.WebGLRenderer()
renderer.setPixelRatio(window.devicePixelRatio)
container.appendChild(renderer.domElement)
// Store references
sceneRef.current = {
camera,
scene,
renderer,
uniforms,
animationId: null,
}
// Handle resize
const onWindowResize = () => {
const rect = container.getBoundingClientRect()
renderer.setSize(rect.width, rect.height)
uniforms.resolution.value.x = renderer.domElement.width
uniforms.resolution.value.y = renderer.domElement.height
}
onWindowResize()
window.addEventListener("resize", onWindowResize, false)
// Animation loop
const animate = () => {
sceneRef.current.animationId = requestAnimationFrame(animate)
uniforms.time.value += 0.05
renderer.render(scene, camera)
}
animate()
}
return (
<div
ref={containerRef}
className="w-full h-full absolute"
/>
)
}
demo.tsx
import { ShaderAnimation } from "@/components/ui/shader-lines";
export default function DemoOne() {
return (
<div className="relative flex h-[650px] w-full flex-col items-center justify-center overflow-hidden rounded-xl">
<ShaderAnimation/>
<span className="pointer-events-none z-10 text-center text-7xl leading-none font-semibold tracking-tighter whitespace-pre-wrap text-white">
Shader Lines
</span>
</div>
)
}
```
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 them
This asset is a production-ready UI component featuring animated shader lines with smooth gradient mesh transitions. It is designed for direct copy-paste integration into AI-assisted development environments like Cursor or Lovable.
Use this component to add dynamic, high-performance visual depth to hero sections, loading states, or background accents in modern web applications. It eliminates the need for manual WebGL or shader programming.
It is useful for developers and designers who prioritize visual polish but require rapid implementation. The component provides a sophisticated, motion-rich aesthetic that static gradients cannot achieve.
The target user is anyone building with AI code generation tools who needs a reliable, visually striking element without deep graphics expertise.
What sets it apart is its specific optimization for AI code generation workflows. The code is structured for immediate comprehension and adaptation by AI assistants, ensuring consistent results unlike generic shader snippets.
Usage:
• Copy the provided component code entirely from the library.
• Paste it directly into your project file within Cursor, Lovable, or a similar AI code editor.
• Use the AI's chat interface to request modifications, such as adjusting color stops, animation speed, or line density.
• Integrate the rendered component into your layout's JSX or template structure.
• Test the component's performance and responsiveness across target devices.
