# face normals

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

## Recommended Posts

Im trying to output a mesh with the face normal on each triangle. I'm doing this in the geometry shader. I have the center of every triangle. I append that point. Then I add the center with the face normal. ex.. (center + facenormal) than I add that point. So I get a line. but there not straight.

my code for the face normal is

 float3 faceEdgeA = input[1].PosH - input[0].PosH;
float3 faceEdgeB = input[2].PosH - input[0].PosH;
float3 faceNormal = normalize( cross(faceEdgeA, faceEdgeB) ) *.1;


so to find the face normal, I just add the center of the triangle with the face normal?

##### Share on other sites

This is what I'm getting

The face normal are going in and not straight

my code is ( a snippet)

This is done in the geometry shader

 float3 faceEdgeA = input[1].PosH - input[0].PosH;
float3 faceEdgeB = input[2].PosH - input[0].PosH;
float3 faceNormal = normalize( cross(faceEdgeA, faceEdgeB) ) *1;
output.PosH = float4((input[0].PosH.xyz + input[1].PosH.xyz + input[2].PosH.xyz)/3.0,1);
output.PosH = mul( output.PosH, gWorldViewProj);
TriStream.Append( output );
output.PosH = float4((input[0].PosH.xyz + input[1].PosH.xyz + input[2].PosH.xyz)/3.0,1) + float4(faceNormal,1);
output.PosH = mul( output.PosH, gWorldViewProj );

TriStream.Append( output );

Edited by terryeverlast

##### Share on other sites

( It's early here, might not be correct ):

When creating the end point of the normal "visualizer", you do this:

pos = float4(center, 1) + float4(normal, 1);

.

Leaving the w component 2, which I do not believe you want, so:

output.PosH = float4((input[0].PosH.xyz + input[1].PosH.xyz + input[2].PosH.xyz)/3.0 + faceNormal,1);

.

Back to bed, I am.

Edited by Migi0027 (????)

##### Share on other sites

Thx migi0027, it works now.

Edited by terryeverlast

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

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

• Total Topics
633736
• Total Posts
3013600
×