I've been working on a toughy project that calls for rotation the entire screen at runtime; a 512x512 texture (as viewed in a 362x362 box circumscribed inside). The single continuing problem thats been holding us back has been slowdown on some peoples machines- I can't get it to run a uniform 50 FPS on everyones computers. Over the past week, simple optimizations to the pixel shader have brought me up from 49 FPS to 56 FPS on my own system (an edited copy of the one sphax posted, which converts it to polar coordinates and back, as seen here):
// Pixel shader input structure
struct PS_INPUT
{
float4 Position : POSITION;
float2 Texture : TEXCOORD0;
};
// Pixel shader output structure
struct PS_OUTPUT
{
float4 Color : COLOR0;
};
// Global variables
sampler2D Tex0;
float fAngle;
PS_OUTPUT ps_main( in PS_INPUT In )
{
// Output pixel
PS_OUTPUT Out;
In.Texture.x = In.Texture.x-0.5;
In.Texture.y = In.Texture.y-0.5;
fAngle = radians(fAngle);
float Ray = sqrt(pow(In.Texture.x,2)+pow(In.Texture.y,2));
float Angle = acos((In.Texture.x) / Ray) * sign(In.Texture.y) + fAngle;
In.Texture.x = 0.5 + cos(Angle)*Ray;
In.Texture.y = 0.5 + sin(Angle)*Ray;
Out.Color = tex2D(Tex0, In.Texture.xy);
return Out;
}
// Effect technique
technique tech_main
{
pass P0
{
// shaders
VertexShader = NULL;
PixelShader = compile ps_2_0 ps_main();
}
}
Display More
But some people still get FPS around 25-30 on their system, which would render my game unplayable. So what I've been searching for is alternative means of doing the rotation calculations. Carrying out 512x512x50 square roots & arccosines per second is a serious load in the first place, and the inefficiency of HLSL complicates that. I've attempted the simple things like using Distance(a,b) instead of that sqrt(etc), but it still comes out the same.
Anyone know a better way to do this? I know that D3DX has matrix rotation vertex shaders built into it which should be many times more efficient (assembly code and optimized), but I don't think theres any way for MMF2 to support vertex shaders in the first place, is there? Otherwise I'm at a loss for the moment. If there is, please do tell!
Anyway, for anyone who this came off as a bunch of gibberish to, you can actually help me too- if you've got the time, just take a peek at my project and tell me what FPS you get on your machine / graphics card:
Please login to see this link.
and much thanks to sphax of course