I’ve been working on a simple voxel raymarcher in OpenGL. I’ve got a pretty crude system of passing the center positions of my voxels to the fragment shader through the use of Buffer Textures. My main problem is rendering them properly. Rendering a single voxel is fast and works well, but I want to render multiple. I couldn’t find much online so I came up with this system:
fragment.glsl
...
float map(in vec3 rayPos)
{
float result = 0;
for (int i = 0; i < 81; i+=3)
{
vec3 pos = vec3(
texelFetch(voxelData, i).x,
texelFetch(voxelData, i+1).x,
texelFetch(voxelData, i+2).x
);
if (i == 0)
{
result = Box(rayPos, vec3(VOXEL_SIZE), pos);
}
else
{
result = min(Box(rayPos, vec3(VOXEL_SIZE), pos), result);
}
}
return result;
}
...
Of course, there are a LOT of optimizations to be made, but at the moment, I’m trying to draft up the basic systems. This code is responsible for displaying a 3x3x3 grid of voxels. It runs terribly but I can’t figure out why. There is definitely a better way to do this but I don’t know how.