glsl-geo-projection

1.1.1 • Public • Published

carbonplan / glsl-geo-projection

shader math for geographic projections

GitHub MIT License

why

The libraries d3-geo and d3-geo-projection expose a wide diversity of geographic map projections. While they are a perfect solution in JavaScript, for WebGL applications we need the same math available in GLSL. A specific use case is using the inverse equations to render raster data with arbitrary map projections, as shown in this neat demo. This library exposes snippets of shader code with forward and inverse functions for a variety of projections.

Note: Work in progress. We're making our way through the projections, largely motivated by our needs to use them. If you want to add one, please open an Issue.

use

Install the package.

npm i glsl-geo-projection

Then import the functions you want and insert them into your shader.

import { orthographicInvert } from "glsl-geo-projection";

const frag = `
${orthographicInvert}

void main() 
{
  vec2 coordinates = orthographicInvert(x, y);
  // ... remaining shader code...
}
`;

Names are identical to those in d3-geo and d3-geo-projection. The naming convention is that each projection has a forward function with its name and an inverse function with its name followed by Invert. For example, orthographic and orthographicInvert, or mercator and mercatorInvert.

license

All the original code in this repository is MIT licensed. The library is based closely on d3-geo and d3-geo-projection. We request that you please provide attribution if reusing any of our digital content (graphics, logo, copy, etc.).

Package Sidebar

Install

npm i glsl-geo-projection

Weekly Downloads

133

Version

1.1.1

License

MIT

Unpacked Size

21.5 kB

Total Files

9

Last publish

Collaborators

  • freeman-lab