Sign in to follow this  
sipickles

[HLSL] Simple scaling using Normals

Recommended Posts

Hello, I have a mental block! Help! I am trying to perform a simple scaling operation of my mesh in HLSL. I thought it would be as simple as this:

float scale = 4.0;

VS_OUTPUT VS(	float4 Position 	: POSITION,
    		float4 Normal   	: NORMAL)
{
    	VS_OUTPUT OUT	= (VS_OUTPUT)0;
    	OUT.Position	= mul( Position + (Normal * scale), WVP );                      
    	return OUT;
}

I know my normal data is fine as I am using the same mesh in a different lighting effect. Any suggestions? Thanks

Share this post


Link to post
Share on other sites
Maybe you already checked how huge your mesh is, but that shader isn't going to work unless your object is very small.

Suppose position is 100.0,400.0,-1000.0. By scaling the normal you add/subract a small value, so the object will look the same.

If your object is centered at 0,0,0 there's no reason to use the normal to scale it.. a simple Position*Scale should be enough.

Share this post


Link to post
Share on other sites
Hmm.

I thought I was modifying the position of each vertex in ObjectSpace, before transforming each vertex, so this is irrelevant to the world position of the object.

I agree, the scale multiplier needs to be in proportion with the size of the object to notice any difference.

As long as the object is convex, this should make it bigger, no?

Share this post


Link to post
Share on other sites
Quote:
Original post by sipickles
Hmm.

I thought I was modifying the position of each vertex in ObjectSpace, before transforming each vertex, so this is irrelevant to the world position of the object.

You're right, object space works this way. I was just pointing out a general rule. :)

Quote:

As long as the object is convex, this should make it bigger, no?

Yes.

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