[HLSL]: How do I invert a vertex?

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

Recommended Posts

Not succeeding in doing this so far. This is what I have:
struct Appdata
{
float4 position        : POSITION;
float4 texCoord        : TEXCOORD0;
float3 normal          : NORMAL;

};
struct Conn
{
float4 HPOS             : POSITION;
float2 outTexCoord     : TEXCOORD0;
float3 normal		  : TEXCOORD1;

};

Conn main( Appdata In, uniform float4x4 modelview : register(VC_WORLD_PROJ),
uniform float4x4 texMat          : register(VC_TEX_TRANS1)

)
{
Conn Out;

Out.HPOS = mul(modelview, In.position);
float3 N = normalize(In.normal);
Out.normal = -N;

Out.outTexCoord = mul(texMat, In.texCoord);
return Out;
}

Since it doesn't seem to matter what I set Out.normal to (even setting it to 0 doesn't make any difference) I'm assuming I'll have to tinker with Out.HPOS. Any tips?

Share on other sites
What is it you are actually trying to achieve with this?

Taking the negative of N should invert the normal but what are you then doing with this? Are you using a pixel shader to take the normal and performing a lighting calculation?

Share on other sites
Quote:
 What is it you are actually trying to achieve with this?
Yup, we need more detail including the pixel shader and ideally a picture or explanation of the desired output.

Given that a vertex is just a point in space inversion doesn't really mean anything. Do you mean reflection? That's the closest I can think of to what you're saying...

Cheers
Jack

Share on other sites
Sorry for being vague.

I'm not doing anything with the normal after I invert it. I assumed it would directly affect the mesh like fiddling with POSITION does. Shouldn't it?

What I'm trying to do is a cheap outline around the player. That's rendering the model a second time, scaling it up slightly and then inverting the faces so it's inside-out. I'm just not sure what I do with NORMAL to get this effect.

Guessing based on your answers I'm not on the right path and will have to use the normal somehow, not just set it and expect magic to happen.

Share on other sites
instead of doing anything with the normal you could just change your cull mode to the opposite direction this will cause the faces to appear inverted, im not sure changing the normal will have the desired effect of what you want as the winding of the vertices will remain the same.

Share on other sites
Quote:
 Original post by BlackSeedsinstead of doing anything with the normal you could just change your cull mode to the opposite direction this will cause the faces to appear inverted, im not sure changing the normal will have the desired effect of what you want as the winding of the vertices will remain the same.

This was indeed what I had to do. So simple! Set the CullMode to Counter-Clockwise and it was exactly like I wanted it.

Thanks!

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5
khawk
11

• 9
• 9
• 11
• 11
• 23
• Forum Statistics

• Total Topics
633677
• Total Posts
3013281
×