Darkphibre

When I deployed to the 360, I found that Vector4 textures are not supported as a render target, and that only one render target is supported at a time. I've refactored my code such that it uses four R32Fs and one render target, and this runs fine on my PC. But when deploying to the 360 I ran into another problem; GetData after GetTexture is returning completely wrong information.
 
The thing is... even this simplified pixel shader returns NaN on 360!
        float4 Test() : COLOR0 {return (float4).25;}
But it returns .25 for on the PC.

How I'm calling it:
this.GraphicsDevice.SetRenderTarget(0, null);
this.GraphicsDevice.SetRenderTarget(0, rt[Offset + 0]);
currentEffect.Begin();
currentEffect.Techniques[
"Particle"].Passes["UpdateParticleLX"].Begin();
this.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, this.VertCount, 0, this.PrimitiveCount);
currentEffect.Techniques[
"Particle"].Passes["UpdateParticleLX"].End();
currentEffect.End();
this.GraphicsDevice.ResolveRenderTarget(0);
ParticleLocation[0] = rt[Offset + 0].GetTexture();

Debug of GetData on the PC shows:
0.2500,0.2500 0.2500,0.2500
0.2500,0.2500 0.2500,0.2500
0.2500,0.2500 0.2500,0.2500
...

XBox shows:
NaN,NaN NaN,NaN
NaN,NaN NaN,NaN
NaN,NaN NaN,NaN
...



Re: XNA Framework Render Target returns NaN on 360, not on PC

Shawn Hargreaves - MSFT

For what it's worth, I wrote a simple program that renders to a floating point target and then uses GetData to read back the results, and that seems to be working ok for me.

Using this effect:

 float4 PixelShader() : COLOR0
{
return float4(23, 42, 0.5, -1);
}

technique
{
pass
{
PixelShader = compile ps_2_0 PixelShader();
}
}

This program code:

 using (RenderTarget2D rt = new RenderTarget2D(device, 32, 32, 1, SurfaceFormat.Single))
{
device.SetRenderTarget(0, rt);

using (SpriteBatch sprites = new SpriteBatch(device))
{
sprites.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
effect.Begin();
effect.CurrentTechnique.Passes[0].Begin();

sprites.Draw(texture, Vector2.Zero, Color.White);

sprites.End();
effect.CurrentTechnique.Passes[0].End();
effect.End();
}

device.ResolveRenderTarget(0);
device.SetRenderTarget(0, null);

float[] results = new float[rt.Width * rt.Height];

rt.GetTexture().GetData(results);

foreach (float result in results)
Trace.WriteLine(result);
}

Prints the expected results. Vector2 format rendertargets also work correctly, but (as expected) trying to use a Vector4 format throws an exception when creating the rendertarget, due to that format not being supported.