@mapcat/mapcat-gl-shaders

1.0.1 • Public • Published

Mapbox GL Shaders

This repository contains GL shaders which are shared by Mapbox GL JS and Mapbox GL Native.

Pragmas

Some variables change type depending on their context:

  • if the variable is the same for all features, we declare it as a uniform
  • if the variable is different for each feature, we declare it as an attribute
  • if the variable is different for each feature and a function of zoom, we declare several attributes and uniforms then calculate the value using interpolation

We abstract over this functionality using pragmas.

#pragma mapbox: define lowp vec4 color

main() {
    #pragma mapbox: initialize lowp vec4 color
    ...
    gl_FragColor = color;
}

This program defines a variable within main called color, initialize the value of color, then sets gl_FragColor to the value of color.

Pragmas take the following form.

#pragma mapbox: (define|initialize) (lowp|mediump|highp) (float|vec2|vec3|vec4) {name}

When using pragmas, the following requirements apply.

  • all pragma-defined variables must have both define and initialize pragmas
  • define pragmas must be in file scope
  • initialize pragmas must be in function scope
  • all pragma-defined variables defined and initialized in the fragment shader must also be defined and initialized in the vertex shader because attributes are not accessible from the fragment shader

Util

The util.glsl file is automatically included in all shaders by the compiler.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.10latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.10
1.0.00

Package Sidebar

Install

npm i @mapcat/mapcat-gl-shaders

Weekly Downloads

0

Version

1.0.1

License

ISC

Last publish

Collaborators

  • ikapcsandi