Let’s say I have this very simple pixel shader (cbuffers and other stuff omitted)
float4 PS(VertexOut pin, uniform bool useLighting) : SV_Target {
float4 retColor = gDiffuseMap.Sample( sampler0, pin.Tex );
if (useLighting) {
retColor = retColor * float4(gAmbientLight, 1.0f);
}
return retColor;
}
and two techniques such as
technique11 TexTech {
pass P0 {
SetVertexShader( CompileShader( vs_4_0, VS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader( ps_4_0, PS(false)));
}
}
technique11 TexLitTech {
pass P0 {
SetVertexShader( CompileShader(vs_4_0, VS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(ps_4_0, PS(true)));
}
}
The way I understand it, the useLighting
condition is evaluated during compile-time and each technique will have its own version of the pixel shader function without any branching. That means the useLighting
condition wouldn’t have any runtime penalties. Is that correct? So it’s kind of like C preprocessing?
Why can the pin
variable just be left out like that in the CompileShader call? It makes sense, of course, I’m just wondering if this is some special HLSL or Effect Framework syntax?