1
\$\begingroup\$

I have a couple of .fx files from a Shader-Based 2D Shadows example. I want to utilize the same kind of technique with XNA 4.0's Reach profile, which if I understand correctly needs to have HLSL 2.0 shaders. I am not familiar with shaders, so obviously I need to learn HLSL, but what I'm wondering right now is how to tell what shader code is 3.0 and what is 2.0, because I need to port those shaders to 2.0 and utilize them in my project. Can FX Composer be used to know such a thing?

A sub-question - Is it possible that they would not perform well when ported to 2.0? If I want to utilize a similar effect to what is presented in the link, do I need to bump my project up to the HiDef profile and use HLSL 3.0, or should I be able to get away with 2.0?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

The main differences between SM 2.0 and 3.0 are the instruction/register limits and the presence of vertex texture fetch functions (for accessing texture data from the vertex shader). Wikipedia has some nice tables with the capabilities of the different shader models.

The shaders in your link do exactly what you are trying to achieve; some are compiled for SM 2.0 and the main one is for 3.0. You can see it clearly at the end of the FX files:

technique Distort
{
    pass P0
    {          
        VertexShader = compile vs_2_0 FullScreenVS();
        PixelShader  = compile ps_2_0 DistortPS();
    }
}

technique DrawShadows
{
    pass P0
    {          
        VertexShader = compile vs_3_0 FullScreenVS();
        PixelShader  = compile ps_3_0 DrawShadowsPS();
    }
}

Seeing that the DrawShadows functions are quite lenghty, and knowing that Catalin Zima is an experienced XNA programmer (and MVP too), I'd say that you can't just force the shader to an inferior SM, probably because it surpasses the instruction limit. So you would need to learn some HLSL and strip the shader of unwanted functionality to cram it into SM 2.0 limits.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for the pointers. This definitely gets me started. \$\endgroup\$ Commented Nov 26, 2010 at 18:29
  • \$\begingroup\$ Change the 3_0 to 2_0 and see what breaks :) \$\endgroup\$ Commented Jan 7, 2011 at 14:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .