[HLSL]: How do I invert a vertex?

Started by
4 comments, last by SymLinked 15 years, 4 months ago
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?
Advertisement
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?
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.

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.
Quote:Original post by BlackSeeds
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.


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!

This topic is closed to new replies.

Advertisement