Skip to content
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
24 changes: 22 additions & 2 deletions src/components/Globe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
makeColormapMaterial,
availableColormaps,
calculateColorMapProperties,
availableProjections,
} from "./utils/colormapShaders.ts";
import { decodeTime } from "./utils/timeHandling.ts";

Expand All @@ -26,6 +27,7 @@ import { storeToRefs } from "pinia";
import type {
TBounds,
TColorMap,
TProjection,
TSources,
TVarInfo,
} from "../types/GlobeTypes.ts";
Expand All @@ -38,6 +40,7 @@ const props = defineProps<{
varbounds?: TBounds;
colormap?: TColorMap;
invertColormap?: boolean;
projection?: TProjection;
}>();

const emit = defineEmits<{ varinfo: [TVarInfo] }>();
Expand Down Expand Up @@ -109,11 +112,18 @@ watch(
}
);

watch(
() => props.projection,
() => {
updateProjection();
}
);

const colormapMaterial = computed(() => {
if (props.invertColormap) {
return makeColormapMaterial(props.colormap, 1.0, -1.0);
return makeColormapMaterial(props.colormap, 1.0, -1.0, props.projection);
} else {
return makeColormapMaterial(props.colormap, 0.0, 1.0);
return makeColormapMaterial(props.colormap, 0.0, 1.0, props.projection);
}
});

Expand Down Expand Up @@ -184,6 +194,16 @@ function updateColormap() {
redraw();
}

function updateProjection() {
if (props.projection) {
const myMesh = mainMesh as THREE.Mesh;
const material = myMesh.material as THREE.ShaderMaterial;
material.uniforms.projection.value =
availableProjections[props.projection!];
redraw();
}
}

