Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-19] feature: allow configuring maxMarkers #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface COBEOptions {
markerColor: [number, number, number]
glowColor: [number, number, number]
markers: Marker[]
maxMarkers?: number
diffuse: number
devicePixelRatio: number
dark: number
Expand Down
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const OPT_OFFSET = 'offset'
const OPT_SCALE = 'scale'
const OPT_OPACITY = 'opacity'
const OPT_MAP_BASE_BRIGHTNESS = 'mapBaseBrightness'
const OPT_MAX_MARKERS = 'maxMarkers'

const OPT_MAPPING = {
[OPT_PHI]: GLSLX_NAME_PHI,
Expand All @@ -34,9 +35,9 @@ const OPT_MAPPING = {

const { PI, sin, cos } = Math

const mapMarkers = (markers) => {
const mapMarkers = (markers, maxMarkers) => {
return [].concat(
...markers.map((m) => {
...markers.slice(0, maxMarkers).map((m) => {
let [a, b] = m.location
a = (a * PI) / 180
b = (b * PI) / 180 - PI
Expand Down Expand Up @@ -139,7 +140,7 @@ export default (canvas, opts) => {
[GLSLX_NAME_DARK]: createUniform('float', OPT_DARK),
[GLSLX_NAME_MARKERS]: {
type: 'vec4',
value: mapMarkers(opts[OPT_MARKERS]),
value: mapMarkers(opts[OPT_MARKERS], opts[OPT_MAX_MARKERS] || 64),
},
[GLSLX_NAME_MARKERS_NUM]: {
type: 'float',
Expand Down Expand Up @@ -170,7 +171,7 @@ export default (canvas, opts) => {
}
}
if (state[OPT_MARKERS] !== undefined) {
uniforms[GLSLX_NAME_MARKERS].value = mapMarkers(state[OPT_MARKERS])
uniforms[GLSLX_NAME_MARKERS].value = mapMarkers(state[OPT_MARKERS], opts[OPT_MAX_MARKERS] || 64)
uniforms[GLSLX_NAME_MARKERS_NUM].value = state[OPT_MARKERS].length
}
if (state.width && state.height) {
Expand Down
4 changes: 2 additions & 2 deletions src/shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ uniform float scale;
uniform vec3 baseColor;
uniform vec3 markerColor;
uniform vec3 glowColor;
uniform vec4 markers[64];
uniform vec4 markers[300];
uniform float markersNum;
uniform float dotsBrightness;
uniform float diffuse;
Expand Down Expand Up @@ -172,7 +172,7 @@ void main() {

int num = int(markersNum);
float markerLight = 0.;
for (int m = 0; m < 64; m++) {
for (int m = 0; m < 300; m++) {
if (m >= num) break;
vec4 marker = markers[m];
vec3 c = marker.xyz;
Expand Down
1 change: 1 addition & 0 deletions website/pages/docs/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ An object with the following properties:
| scale | Scales the globe, 0 ≤ scale | |
| offset | [offsetX, offsetY], offset of the globe in pixel | |
| markers | An array of markers displayed | |
| maxMarkers | Control the max amount of markers on the globe (0-300), defaults to 64 | |
| opacity | The transparency of the globe texture | |
| onRender | A callback function called when a new frame is rendered | Required |

Expand Down