Sign in to follow this  
SymLinked

[HLSL]: How do I invert a vertex?

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this