Jump to content
  • Advertisement
Sign in to follow this  
Deliverance

Voxelization by slicing and geometry instancing

This topic is 2950 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to figure out if this is possible. I'm doing some voxelization work of water-tight meshes using the simplest algorithms i found out there. It works by rendering to a 3D texture, a slice per frame. The mesh to be voxelized is rendered N times, where N is the resolution of the volume texture.
Every frame I setup an ortographic projection with the near plane at

currentSlice / (N-1) * (ObjectAABBMaxZ-ObjectAABBMinZ) + ObjectAABBMinZ,
0 <= currentSlice < N


and the far plane at infinity(a big value).

I render the model with two sided stencil incrementing for front faces and
decrementing for back faces, both with wrap, with stencil testing set to GL_ALWAYS. I then render a full screen quad with stencil testing set to GL_NOTEQUAL to 0.

This way i obtain a solid voxelization of the model. The problem is it's kind of slow, i render the model N times and i'm trying to figure out if i can use geometry instancing to speed things up! I'm a complete noob when it comes to this part, i never did instancing before but i think i figured most of the things up except one.

As far as i read, i get a 32 bit integer representing the intanceID in the vertex shader. I could use this to transform the vertices with different ortographic matrices, to take into the znear for every slice.

The problem is that in the non-instanced version i use a framebuffer for rendering to a 3D texture and bind the volume texture's slice every frame. I cannot understand how to do this when rendering with geometry instancing, though.

Am i right so far? What can i do to render with instancing to the 3D texture?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Deliverance
This way i obtain a solid voxelization of the model. The problem is it's kind of slow, i render the model N times and i'm trying to figure out if i can use geometry instancing to speed things up! I'm a complete noob when it comes to this part, i never did instancing before but i think i figured most of the things up except one.

To be honest, I don't believe that the vertex shader or the number of render calls is your bottleneck. I think that you are pixelbound, so decreasing the number of render calls and vertex fetches will not help.

Quote:
Original post by Deliverance
The problem is that in the non-instanced version i use a framebuffer for rendering to a 3D texture and bind the volume texture's slice every frame. I cannot understand how to do this when rendering with geometry instancing, though.

Try to "unwrap" your 3d volume to a 2d texture by placing the slice on a single texture. Then calculate for each instance a offset which will be used in your vertex shader to shift your model to the according portion of the 2d texture.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ashaman73
Try to "unwrap" your 3d volume to a 2d texture by placing the slice on a single texture. Then calculate for each instance a offset which will be used in your vertex shader to shift your model to the according portion of the 2d texture.


Thanks, that sounds like a really neat idea!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!