Liquid Background
A reactive and dynamic background effect using OGL for WebGL-based visuals.
API
This component does not require external props to function, as it dynamically renders the liquid background effect on mount.
注意: This component uses OGL Web Renderer & requires ogl
npm package as a dependency.
通过 CLI 安装
手动安装
You can 复制并粘贴以下代码: to create this component:
功能特性
- WebGL Rendering: Utilizes the OGL library to provide hardware-accelerated background effects.
- Animated Shader: Runs a custom fragment and vertex shader to generate a liquid-like visual animation.
- Automatic Resizing: Listens to window resize events and adjusts the canvas dimensions accordingly.
- Clean Resource Management: Disposes of the WebGL context and removes event listeners upon unmount, preventing memory leaks.
Implementation Details
- OGL Renderer: Creates a renderer with
new Renderer()
and appends the associatedcanvas
to the DOM. - Shader Programs: Defines vertex (
vert
) and fragment (frag
) shaders, where the fragment shader implements the liquid animation logic. - Triangle Geometry: Uses OGL’s built-in
Triangle
geometry for a full-screen quad. - Uniforms:
uTime
: Updated each frame to animate the shader.uResolution
: Adjusted on window resize to maintain consistent visuals.uColor
: An example color uniform (slightly purple) used in the shader.
- Animation Loop: Schedules updates via
requestAnimationFrame
, updatesuTime
, and renders the scene.
感谢
- Built with the OGL library for 3D rendering.
- Inspired by generative art patterns.
- Uses Vue's Composition API for lifecycle and state management.