1.1.0 • Published 5 years ago

@react-vertex/shader-hooks v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@react-vertex/shader-hooks

license bundlephobia npm version

Documentation and Examples

React hooks for working with WebGL programs and shaders. More info on WebGL Programs and WebGL shaders.

Install via npm:
npm install @react-vertex/shader-hooks

Importing:

import {
  useProgram,
  useShader,
} from '@react-vertex/shader-hooks'

useProgram(gl, vertSource, fragSource) => WebGLProgram

React hook for creating a WebGL program. It uses useShader internally so you likely only need to use this hook to setup a basic program. More info on WebGL Programs. The hook will warn on compile errors and provide debug information. The program will also be deleted automatically when the containing component unmounts to conserve resources.

Arguments:

gl: A WebGL context.

vertSource: A string containing the vertex shader source or a compiled WebGLShader (see useShader below).

fragSource: A string containing the fragment shader source or a compiled WebGLShader (see useShader below).

Returns:

program: A WebGLProgram.

Example Usage:
import { useProgram } from '@react-vertex/shader-hooks'
import vert from './vert.glsl'
import frag from './frag.glsl'

...
  const program = useProgram(gl, vert, frag)
...

useShader(gl, source, [isVertShader]) => WebGLShader

React hook for creating a WebGL shader. This is used internally by useProgram so you might not need it. This is useful if you want to compile your shaders higher up in your app. The hook will warn on compile errors and provide debug information.

Arguments:

gl: A WebGL context.

source: A string containing the shader source.

isVertShader (optional): Boolean value that defualts to false.

Returns:

shader: A WebGLShader.

Example Usage:
import { useShader, useProgram } from '@react-vertex/shader-hooks'
import vert from './vert.glsl'
import frag from './frag.glsl'

...
  const vertShader = useShader(gl, vert, true) // compile shaders higher up in your app
  const fragShader = useShader(gl, frag)
...

// Then somewhere else in your app (same conext of course)...
...
  const program = useProgram(gl, vertShader, fragShader)
...
1.1.0

5 years ago

1.0.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.11

5 years ago