Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Comment thread
arno-fukuda marked this conversation as resolved.
Outdated
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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that 64 should be extracted into a const.

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