https://github.com/hughsk/glsl-fog
Basic fog functions for GLSL
https://github.com/hughsk/glsl-fog
Last synced: 3 months ago
JSON representation
Basic fog functions for GLSL
- Host: GitHub
- URL: https://github.com/hughsk/glsl-fog
- Owner: hughsk
- License: mit
- Created: 2013-10-11T01:20:19.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-12-27T18:25:14.000Z (over 6 years ago)
- Last Synced: 2024-04-14T13:05:54.960Z (about 1 year ago)
- Language: C
- Size: 74.2 KB
- Stars: 32
- Watchers: 5
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# glsl-fog [](http://github.com/hughsk/stability-badges) #
Basic fog functions for GLSL, generic but intended for use with
[glslify](http://github.com/chrisdickinson/glslify).## Usage ##
[](https://nodei.co/npm/glsl-fog)
Here's a hypothetical example of linear fog calculated in a vertex shader:
``` glsl
#define FOG_START 100
#define FOG_END 500uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;attribute vec3 position;
varying float fogAmount;#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:
``` glsl
#define FOG_DENSITY 0.05varying 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); // whitegl_FragColor = mix(vertexColor, fogColor, fogAmount);
}
```## License ##
MIT. See [LICENSE.md](http://github.com/hughsk/glsl-fog/blob/master/LICENSE.md) for details.