glsl-gamma

gamma-to-linear convenience utilities


Keywords
ecosystem:stackgl, glsl, gamma, sRGB, correct, texture, linear, space
License
MIT
Install
npm install glsl-gamma@2.0.0

Documentation

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.