JSPM

glsl-dof

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q28777F
  • License MIT

depth of field based on vertex position

Package Exports

  • glsl-dof

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (glsl-dof) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.