glsl-dof

1.0.0 • Public • Published

glsl-dof

Physically accurate depth of field calculated from a vertex position.

Based on a post from Martins Upitis and with the help of this thread.

Example

#pragma glslify: dof require('glsl-dof') 
 
void main() {
    vec4 finalPosition = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
 
    float depth = finalPosition.z / finalPosition.w;
    float focalDepth = 1.5;
    float d = dof(depth, focalDepth);
}

Install

Use npm to install and glslify to consume the function in your shaders.

npm install glsl-dof

Usage

NPM

float dof(float depth, float focalDepth)

Default values: focalLength = 100.0, fstop = 2.0, near = 0.01 and far = 100.0.

float dof(float depth, float focalDepth, float focalLength, float fstop, float near, float far)

License

MIT, see LICENSE.md for details.

Package Sidebar

Install

npm i glsl-dof

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

3.71 kB

Total Files

4

Last publish

Collaborators

  • brunoimbrizi