Refine constellation artwork rendering
This commit is contained in:
parent
16dfd792ce
commit
3619d9ca0b
1 changed files with 29 additions and 6 deletions
|
|
@ -1224,10 +1224,33 @@ if (typeof CONSTELLATIONS !== 'undefined') {
|
||||||
for (const constellation of CONSTELLATIONS) {
|
for (const constellation of CONSTELLATIONS) {
|
||||||
if (!constellation.art) continue;
|
if (!constellation.art) continue;
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => projectSky();
|
const entry = { img, render: null };
|
||||||
|
img.onload = () => {
|
||||||
|
/* Os originais usam preto como transparência. Convertê-lo em alpha
|
||||||
|
evita que a transformação afim revele os limites retangulares. */
|
||||||
|
const out = document.createElement('canvas');
|
||||||
|
out.width = constellation.art.size[0];
|
||||||
|
out.height = constellation.art.size[1];
|
||||||
|
const oc = out.getContext('2d', { willReadFrequently: true });
|
||||||
|
oc.drawImage(img, 0, 0, out.width, out.height);
|
||||||
|
const pixels = oc.getImageData(0, 0, out.width, out.height);
|
||||||
|
for (let i = 0; i < pixels.data.length; i += 4) {
|
||||||
|
const r = pixels.data[i], g = pixels.data[i + 1], b = pixels.data[i + 2];
|
||||||
|
const light = Math.max(r, g, b);
|
||||||
|
const mask = Math.max(0, Math.min(1, (light - 9) / 118));
|
||||||
|
pixels.data[i] = 105 + light * 0.42;
|
||||||
|
pixels.data[i + 1] = 175 + light * 0.27;
|
||||||
|
pixels.data[i + 2] = 235 + light * 0.08;
|
||||||
|
pixels.data[i + 3] = pixels.data[i + 3] * mask;
|
||||||
|
}
|
||||||
|
oc.clearRect(0, 0, out.width, out.height);
|
||||||
|
oc.putImageData(pixels, 0, 0);
|
||||||
|
entry.render = out;
|
||||||
|
projectSky();
|
||||||
|
};
|
||||||
img.onerror = () => console.error('[skeledance] falha na arte de ' + constellation.name);
|
img.onerror = () => console.error('[skeledance] falha na arte de ' + constellation.name);
|
||||||
img.src = constellation.art.file;
|
img.src = constellation.art.file;
|
||||||
constellationArtImages.set(constellation.id, img);
|
constellationArtImages.set(constellation.id, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const VIEW_AZ = 90; // centro da tela olha para o LESTE — a tela física do
|
const VIEW_AZ = 90; // centro da tela olha para o LESTE — a tela física do
|
||||||
|
|
@ -1435,8 +1458,8 @@ function constellationArtTransform(source, target) {
|
||||||
|
|
||||||
function drawConstellationArt(c, constellation, lst, W, horizonPx) {
|
function drawConstellationArt(c, constellation, lst, W, horizonPx) {
|
||||||
const art = constellation.art;
|
const art = constellation.art;
|
||||||
const img = constellationArtImages.get(constellation.id);
|
const imageEntry = constellationArtImages.get(constellation.id);
|
||||||
if (!art || !img || !img.complete || !img.naturalWidth) return;
|
if (!art || !imageEntry || !imageEntry.render) return;
|
||||||
|
|
||||||
const target = art.anchors.map(anchor => {
|
const target = art.anchors.map(anchor => {
|
||||||
const aa = altAz(anchor.sky[0], anchor.sky[1], lst);
|
const aa = altAz(anchor.sky[0], anchor.sky[1], lst);
|
||||||
|
|
@ -1459,9 +1482,9 @@ function drawConstellationArt(c, constellation, lst, W, horizonPx) {
|
||||||
c.rect(0, 0, W, horizonPx);
|
c.rect(0, 0, W, horizonPx);
|
||||||
c.clip();
|
c.clip();
|
||||||
c.globalCompositeOperation = 'screen';
|
c.globalCompositeOperation = 'screen';
|
||||||
c.globalAlpha = 0.19;
|
c.globalAlpha = 0.24;
|
||||||
c.setTransform(...matrix);
|
c.setTransform(...matrix);
|
||||||
c.drawImage(img, 0, 0, art.size[0], art.size[1]);
|
c.drawImage(imageEntry.render, 0, 0, art.size[0], art.size[1]);
|
||||||
c.restore();
|
c.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue