glsl-cartesian-to-barycentric
glslify module to convert cartesian to barycentric coordinates
example
This example creates a shader over the whole screen and calculates barycentric
coordinates for a triangle described by p0
,p1
,p2
.
The color channel is set to the barycentric coordinates for points inside the triangle.
var glsl =var regl =var draw =window{reglreglclear color: 0001 depth: true}
api
#pragma glslify: c2b = require(glsl-cartesian-to-barycentric)
vec3 bc = c2b(vec2 p, vec2 a, vec2 b, vec2 c)
Calculate the barycentric coordinates for a cartesian coordinate p
in a
triangle defined by the cartesian coordinates a
, b
, and c
.
To go from barycentric back to cartesian coordinates:
vec2 p = a * bc.x + b * bc.y + c * bc.z;
install
npm install glsl-cartesian-to-barycentric
license
bsd