Socket
Book a DemoInstallSign in
Socket

glsl-sdf-normal

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glsl-sdf-normal

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

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

glsl-sdf-normal

stable

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

Usage

NPM

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.

Contributing

See stackgl/contributing for details.

License

MIT. See LICENSE.md for details.

Keywords

ecosystem:stackgl

FAQs

Package last updated on 28 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts