glsl-fog
Basic fog functions for GLSL: linear, exp and exp2
Last updated 11 years ago by hughsk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install glsl-fog 
SYNC missed versions from official npm registry.

glsl-fog experimental

Basic fog functions for GLSL, generic but intended for use with glslify.

Usage

glsl-fog

Here's a hypothetical example of linear fog calculated in a vertex shader:

#define FOG_START 100
#define FOG_END 500

varying float fogAmount;
uniform vec3 position;

#pragma glslify: fog_linear = require(glsl-fog/linear)

void main() {
  gl_Position = projection * view * model * vec4(positon, 1.0);
  float fogDistance = length(gl_Position.xyz);
  fogAmount = fog_linear(fogDistance, FOG_START, FOG_END);
}

And another (separate) example using exp/exp2 per-pixel fog:

#define FOG_DENSITY 0.05

varying vec4 vertexColor;

// Take your pick: these should be usable interchangeably.
#pragma glslify: fog_exp2 = require(glsl-fog/exp2)
#pragma glslify: fog_exp = require(glsl-fog/exp)

void main() {
  float fogDistance = gl_FragCoord.z / gl_FragCoord.w;
  float fogAmount = fog_exp2(fogDistance, FOG_DENSITY);
  const float fogColor = vec4(1.0); // white

  gl_FragColor = mix(vertexColor, fogColor, fogAmount);
}

License

MIT. See LICENSE.md for details.

Current Tags

  • 0.0.1                                ...           latest (11 years ago)

2 Versions

  • 0.0.1                                ...           11 years ago
  • 0.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE