glsl-dof
v1.0.0
Published
depth of field based on vertex position
Downloads
12
Maintainers
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
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.