glsl-gamma

2.0.0 • Public • Published

glsl-gamma

stable

Convenience utilities for working in linear space when dealing with sRGB textures.

#pragma glslify: toLinear require('glsl-gamma/in') 
#pragma glslify: toGamma  require('glsl-gamma/out') 
 
void main() {
  //sample into linear space 
  vec4 color = toLinear(texture2D(uTexture, vUv));
 
  //do linear space transforms on RGB... 
 
  //output to sRGB color buffer 
  gl_FragColor = toGamma(color);
}

Currently all gamma operates on a 2.2 constant.

Usage

NPM

toLinear = require('glsl-gamma/in')

genType = toLinear(genType color)

Take a sRGB value and return its linear form. For vec4, the alpha component is left unchanged.

This is also the default export of glsl-gamma.

toGamma = require('glsl-gamma/out')

genType = toGamma(genType color)

Takes a linear value and return its gamma-corrected (sRGB) form. For vec4, the alpha component is left unchanged.

License

MIT. See LICENSE.md for details.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.0
    12
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.0
    12
  • 1.0.2
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i glsl-gamma

Weekly Downloads

12

Version

2.0.0

License

MIT

Last publish

Collaborators

  • mattdesl