thanks for the response.
Kenneth Gorking said:
1. Functions are always inlined. I think there has been some talk about allowing actual 'call' opcodes for GPU's, but I do not know if they exist yet.
Yeah, I kind of worded that funny. What I meant was...
OUTPUT CameraPS( INPUT IN )
{
OUTPUT OUT;
OUT.color = find_color(input stuff goes here) ;
return OUT;
}
float4 find_color(input stuff)
{
do calculations;
return calculations;
}
That's a more literal translation of what I meant. It never goes out of the shader, it just goes out of what would be considered Main().
Kenneth Gorking said:
2. It pretty much depens on what you are doing, but for the example you described, the first option will be faster because it only results in one texture lookup to get the normal. Just keep in mind, that you want to keep your shaders as simple as possible while still getting the job done.
I was really more wondering about the multi vs single pass lighting. I experimented a while back with a fairly small scene. One method used 3 lights in the same pixel shader making no repeat calculations. The other method redrew the polygons 3 times. The visual results were the same, but the multipass version ran almost 3x faster. I'm just convinced I'm doing something wrong with that. It doesn't make a bit of sense.
Kenneth Gorking said:
For large scenes, you can do a depth-first pass, which just lies down the depth. Then in the following passes you can execute whatever shader you want, and because of the depth-first pass, only pixels that are visible will be evaluated.
wait... do you mean rendering the depth (z-write) to the main render target (or back buffer I guess), then just drawing over it with subsequent passes? There's no shader work involved right? That's pretty clever :D
Kenneth Gorking said:
3. Branching in shader code is costly, because the GPU processes multiple pixels at once. If just one of these takes the 'if' branch, all the other processors has to wait for it to finish before they can continue.
but that's the thing, there's no way that any are supposed to execute the compicated path at all. The way I disable it is:
bool complex;
OUTPUT CameraPS( INPUT IN )
{
OUTPUT OUT;
if (complex == true)
{
do complex things
}
do regular things;
return OUT;
}
and I enable/disable it through the application via Effect->SetBool() and change it per object. I thought that may have been the problem but I left it off totally and no different results. :(