Hello,
I am currently trying to do a 3D rasterization. To perform that, I have a framebuffer object in which I write the result. The attachment of this framebuffer object is an 2D integer texture(GL_RGBA32UI to be exact). For this framebuffer, I enable the logical operation OR.
My glsl program computes for each fragment its depth and compute the channel and a mask in order to set the matching bit to 1. To sum up, I set a bit to 1 if a 3D pixel, or voxel, is present at the corresponding depth,normalized between 0 and 128, and at the coordinates x and y of the fragment.
My problem is that when two voxels are in the same channel, the logical operation seems to not working, and I get value which not match with I expect. If two voxels are in different channel, everythings work fine. I suspect that the logical operation is performed on the floating representation of my “colors”, which lead to crazy values.
If that can help, there is my glsl frament code(vertex and geometry are standard ones) :
#version 330 compatibility
#extension GL_EXT_gpu_shader4 : enable
void main()
{
uint channel_number; // r or g or b or a
uint shift; // to shift the bit of the mask
num_image = 0x00000000u;
num_channel = uint(gl_FragCoord.z * 127u) / 32u;
bit_a_setter = uint(gl_FragCoord.z * 127u) % 32u;
uint mask = 0x00000001u << shift; // mask creation by bit shifting
uvec4 finalColor = uvec4(0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u);
finalColor[num_channel] = mask; // channel affectation
// The logical operation "or" is enabled. So, OpenGl will perform the operation between two overlaid fragments
gl_FragData[0] = finalColor;
}
Sorry, for the “old school” aspect of the glsl fragment program, I develop this only as part of tests.
Thanks,
Fabien MATHIEU