XNA – Compile for Pixel Shader 3.0

The default shader model for XNA 4.0 is 2.0. There are a number of limitations to this, the most significant is that you’re limited to 64 instructions slots.

Since pixel shader 3.0 is available in XNA 4.0 (and will run on the Xbox 360), you may decide to simply alter your pass technique as follows:


technique Technique1
{
pass Pass1
{
//PixelShader = compile ps_2_0 PixelShaderFunction();
PixelShader = compile ps_3_0 PixelShaderFunction();
}
}

The problem is that the default Vertex Shader is already compiled to the 2.0 shader model, and you can’t mix your shader models. What you need to do instead is add a default vertex shader and compile it in 3.0. You can find the following example on the XNA forums:


float4x4 MatrixTransform;

void SpriteVertexShader(inout float4 vColor : COLOR0, inout float2 texCoord : TEXCOORD0, inout float4 position : POSITION0)
{
position = mul(position, MatrixTransform);
}

Putting it all together, you’ll get something that looks like this:

1 comment on “XNA – Compile for Pixel Shader 3.0

Leave a Reply to Realtime Ray Tracing on Xbox360 via HLSL, XNA, C# Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.