# How to calculate correct normal for two-sided poly?

This topic is 4785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
If it's a backfacing poly, then can't you just negate the normal and be done with it?

##### Share on other sites
It's likely not in ASM, it's a shader language...

##### Share on other sites
Quote:
 Original post by PromitIf 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.

##### Share on other sites
Maybe if I negate both the light and the eye vectors
	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?

##### Share on other sites
I believe something like this should work in HLSL:
float ndotv = dot( IN.normal, vertexToView );float side = sign( ndotv );IN.normal *= side;

##### Share on other sites
Wow, that's pretty clever. I wouldn't have think of that by myself althouhg it's so simple ^^

##### Share on other sites
Quote:
 Original post by paicWow, 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

##### Share on other sites
Cool, another thing I didn't know. But it's limited to SM 3.0 on the contrary of the previous method.

##### Share on other sites
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]

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
14
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013643
×