Creating a grid (and Z-buffering)

Oct 9, 2010 at 2:26 AM

Just wanted to say thanks for making this.  What a fantastic project!

My question is:  I'm trying to display a large wireframe grid, that also intersects objects in my scene.  The objects are all Balder primitives, such as cylinders.  I can do this using a HeightMap and changing the material so it shows the wireframe and isn't solid, and this works.  But the downside is that the heightmap is all triangles, and I really want my grid to be a grid of squares.  So then I tried making my own grid geometry.  I followed the programmatic example in the tutorials and added a 20x20 grid of vertices with lines to connect them up.  This renders fine, but what I'm finding is that it always shows up behind my primitives, even when it intersects them.  Does Z-buffering only apply to faces, and not lines?  I'm using 8.8.9.


Oct 9, 2010 at 7:30 AM

Hi and thanks,

I'm afraid Z buffering has not been implemented yet for lines. In fact, its one of those things I keep forgetting to create. I'll add a work item for it, so it won't be forgotten.

Oct 9, 2010 at 7:31 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Oct 15, 2010 at 9:53 PM

Z buffering is now implemented :

Nov 16, 2010 at 1:52 AM

Okay, I think we figured out why z-buffering isn't working for lines.  The code that draws line pixels to the framebuffer is checking the z-buffer, but not writing back to the z-buffer.  In the file Source\Balder\Rendering\Silverlight\Shapes.cs, you should add the highlighted code to the DrawLine method:

var bufferOffset = (stride * (int)currentY) + (int)currentX;
var bufferZ = (UInt32)((1.0f - (currentZ*viewport.View.DepthMultiplier)) * (float)UInt32.MaxValue);
if (bufferZ > depthbuffer[bufferOffset] &&
currentZ >= viewport.View.Near &&
currentZ < viewport.View.Far
depthbuffer[bufferOffset] = bufferZ; // Add this to enable z-buffering on lines
framebuffer[bufferOffset] = color;
Nov 16, 2010 at 6:48 AM

Ok. Embarrassing. :)

Thanks for finding it, I'll fix it in the main repo later tonight. 

Nov 16, 2010 at 8:44 PM

Fixed :