Get the normal vector of a position within a signed distance field.
Last updated 6 years ago by hughsk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install glsl-sdf-normal 
SYNC missed versions from official npm registry.



Get the normal vector of a position within a signed distance field.



getNormal = require(glsl-sdf-normal, <map>)

Loads the getNormal function into your shader. Note that map is required to be defined when using this module.

vec2 map(vec3 position)

Your signed distance function, responsible for defining the solid shapes in your scene. Accepts position, and returns a vec2 – see glsl-raytrace for more guidance :)

vec2 doModel(vec3 p);

#pragma glslify: getNormal = require('glsl-sdf-normal', map = doModel)

vec2 doModel(vec3 position) {
  float radius  = 1.0;
  float dist    = length(position) - radius;
  float objType = 1.0;

  return vec2(dist, objType);

vec3 getNormal(vec3 position)

Gets the normal vector for the provided position.

vec3 getNormal(vec3 position, float epsilon)

Optionally, you may pass in a custom epsilon value, which determines the granularity at which to sample the field. Defaults to 0.002.


See stackgl/contributing for details.


MIT. See for details.

Current Tags

  • 1.0.0                                ...           latest (6 years ago)

1 Versions

  • 1.0.0                                ...           6 years ago
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
Dev Dependencies (15)
Dependents (1)

Copyright 2014 - 2017 © |