Instanced spheres

Oct 11, 2010 at 5:21 AM

I've gone dain bramaged.

I just put together a simple scene that draws a ring of 12 spheres using a Xen.ExGeometry.Sphere, and a MaterialShader.  At least that's what I thought I was doing.  The scene has an array of 12 Matrix objects: each of them is created with Matrix.CreateTranslation().  My Draw method just sets the state's shader to the material shader, and then I call sphere.DrawBatch( state, matrices, matrices.Length);

And what happens is the spheres are *scaled* as well as translated according to its the translation matrix.

But then I saw in Tutorial 16 that the MaterialShader's 'UseHardwareInstancing' property has to be set to true.  And the only difficulty with that is there's no 'UseHardwareInstancing' property in the MaterialShader.

Is this one of those breaking changes in Xen 2.0, or am I missing something simple and obvious?

Oct 16, 2010 at 3:50 AM

Well, as an interim, I've been using the Tutorial16 shader to draw a solid colour on my batch objects, but I think I found a bug...

If I draw *two* batches in the same frame, I get an exception at Vertices.cs, line 243: 

 

((

DynamicVertexBuffer)target).SetData(start, data, startIndex, length, Stride, setOp);



This parameter must be a valid index within the array.
Parameter name: elementCount

For my first batch (of 12 spheres), startIndex is 0; for my second batch, it's 12.  I'm guessing there's a buffer being reused that holds some state which only gets cleared once per frame, but that's just a guess.

Oct 16, 2010 at 3:54 AM

Incidentally, I did read your post that curerntly in Xen 2.0 instancing is broken, but I wasn't sure if that was *just* for the Xbox or it was just broken in general.  I'm on Xen 2.0 but only targetting Windows for the moment.  Reporting the bug more to capture it just in case the issues you're dealing with on the 360 are lower level.  I haven't tried to reproduce this in Xen 1.8 yet.