Suzanne 🐒 - Dependency-free 3D Software Renderer
Features 🐵
- Programmable Vertex and Fragment shaders
- Perspective correct varying interpolation
- Texture mapping
- OBJ model loader
- API similar to WebGL
- Works in the browser and node.js
- Provides TypeScript type declarations
Use cases 🙈
- Server-side 3D rendering
- Set your CPU on 🔥
Todo 🙊
- Implement clipping
- Support .mtl files
- Improve performance
- Antialiasing
- Mipmapping
Usage 🍌
npm install suzanne
Importing
Node.js
const suz = ;
Browser
Webpack, Parcel...
;
Basic example
To draw something, a new Context must be created
Suzanne internally stores pixel data in a Uint8ClampedArray in RGBA
const sz = 400 300 { // draw bitmap (to a file or in an html canvas) }; const triangle = vertices: suz suz suz indices: 0 1 2 attributes: color: //suz.colors are just suz.vec4 instances suzcolorsred suzcolorsgreen suzcolorsblue ; // create a Vertex Array Object from our triangleconst VAO = suzVertexArray; // Use a perspective projection matrix to transform the triangle's verticesconst proj = suzMatrix4; // declare a uniform variable (accessible from both shaders)VAO; // Attach shaders to our Canvas3Dsz; // bind our VAO to our Canvas3Dsz; // clear the canvas to blackszclearsuzcolorsblack; // draw the triangle in indexed modesz; // update the canvassz;