Hi,
I've been trying to use the VFACE semantic to get different shading on the front and back side of my geometry. According to the D3D documentation, VFACE should be positive for frontfacing triangles and negative for backfacing triangles (I guess it would be more concise to say counterclockwise and clockwise?). I got it working in most scenarios. Only when textures are involved, it seems to fail (more precisely: I've got a batch of tests, and only the ones with textures are failing. What happens is that only one side of the geometry gets shaded, or both sides get shaded with the same material). I've been trying to pinpoint the problem, but without succes. In the case where it works, I get shader assembly code like this:
ps_3_0
def c0, 0, 1, 0, 0
dcl vFace
0: cmp oC0.xz, vFace, c0.xyyw, c0.yyxw
1: mov oC0.yw, c0.xxzy
I don't know the instructions well, but this seems logical: in line 0 something different happens, based on the value of vFace. When I now take one of my shaders that use textures, I get this:
ps_3_0
def c8, -1, 1, 0, 0
dcl_normal v0.xyz
dcl_texcoord v1.xy
dcl vFace
dcl_2d s2
dcl_2d s3
0: cmp r0.x, vFace, c8.x, c8.x
1: if_lt r0.x, c8.x
//blah
24: else
//blah
45: endif
That seems very wrong: c8.x gets stuffed in r0.x, no matter what value vFace has! In both cases, the hlsl code is something like:
void main(in PS_INPUT Input, in float isBackFacing : VFACE, out PS_OUTPUT Output)
{
Output.color = float4(0,0,0,1);
if (isBackFacing < 0)
//blah
else
//blah
}
Am I misunderstanding this stuff? Are there things I should know about the interaction between VFACE and texturing? I really have no clue why this doesn't work, so any help is much appreciated
BTW: I check all calls into D3D, and have debug output at the highest level, but no errors are reported.