I have an SSBO that contains a list of structs that contain both integers and vec3s as you can see below. I am using OpenTK for the C# opengl bindings.
struct BVHNode {
vec3 AABBMin;
int Child1;
vec3 AABBMax;
int Child2;
int SplitAxis;
int NumTriangles;
int TriangleOffset;
int ParentIndex;
};
layout(std430, binding=6) buffer BVHSSBO {
BVHNode BVHNodes[];
} bvhSSBO;
The buffer is populated like this:
var gpuNodes = new Vector4[...];
...
GL.NamedBufferStorage(_bvhBufferHandle, bvhBufferSize, IntPtr.Zero, BufferStorageMask.DynamicStorageBit);
GL.BindBufferRange(BufferTargetARB.ShaderStorageBuffer, 6, _bvhBufferHandle, IntPtr.Zero, bvhBufferSize);
GL.NamedBufferSubData(_bvhBufferHandle, IntPtr.Zero, bvhBufferSize, gpuNodes);
The problem is that these integers get transformed into their floating point binary representation which is then converted back to integer.
The number in the screenshot should be equal to 1, but its 1065353216
, which is 111111100000000000000000000000
in binary, converting this back to decimal as IEE754 float yields 1.0
.
If I change the type of these numbers in my shader to float, the numbers are correct but when I want to use them as indices for an array I have to do int(x)
every time.
The only way I can get the integers to work is by changing the type of gpuNodes
to Vector4i
instead of Vector4
, but this way the vector3's don't work.
How do I get the correct numbers when leaving the type at int?