async function getData() {
store.startLoading();
try {
Expand Down
22 changes: 22 additions & 0 deletions src/components/GlobeControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import type {
TColorMap,
TModelInfo,
TBounds,
TProjection,
TVarInfo,
TSelection,
} from "../types/GlobeTypes.js";
import { availableProjections } from "./utils/colormapShaders.ts";

const props = defineProps<{ varinfo?: TVarInfo; modelInfo?: TModelInfo }>();

Expand All @@ -32,6 +34,7 @@ const defaultBounds: Ref<TBounds> = ref({});
const userBoundsLow: Ref<number | undefined> = ref(undefined);
const userBoundsHigh: Ref<number | undefined> = ref(undefined);
const pickedBounds = ref("auto");
const projection: Ref<TProjection> = ref("perspective");

const activeBounds = computed(() => {
if (pickedBounds.value === "auto") {
Expand Down Expand Up @@ -119,6 +122,11 @@ watch(
() => setDefaultColormap()
);

watch(
() => projection.value,
() => publish()
);

function toggleMenu() {
menuCollapsed.value = !menuCollapsed.value;
}
Expand All @@ -132,6 +140,7 @@ const publish = () => {
bounds: bounds.value as TBounds,
colormap: colormap.value,
invertColormap: invertColormap.value,
projection: projection.value,
});
};

Expand Down Expand Up @@ -404,6 +413,19 @@ publish(); // ensure initial settings are published
</button>
</div>
</div>
<div v-if="modelInfo && !isHidden" class="panel-block">
<div class="select is-fullwidth">
<select v-model="projection">
<option
v-for="p in Object.keys(availableProjections)"
:key="p"
:value="p"
>
{{ p }}
</option>
</select>
</div>
</div>
<div v-if="modelInfo && !isHidden" class="panel-block">
<p class="control">
<button
Expand Down
24 changes: 23 additions & 1 deletion src/components/GlobeHealpix.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as zarr from "zarrita";
import * as healpix from "@hscmap/healpix";
import {
availableColormaps,
availableProjections,
calculateColorMapProperties,
makeTextureMaterial,
} from "./utils/colormapShaders.ts";
Expand All @@ -16,6 +17,7 @@ import { storeToRefs } from "pinia";
import type {
TBounds,
TColorMap,
TProjection,
TSources,
TVarInfo,
} from "../types/GlobeTypes.ts";
Expand All @@ -28,6 +30,7 @@ const props = defineProps<{
varbounds?: TBounds;
colormap?: TColorMap;
invertColormap?: boolean;
projection?: TProjection;
}>();

const emit = defineEmits<{ varinfo: [TVarInfo] }>();
Expand Down Expand Up @@ -103,6 +106,13 @@ watch(
}
);

watch(
() => props.projection,
() => {
updateProjection();
}
);

const gridsource = computed(() => {
if (props.datasources) {
return props.datasources.levels[0].grid;
Expand Down Expand Up @@ -156,6 +166,17 @@ function updateColormap() {
redraw();
}

function updateProjection() {
for (const myMesh of mainMeshes) {
const material = myMesh.material as THREE.ShaderMaterial;
if (material?.uniforms.projection && props.projection) {
material.uniforms.projection.value =
availableProjections[props.projection];
}
}
redraw();
}

async function fetchGrid() {
const gridStep = 64 + 1;
try {
Expand Down Expand Up @@ -468,7 +489,8 @@ onBeforeMount(async () => {
new THREE.Texture(),
props.colormap!,
addOffset,
scaleFactor
scaleFactor,
props.projection!
);
mainMeshes[ipix] = new THREE.Mesh(
makeHealpixGeometry(1, ipix, gridStep),
Expand Down
46 changes: 41 additions & 5 deletions src/components/utils/colormapShaders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from "three";
import type { TColorMap } from "../../types/GlobeTypes";
import type { TColorMap, TProjection } from "../../types/GlobeTypes";

export const availableColormaps = {
inferno: 0,
Expand Down Expand Up @@ -62,6 +62,11 @@ export const availableColormaps = {
tarn: 57,
} as const;

export const availableProjections = {
perspective: 0,
azimuthal: 1,
} as const;

const shaders = `
vec3 inferno(float t) {

Expand Down Expand Up @@ -1031,14 +1036,40 @@ void main() {
${distinguishShaders}
}`;

const PI = 3.14159265359;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using Math.PI instead


const positionVertexShaderPerspective = `
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
`;

const positionVertexShaderAzimuthal = `
vec3 pos = mat3(modelViewMatrix) * position;
float dist = (${PI} / 2.) - asin(pos.z);
pos.xy = normalize(pos.xy) * (dist * .39);
pos.z = -10. + pos.z * 0.001;
gl_Position = projectionMatrix * vec4(pos, 1.);
`;

const positionVertexShaderUniforms = `
uniform int projection;
`;
const positionVertexShaderPart = `
if (projection == 0) {
${positionVertexShaderPerspective}
} else if (projection == 1) {
${positionVertexShaderAzimuthal}
}
`;

const dataOnMeshVertexShader = `
attribute float data_value;

varying float v_value;
${positionVertexShaderUniforms}

void main() {
v_value = data_value;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
${positionVertexShaderPart}
}
`;

Expand All @@ -1055,23 +1086,26 @@ const dataOnScreenMeshVertexShader = `

const dataOnTextureVertexShader = `
varying vec2 vUv;
${positionVertexShaderUniforms}

void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
${positionVertexShaderPart}
}
`;

export function makeColormapMaterial(
colormap: TColorMap = "turbo",
addOffset: 1.0 | 0.0 = 0.0,
scaleFactor: -1.0 | 1.0 = 1.0
scaleFactor: -1.0 | 1.0 = 1.0,
projection: TProjection = "perspective"
) {
const material = new THREE.ShaderMaterial({
uniforms: {
addOffset: { value: addOffset },
scaleFactor: { value: scaleFactor },
colormap: { value: availableColormaps[colormap] },
projection: { value: availableProjections[projection] },
},

vertexShader: dataOnMeshVertexShader,
Expand Down Expand Up @@ -1102,14 +1136,16 @@ export function makeTextureMaterial(
texture: THREE.Texture,
colormap: TColorMap = "turbo",
addOffset: number,
scaleFactor: number
scaleFactor: number,
projection: TProjection = "perspective"
) {
const material = new THREE.ShaderMaterial({
uniforms: {
addOffset: { value: addOffset },
scaleFactor: { value: scaleFactor },
colormap: { value: availableColormaps[colormap] },
data: { value: texture },
projection: { value: availableProjections[projection] },
},

vertexShader: dataOnTextureVertexShader,
Expand Down
7 changes: 6 additions & 1 deletion src/types/GlobeTypes.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import type { Dayjs } from "dayjs";
import type { availableColormaps } from "../components/utils/colormapShaders.ts";
import type {
availableColormaps,
availableProjections,
} from "../components/utils/colormapShaders.ts";
import * as zarr from "zarrita";

export type EmptyObj = Record<PropertyKey, never>;

export type TColorMap = keyof typeof availableColormaps;
export type TProjection = keyof typeof availableProjections;

export type TBounds = EmptyObj | { low: number; high: number };

export type TSelection = {
colormap: TColorMap;
invertColormap: boolean;
bounds: TBounds;
projection: TProjection;
};

export type TVarInfo = {
Expand Down
1 change: 1 addition & 0 deletions src/views/GlobeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ onMounted(async () => {
:invert-colormap="selection.invertColormap"
:varbounds="selection.bounds"
:is-rotated="gridType === GRID_TYPES.REGULAR_ROTATED"
:projection="selection.projection"
@varinfo="updateVarinfo"
/>
<div v-if="isLoading || loading" class="top-right-loader loader" />
Expand Down