To start with my main question:
Can I use pixel shader model 3, 4 or 5 in my FireMonkey applications?
I want to be able to dynamically create pixel shaders in my FireMonkey program. To do that, I now compile a pixel shader using fxc.exe that comes with the DirectX SDK, and load the compiled code into my TShaderFilter descendant. That works fine (let me know if you're interested in how I do that).
However, I can only get things to work if I compile with ps_2_0
as a target profile.
I'm currently running into limitations of shader model 2.0. For example loops seem to be unrolled by the compiler, and there's a maximum number of instructions that you can have in level 2 shaders. Because of that, the number of possibilities are pretty limited.
Example:
The shader code below creates a mandelbrot fractal. If I set Iterations
too high, it doesn't compile. Error message:
error X5608: Compiled shader code uses too many arithmetic instruction slots (78). Max. allowed by the target (ps_2_0) is 64.
#define Iterations 12
float2 Pan;
float Zoom;
float Aspect;
float4 main(float2 texCoord : TEXCOORD0) : COLOR0
{
float2 c = (texCoord - 0.5) * Zoom * float2(1, Aspect) - Pan;
float2 v = 0;
for (int n = 0; n < Iterations; n++)
{
v = float2(v.x * v.x - v.y * v.y, v.x * v.y * 2) + c;
}
return (dot(v, v) > 1) ? 1 : 0;
}
With shader model ps_3_0 I can compile with more iterations, but the compiled shader doesn't seem to work in FireMonkey. I don't get any error message; I just get a red image as a result.
Does anyone here have any idea on how to get around this, or is FireMonkey just not capable of utilizing the full potential of my graphics card?
Note, I've seen that the minimum requirement for FireMonkey is a graphics card with shader level 2.0, but it's not clear if that means you cannot use shader level 3 or higher.