Recreate Balatro’s Animated Shader Effect with WebGL – balatroShader.js
It renders GPU-accelerated, infinitely looping geometric patterns with customizable colors, rotation, and pixel sizing.
1. Load the balatroShader library and create a container element in your HTML:
<script src="balatroShader.js"></script>
<div id="background"></div>
2. Create a new shader instance by targeting an HTML element and optionally configuring parameters. The shader creates a canvas element, positions it absolutely within the container, and starts the animation loop automatically. The canvas fills the container’s dimensions and updates on window resize by default.
const instance = new BalatroShader({
container: "#background",
colours: { c1: "#DE443B", c2: "#006BB4", c3: "#162325" },
speed: 1.4,
contrast: 2,
spinAmount: 0.5,
pixelSizeFac: 1000,
spinEase: 0.5
}); 3. All possible configuration options:
c1, c2, c3) that define the visual palette.4. API methods.
instance.pause(): Stops the rendering loop to save GPU resources.instance.resume(): Restarts the animation loop.instance.destroy(): Removes the canvas from the DOM and cleans up event listeners.Q: The shader appears pixelated but I want a smoother look. How do I fix this?
A: Increase the pixelSizeFac value substantially. The default of 700 creates visible pixel blocks. Try values between 2000 and 5000 for much finer detail. Keep in mind that higher values increase GPU calculation load, so test performance on target devices. If you want completely smooth rendering, set pixelSizeFac to 10000 or higher.
Q: The animation causes performance issues on mobile devices. What are my options?
A: Reduce maxFPS to 30 or even 24 for mobile users. You can detect mobile devices and pass a lower frame rate during initialization. Also consider lowering pixelSizeFac to around 400-500, which reduces the number of calculations per frame. The combination of fewer frames and larger pixels significantly improves mobile performance. You can also use pause() when the element scrolls out of view using an Intersection Observer.
Q: How do I layer content on top of the shader?
A: The canvas uses pointer-events: none by default, so clicks pass through to underlying elements. Position your content elements within the same container and use z-index to control stacking order. Make sure your content elements have position: relative or position: absolute with a z-index higher than the canvas. The shader automatically applies to the container’s background layer.
The post Recreate Balatro’s Animated Shader Effect with WebGL – balatroShader.js appeared first on CSS Script.
Between the ubiquitous virtual assistants cheerfully patronising us from almost every electronic device and the…
If you're a Windows user who's looking for a PC version of the Apple Mac…
FORT WAYNE, Ind. (WOWO) — The state of Indiana has agreed to let the Indiana…
FORT WAYNE, Ind. (WOWO) — Severe thunderstorms are expected to move across central Indiana in…
Universal Pictures and Focus Features have taken the stage at CinemaCon. We're expecting new looks…
Maritza Montejo, a Liberty Tax Service office manager, helps Aurora Hernandez, left, with her taxes…
This website uses cookies.