Jump to content
  • Advertisement
Sign in to follow this  
sipickles

[HLSL] Simple scaling using Normals

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!