27 lines
2.0 KiB
GLSL
27 lines
2.0 KiB
GLSL
// The loaded biome areas (host: composeRegion in main.cpp). One record of 16 words per area after the 8 word header, then the tile map (biome-map tile -> area + 1).
|
|
// header (8 words): [0] area count, [1] tile map offset, [2] tile map width, [3] tile map height, [4] offset of the per-tile topology record offsets, [5] world seed, [6] x offset of the gradient noise (float)
|
|
// record: [0] origin x, [1] origin y (world cell at the centre of wang pixel (0,0)), [2] wang width, [3] wang height, [4] offset in the solidity plane, [5] offset in the material plane,
|
|
// [6] scene x0, [7] scene y0, [8] scene width, [9] scene height, [10] offset of the chunk table of the scene planes (materials, visuals, backgrounds; chunks of 64 x 64 cells, absolute index of the chunk or 0xFFFFFFFF), [11] offset of the background tile,
|
|
// [12] background width, [13] background height, [14] offset of the biome's <Materials> list, [15] its component count
|
|
layout(std430, set = 0, binding = 43) readonly buffer AreaTab { uint atab[]; };
|
|
|
|
int arec(int a, int k) { return int(atab[8 + 16 * a + k]); }
|
|
|
|
// The area of the biome-map tile that holds the world cell, -1 when none is loaded.
|
|
int area_of(ivec2 w) {
|
|
int tx = (w.x >= 0 ? w.x / 512 : -((-w.x + 511) / 512)) + 35;
|
|
int ty = (w.y >= 0 ? w.y / 512 : -((-w.y + 511) / 512)) + 14;
|
|
if (tx < 0 || ty < 0 || tx >= int(atab[2]) || ty >= int(atab[3])) return -1;
|
|
return int(atab[atab[1] + uint(ty) * atab[2] + uint(tx)]) - 1;
|
|
}
|
|
|
|
// Index of a world cell in the scene planes of area a, -1 when the cell is outside that area's planes.
|
|
int scene_index(int a, ivec2 w) {
|
|
ivec2 sc = w - ivec2(arec(a, 6), arec(a, 7));
|
|
if (sc.x < 0 || sc.y < 0 || sc.x >= arec(a, 8) || sc.y >= arec(a, 9)) return -1;
|
|
int cw = (arec(a, 8) + 63) >> 6;
|
|
uint ct = atab[uint(arec(a, 10) + (sc.y >> 6) * cw + (sc.x >> 6))]; // scene planes are stored in chunks of 64 x 64 cells
|
|
if (ct == 0xFFFFFFFFu) return -1;
|
|
return int(ct) + ((sc.y & 63) << 6) + (sc.x & 63);
|
|
}
|