48 lines
1.3 KiB
GLSL
48 lines
1.3 KiB
GLSL
// Copyright (c) 2025 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "../../../../dusk/overworld/overworlddefs.h"
|
|
#include "../fragments/packed.glsl"
|
|
#include "../fragments/quad.glsl"
|
|
#include "../data/tilesets.glsl"
|
|
|
|
struct Entity {
|
|
uvec4 position;
|
|
};
|
|
|
|
layout(std140) uniform b_Entities {
|
|
Entity entities[OVERWORLD_ENTITY_COUNT_MAX];
|
|
};
|
|
|
|
vec2 entityGetSize() {
|
|
return vec2(float(OVERWORLD_ENTITY_WIDTH), float(OVERWORLD_ENTITY_HEIGHT));
|
|
}
|
|
|
|
vec2 entityGetVertice(uint instanceIndex, uint indiceIndex) {
|
|
// Get base quad vertice
|
|
vec2 vert = quadGetVertice(indiceIndex);
|
|
|
|
uint x = packedGetU8(0u, entities[instanceIndex].position);
|
|
uint y = packedGetU8(1u, entities[instanceIndex].position);
|
|
int subX = packedGetI8(2u, entities[instanceIndex].position);
|
|
int subY = packedGetI8(3u, entities[instanceIndex].position);
|
|
|
|
vert.x += float(x);
|
|
vert.y += float(y);
|
|
|
|
vert *= entityGetSize();
|
|
|
|
vert.x += float(subX);
|
|
vert.y += float(subY);
|
|
|
|
return vert;
|
|
}
|
|
|
|
vec2 entityGetUV(uint instanceIndex, uint indiceIndex) {
|
|
uint frame = packedGetU8(4u, entities[instanceIndex].position);
|
|
vec4 tilesetUVs = tilesetGetUVsByIndex(uint(TILESET_SLOT_ENTITIES), frame);
|
|
vec2 uv = quadGetTextureCoordinate(indiceIndex, tilesetUVs);
|
|
return uv;
|
|
} |