This project is read-only.

Bug - SolidColourElement drawing behind all 3D objects

Oct 30, 2010 at 1:27 AM

Xen 2.0, Windows build (can't test Xbox yet), DrawAtMaxZ property = false

Tutorial 15 draws the embedded SolidColouredElement (the red square that fades in and out) in front of the 3D geometry in Xen 1.8, behind it in Xen 2.0.  The yellow element its embeeded into (the TextElement) stays in front of the 3D geometry in both versions.

A quick check with PIX shows there's nothing happening to turn off depth testing preceding the SolidColouredElement DIP call.  The draw code in Element doesn't look like its changed:  I need to switch partitions to check how depth testing was manipulated in 1.8...

Oct 30, 2010 at 6:21 AM

Woah, weirdness.  On my Vista 64 partition, and Xen 2.0 compiled with (I think) VS2008. there's no issue, depth testing is turned off by the TextElement and stays off for the SolidColouredElement.  Win7 64, Xen 2.0 compiled with VS2010, same DirectX libraries, there's no ZTestEnalble = false anywhere.  So the SolidColouredElement fails the Z test.

Another thing I noticed is that the Text renders fine because it's using a different shader.  InstancingSprite looks like it's only setting x and y, and z and w are defaulted to 0. 

SimpleVS is drawing with Z = 1.0, even though the DrawAtMaxZ property is false (ElementRect sets Z=1.0 explicitly, and uses a displayMatrix that retains the Z coordinate unchanged.)

Did it do that before?  Well, I haven't found what if anything is different in the code.  I suppose it's possible I downloaded a very early version of Xen 2.0 for Vista, andwhen I downloaded Xen 2.0 again for my Win7 partition there had been a few changes that prevented the ZEnable-false command from being issued.

Oct 30, 2010 at 7:47 AM

Got it.  State has been heavily revised in the version of Xen 2.0 I have on Win7.

In Element.cs, line 255, (Element.Draw) you set the DepthWrite and DepthTest to false.  Later in the same method, line 276, you create a new StencilState, and at line 322 you assign it to the CurrentStencilState.  Problem with that is that the DepthState byte is zero'd out in a new StencilState (it's byte 8 of the 8 byte stencil state)  So after line 322, DepthWrite and DepthTest are set back to true, and SolidColouredElements are depth tested and fail if any geometry is drawn in the same pixels because their verts will always have Z=1 (unless there's some way to adjust their depth that I haven't seen) 

And again, TextElements don't exhibit the same behaviour because the shader they're using only uses the x and y values of the position element of their verts.

Oct 31, 2010 at 10:53 PM
Edited Oct 31, 2010 at 11:11 PM

It sounds like there is still something messed up. The state bitpacking was badly broken in the first beta of xen 2, and I've fixed this up a lot - especially on the 360. But it's quite likely it's still messed up.

The state structures no longer overlap in beta 2 (I admit, that was kinda silly). However they are internally compared in a semi-overlapped way, which is all some internal weirdness to get around some of the odd ways XNA structures it's state objects (for example, colour channel masks are in the blend state, etc).

Thanks for pointing these things out

Nov 1, 2010 at 3:24 AM

Whoops, my mistake.  There must have been a few versions of Xen 2.0.  I definitely missed the fact that you'd upreved to b2.  I just tested it and it's working fine out of the box.