🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Voxelization without flickering

Started by
7 comments, last by dmmon01 3 years, 8 months ago

Hey. Im implementing some VCT in my OpenGL project and the first step that is needed - voxelization of course. But when i do it the naive way - everything flickers. So ive done color averaging - but using atomic operations for each pixel is VERY HEAVY. Do you know some other ways to voxelize the scene without flickering?

Thanks

Advertisement

not sure what u mean by “everything flickers”

however, there is a known issue of cracks which depends on your camera direction and the primitive's orientation being voxelized… it is resolved be swapping the x,y,z according to which axis you are projecting to; but this in turn will cause holes (because of pixels half centers not covered in rasterization), this in turn is resolved by conservative rasterization..

so what's yours ?

Until then ?

@ddlox thanks for reply. By ‘flickering’ i mean that because of voxels finite precision a lot of pixels fall in the same voxel and this results in flickering. For example we have 2 pixels - black and white. Because of parallelism i dont know which pixel will fill the voxel first - sometimes it's white, sometimes it's black. So thats why everything flickers (white and black).

I tried averaging pixels but as i said - atomic operations for every pixel is very heavy.

Thanks.

maybe yr voxelizer has problems with holes

try this voxer: https://github.com/karimnaaji/voxelizer​​ (only 1 header to include)

how to use:

//pseudo
#define VOXELIZER_IMPLEMENTATION
#include "voxelizer.h

vx_mesh_t* inputMesh = vx_mesh_alloc(num_verts, num_indices);

// Add vertices and indices from the original mesh you want to voxelize
 into inputMesh
for (...)
{
    inputMesh->vertices[0]->x,y,z .... = yourMesh[0]->verts
    inputMesh->indices[0]->x,y,z .... = ...


    ...


    
// Precision factor to reduce "holes" artifact
float precision = 0.01f;

// Run voxelization
vx_mesh_t* outputMesh = vx_voxelize(inputMesh, 
                                     0.03f, 
// this is voxel size in X axis
                                     0.03f, 
// size in y axis
                                     0.03f, 
// size in z
                                     precision);

// WARNING: outputMesh can have more verts than inputMesh so alloc space for new mesh with outputMesh->nvertices,normals etc... then fill in
for (...)
{
  yourNewMesh->verts[index] = outputMesh->vertices[index]
  ...

vx_mesh_free(output_mesh);
vx_mesh_free(input_mesh);

also it was written with ogl in mind, so verts winding may matter … I'll leave it for u as an exercise to work the verts winding out if u r using directx

See how it goes;

That's it … all the best ?

That still doesnt help… In addition link is not working. I just need an algorithm for voxelization without this artifact (flickering). Using fragment and geometry shader.

For me it sounds like issue with your shader as mentioned earlier.

Anyhow i am not familar with your voxelization concept so i cant actually help with that. You could describe the process you are using more preceisely , i know you want to voxelize the scene in gs. But how do you do that, i've done some ct imaging and for the most i used raytracing, if you mind showing what type of data are you passing and what you actually do with it in all shaders we might be able to help. If this is an app for.medical usage then its way more important that you describe everything so we can help make world better place ?

First of all you use atomic counters, so i imagine you need some kind of thread free fetaure that stalls whole pipeline…

strange about the broken link…it had extra characters i did not put in;

ok i've refreshed it, but yes this is a cpu-side voxer;

and yes u can do it in the geom shader:

  • find the center of each triangle: center = (tri.vert[0].position.xyz + …[1]… + …[2]…) / 3
  • u can now think of this center as the center of each voxel cube so u can create quads for each face of the cube using your voxel axis size
// pseudo somthing like this:
 vec3 (or float3 if hlsl) quad_v0;
  quad_v0.x = center.x - voxelSizeInX/2.0
  quad_v0.y = center.y - voxelSizeInY/2.0
  quad_v0.z = center.z + voxelSizeInZ/2.0
  
  vec3 quad_v1;
  quad_v1.x = center.x - voxelSizeInX/2.0
  ...1.y = ... + voxelSizeY/2.0
  ...1.z = ... + ...;

  do it for quad_v2 quad_v3
  then you can compute:
  - new normal 
  - new position
  - then emit vertex to pixel shader

best is you show us your current shaders and we can all see what is wrong with it (if at all, respectfully)

Until then ?

Thanks everybody for replies. To solve flickering i've moved my voxelization code completely to the geometry shader. Checked every intersection of voxel with triangle and filled it with color value which i got by projecting voxel center point on triangle.

I also used a smaller voxel grid (64 instead of 128). And now it runs 90-95 fps instead of 10-15!!! Improvement!

Ive used the following code snippet to solve flickering. (It averages all incoming colors that fall in same voxel)

while ( ( curStoredVal = imageAtomicCompSwap( imgUI , coords , prevStoredVal , newVal )) != prevStoredVal) {
	prevStoredVal = curStoredVal;
	vec4 rval = convRGBA8ToVec4( curStoredVal);
	rval . xyz =( rval . xyz* rval .w) ; // Denormalize
	vec4 curValF = rval + val; // Add new value
	curValF . xyz /=( curValF .w); // Renormalize
	newVal = convVec4ToRGBA8( curValF );
}

This topic is closed to new replies.

Advertisement