A highly efficient and lightweight WebGL renderer
stress test demo ( source code )
custom shader demo ( source code )
mask demo ( source code )
- Fast Rendering: Render 10,000 sprites at 60fps
- Multi-Texture Support: Batch rendering using GPU's maximum texture units
- Graphics Drawing
- Matrix Stack
- Text Rendering
- Line Drawing
- Custom Shaders
- Mask
npm i rapid-render
Or use unpkg
<script src="https://unpkg.com/rapid-render/dist/rapid.umd.cjs"></script>
import { Rapid } from "rapid-render"
let rapid = new Rapid({
canvas: document.getElementById("game"),
backgroundColor: Color.fromHex("FFFFFF")
});
// Create texture
const cat = await rapid.textures.textureFromUrl("./cat.png");
// R G B A
const color = new Color(255, 255, 255, 255); // Or use Color.fromHex
// Call before rendering
rapid.startRender();
// Render here...
// Call after rendering
rapid.endRender();
// Set canvas size
rapid.resize(100, 100);
const text = rapid.textures.createText({ text: "Hello!", fontSize: 30 })
rapid.save() // Save state
rapid.matrixStack.translate(0,0)
rapid.matrixStack.scale(1)
rapid.matrixStack.rotate(0)
// Render Sprit
rapid.renderSprite(cat, 0, 0, color) // or rapid.renderSprite(cat, 0, 0, { color })
// Rendr Graphic
const path = Vec2.FormArray([[0, 0], [100, 0], [100, 100]])
rapid.renderGraphic(0,0,{points:path, color:green})
// or
// rapid.startGraphicDraw()
// rapid.addGraphicVertex(0, 0, color)
// rapid.endGraphicDraw()
// Render Text
rapid.renderSprite(text, 200, 0)
text.setText("time:" + Math.round(time))
rapid.restore() // back to the previous saved state
View demo and watch detailed shader code custom shader demo ( source code )
const vertexShaderSource = `...`
const fragmentShaderSource = `...`
const customShader = new GLShader(rapid, vertexShaderSource, fragmentShaderSource)
rapid.startRender()
rapid.renderSprite(plane, 100, 100, {
shader: customShader, // shader
uniforms: {
// Set custom uniform (You can set mat3, vec2, texture and so on here)
uCustomUniform: Number(costumUniformValue)
// uVec2Uniform: [0,2] // recognized as vec2
// uMat3Uniform: [
// [0,0,0],
// [0,0,0],
// [0,0,0],
// ]
// recognized as mat3
}
});
rapid.endRender()