Quote: "I suppose that I could check all lines in my shader and see what could be simplified."
You could - but unless you've done something obviously wasteful my experience is that it is hard to fool the FX compiler. It already has an optimiser built into it - it can detect some things which are unnecessary and changes the compiled code accordingly.
Quote: "Another method would be to use more then one pass if I'm not mistaken."
Yes - that's often used for things like adding several lights.
Quote: "How could I do that?"
Look for parts of the code where several things have been added together to give the final colour (such as lights). Put some in one pass and the rest in another. If you mean "how do I set up the shader with several passes?" then it would look something like the following:
< usual declarations at the beginning >
VSOutput1 VShaderPass1(VSInput1 In, VSOutput1)
{ <various vertex shader code lines for first pass>
}
VSOutput2 VShaderPass2(VSInput2 In, VSOutput2)
{ <various vertex shader code lines for second pass>
}
PSOutput PShaderPass1(PSInput1 In, PSOutput)
{ <various pixel shader code lines for first pass>
}
PSOutput PShaderPass2(PSInput2 In, PSOutput)
{ <various pixel shader code lines for second pass>
}
technique twoPasses
{ pass p1
{ vertexShader = compile vs_2_0 VShaderPass1();
pixelShader = compile ps_2_0 PShaderPass1();
}
pass p2
{ vertexShader = compile vs_2_0 VShaderPass2();
pixelShader = compile ps_2_0 PShaderPass2();
}
}
It isn't essential to have different vertex or pixel shaders - for example in some applications you could use the same ones but called with different arguments, or in another you might use the same vertex shader code. Similarly, you might have the same input and output structures.
If you are adding several things together then you need to add the following lines to the second and subsequent pass blocks:
alphablendenable = true;
blendOp = add;
srcBlend = one;
destBlend = one;
as in the following simple example:
matrix wvp : WorldViewProjection;
struct VSInput
{ float4 pos : position;
};
struct VSOutput
{ float4 pos : position;
};
VSOutput VShader(VSInput In, VSOutput Out)
{ Out.pos = mul(In.pos, wvp);
return Out;
}
struct PSOutput { float4 col : color; };
PSOutput PShader1(PSOutput Out)
{ Out.col = float4 (1.0, 0.0, 0.0, 1.0); // pure red
return Out;
}
PSOutput PShader2(PSOutput Out)
{ Out.col = float4 (0.0, 1.0, 0.0, 1.0); // pure green
return Out;
}
technique t0
{ pass p1
{ VertexShader = compile vs_1_1 VShader();
PixelShader = compile ps_2_0 PShader1();
}
pass p2
{ VertexShader = compile vs_1_1 VShader();
PixelShader = compile ps_2_0 PShader2();
alphaBlendEnable = true;
blendOp = add;
srcBlend = one;
destBlend = one;
}
}
Before running the code see if you can work out what the final result should look like.
By the way, I'm aiming to put together a simple demo of the solution to the seam problem some time this weekend.