import './_planet.mjs';
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { fakeRenderer } from './importmap.mjs';
const { GlobeView } = await import('../js/globe.js');
const { FlatView } = await import('../js/flatmap.js');
const { SHADE_GLSL } = await import('../js/shading.js');
const makers = [['globe', r => new GlobeView(r, () => {})], ['equal_earth', r => new FlatView(r, 'equal_earth', () => {})],
['plate_carree', r => new FlatView(r, 'plate_carree', () => {})]];
for (const [name, make] of makers) {
test(`${name}: over-layer blend and sun lighting drive the shared uniforms`, () => {
const v = make(fakeRenderer()), u = v.shade, tex = { isTexture: true };
v.setOver(tex, 0.4);
assert.equal(u.map2.value, tex);
assert.equal(u.mix2.value, 0.4);
v.setOver(null, 0.4);
assert.equal(u.mix2.value, 0);
v.setSun([0, 1, 0]);
assert.equal(u.sky.value, 1);
assert.deepEqual(u.sunDir.value.toArray(), [0, 1, 0]);
v.setSun(null);
assert.equal(u.sky.value, 0);
assert.ok(v.material.fragmentShader.includes('shadeColor('));
assert.equal(v.material.uniforms.mix2, u.mix2, 'material and view share uniform objects');
});
}
test('GLSL chunk declares the shared uniforms and the shading function', () => {
for (const n of ['uniform sampler2D map2', 'uniform float mix2', 'uniform vec3 sunDir', 'uniform float sky', 'vec3 shadeColor(']) {
assert.ok(SHADE_GLSL.includes(n), n);
}
});
test('haze uniforms exist and default to none', async () => {
const { shadeUniforms, SHADE_GLSL } = await import('../js/shading.js');
const u = shadeUniforms();
assert.equal(u.hazeAmt.value, 0);
assert.ok(u.camPos.value && u.hazeCol.value && u.hazeK.value > 0);
assert.match(SHADE_GLSL, /hazeAmt/);
});
test('over-layer keeps only the base\'s light and dark: its colour reads true, base colour (river blue) fades', async () => {
const { overMix, SHADE_GLSL } = await import('../js/shading.js');
const white = [0.94, 0.94, 0.94], river = [0.2, 0.4, 0.8], grass = [0.3, 0.45, 0.25];
const a = overMix(river, white, 0.5), b = overMix(grass, white, 0.5);
const spread = c => Math.max(...c) - Math.min(...c);
assert.ok(spread(a) < 0.12, `river under a white over-layer stays nearly grey: ${a}`);
assert.ok(Math.abs(a[2] - b[2]) < 0.12, 'river no longer stands out as blue');
assert.deepEqual(overMix(river, white, 0).map(v => +v.toFixed(6)), river);
const full = overMix(grass, [0.08, 0.47, 0.7], 1);
assert.ok(full[2] > full[0] + 0.3, 'at full opacity the over colour shows, lit by the base');
assert.match(SHADE_GLSL, /vec3 overColor\(vec3 c, vec3 o, float k\)/);
assert.match(SHADE_GLSL, /overColor\(c, texture2D\(map2, uv\)\.rgb, mix2\)/);
});