Only quad coords

mail@pastecode.io avatar
unknown
glsl
a month ago
1.2 kB
8
Indexable
Never
#version 460 core

flat out uint fragSharedData;
...
...

layout (std140, binding = 0) uniform CameraUBO {
    ivec3 voxelPos;
    mat4 projViewMatrix;
} camera;

layout(std430, binding = 1) buffer chunkDataSSBO {
    int chunkData[];
};

layout(std430, binding = 0) buffer quadDataSSBO {
    uint quadData[];
};

...
...
...

void main(void) {
	...
	...
	...
	
	uint quadData1 = quadData[quadIndex];

	uint chunkIndex = (gl_BaseInstance >> 3) * 24;
	ivec3 chunkPos = ivec3(chunkData[chunkIndex], chunkData[chunkIndex + 1], chunkData[chunkIndex + 2]);
	int layer = chunkData[chunkIndex + 3];
	
	ivec3 localQuadCoords = (ivec3(quadData1, quadData1 >> 6u, quadData1 >> 12u) & 63) << layer;
	ivec3 quadCoords = localQuadCoords + chunkPos - camera.voxelPos;

	int faceDir = gl_BaseInstance & 7;

	int wDir = ~faceDir & 2, lDir = (~faceDir >> 2) & 1;
	int wMod = vertexID >> 1, lMod = vertexID & 1;
	int quadWidth = int((quadData1 >> 18u) & 63) << layer;
	int quadLength = int((quadData1 >> 24u) & 63) << layer;

	quadCoords[wDir] += quadWidth * wMod * 2;
	quadCoords[lDir] += quadLength * lMod * 2;
	
	gl_Position = camera.projViewMatrix * vec4(quadCoords, 1.0);

	...
	...
	...
}
Leave a Comment