Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/drwpow/daltonlens-webgl
Port of libDaltonLens to a WebGL shader
https://github.com/drwpow/daltonlens-webgl
Last synced: 9 days ago
JSON representation
Port of libDaltonLens to a WebGL shader
- Host: GitHub
- URL: https://github.com/drwpow/daltonlens-webgl
- Owner: drwpow
- License: mit
- Created: 2024-08-12T22:02:32.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-15T16:46:10.000Z (4 months ago)
- Last Synced: 2024-10-15T00:34:18.098Z (2 months ago)
- Language: TypeScript
- Size: 520 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# daltonlens-webgl
WebGL port of DaltonLens protanopia/deuteranopia simulation.
## Usage
```sh
npm i daltonlens-webgl
```### Basic JS
The default export ships an object with `vShader` and `fShader` that contains a string of the shader code:
```js
import daltonLens from "daltonlens-webgl";daltonLens.vShader; // vector shader
daltonLens.fShader; // fragment shader
```Example of loading using generic WebGL code:
```js
const canvasEl = document.getElementById("canvas");
const gl = canvasEl.getContext("webgl2");// vertex shader
const vShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vShader, daltonLens.vShader);
gl.compileShader(vShader);
if (!gl.getShaderParameter(vShader, gl.COMPILE_STATUS)) {
throw new Error(
`VECTOR SHADER: ${gl.getShaderInfoLog(vShader) || "unknown"}`
);
}// fragment shader
const fShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fShader, daltonLens.fShader);
gl.compileShader(fShader);
if (!gl.getShaderParameter(fShader, gl.COMPILE_STATUS)) {
throw new Error(
`FRAGMENT SHADER: ${gl.getShaderInfoLog(fShader) || "unknown"}`
);
}
```### .frag / .vert files
Alternately, this package ships `shader.frag` and `shader.vert` if you prefer loading shaders that way:
```js
import vShader from "daltonlens-webgl/shader.vert";
import fShader from "daltonlens-webgl/shader.frag";
```Note this will likely take custom Vite or webpack config to work though.