0.2.4 • Published 2 months ago

@webglify/chain v0.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@webglify/chain - A WebGL2 Library for KISS and DRY

This library is designed to render WebGL while adhering to the principles of DRY (Don't Repeat Yourself) and KISS (Keep It Simple, Stupid). The goal is to provide a straightforward interface with a minimal amount of library-specific abstractions. If you're familiar with the WebGL, then this library is primarily about the conventions of how to organize things. That's it.

Installation

npm install @webglify/chain

Basic Usage

import chain from '@webglify/chain';

const gl = document.querySelector('canvas#fancyCanvas').getContext('webgl2');

// Put shaders together
const { renderFrame } = chain(gl, [
  // pass1
  {
    vertexShader: vertexShader1,
    fragmentShader: fragmentShader1
  },
  // pass2
  {
    vertexShader: vertexShader2,
    fragmentShader: fragmentShader2
  }
  // ... add more passes as needed
]);

// Render the frame!
renderFrame();

Working with Uniforms

Uniforms are a way to send data from your JavaScript code to your WebGL shaders. Here's how you can use uniforms with this library:

If you've defined a uniform in your shader, like:

uniform float uTime;

void main(){
  
  vec2 pos = vec2(sin(uTime), cos(uTime));
  // ...

}

You can communicate with it from your JavaScript code as follows:

const STATE = {
  time: 0
}

chain(gl, [
  {
    vertexShader: vertexShader1,
    fragmentShader: fragmentShader2,
    uniforms(gl, uniformLocations){
      gl.uniform1f(uniformLocations.uTime, STATE.time)      
    }
  },
])

comming soon:

Advanced Usage: Dive deeper into more complex features or configurations.

API Reference: A detailed breakdown of the library's API.

Contributing: Information for developers who want to contribute to the library.

License: Information about the library's licensing.

0.2.4

2 months ago

0.2.3

3 months ago

0.2.2

3 months ago

0.2.0

4 months ago

0.1.7

4 months ago

0.1.6

4 months ago

0.1.5

4 months ago

0.1.4

4 months ago

0.1.3

4 months ago

0.1.2

5 months ago

0.1.1

6 months ago

0.1.0

8 months ago

0.0.9

8 months ago

0.0.8

8 months ago

0.0.7

9 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago