How to calculate correct normal for two-sided poly?
Anyone knows how to do this?
I found a sample app that does it on the NVidia site but the shader is all in assembly which I don’t really under stand.
There is also no documentation with the sample so it’s not very useful to me.
Can anyone explain what needs to be done to flip the normal for correct lighting?
Quote:Original post by Promit
If it's a backfacing poly, then can't you just negate the normal and be done with it?
Is it really that simple?
That sample looked to be doing a lot more.
It looked more like a reflection of the normal but I wasn't sure do to the assembly language shader code.
I was looking at the Two-Sided Polygons sample.
Maybe if I negate both the light and the eye vectors
Would that work?
float3 N = mul(IN.normal, worldInverseTranspose); // normal float3 E = normalize(worldEyePos - worldVertPos); // eye float3 L = normalize(-lightDir.xyz); // light if(0 > dot(N, L)) { L = -L; E = -E; } float3 H = normalize(E + L); // half angle
Would that work?
I believe something like this should work in HLSL:
float ndotv = dot( IN.normal, vertexToView );float side = sign( ndotv );IN.normal *= side;
Quote:Original post by paic
Wow, that's pretty clever. I wouldn't have think of that by myself althouhg it's so simple ^^
The VFace semantic is provided to tell you the side of the face for shader model 3.0. This is the correct way to determine the polygonside:
float4 main(...,float3 Normal : NORMAL, float S : VFace)
{
if(S < 0)
Normal = -Normal;
...
}
Unfortantly, due to hardware weirdness the only thing you know about VFace is the sign
Cool, another thing I didn't know. But it's limited to SM 3.0 on the contrary of the previous method.
Ok, seems that the solution Promit provided is the one I'll use.
Id love to use the vs_3_0 VFace but I don’t have that luxury.
I had the right idea but not the correct vector. It's obvious now that I should have used the vertex to eye vector and not the light vector for the dot... what was I thinking [rolleyes]
Id love to use the vs_3_0 VFace but I don’t have that luxury.
I had the right idea but not the correct vector. It's obvious now that I should have used the vertex to eye vector and not the light vector for the dot... what was I thinking [rolleyes]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement