Jump to content
  • Advertisement
Sign in to follow this  
STufaro

Negative Scale Factor

This topic is 3734 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

Hey guys, quick question about scaling and normals. I'm using a negative scale factor to quickly mirror a mesh in D3D. Of course the problem with that is the negative scale also flips the mesh's normals inward, and backface culling just totally removes the mesh entirely (or lighting just doesn't get to the mesh's normals because it's inside-out, I'm not entirely clear on what's going on). Is there a way to easily mirror a mesh in D3D (I'm using D3D8 in VB6 at the moment because I'm too lazy to get into another language :P ) without the drawbacks of a negative scale factor? Any suggestions are appreciated! Much obliged, - Steve.

Share this post


Link to post
Share on other sites
Advertisement
If you have a negative scale, would it be possible to simply flip back/front face culling before rendering? As in:

if (scale.isNegative())
culling = (culling == CULL_CLOCKWISE) ? CULL_ANTICLOCKWISE : CULL_CLOCKWISE;


Edit: Hold up. After some thoughts, if you have a negative scale and you transform the normals by the world (and possibly view) matrix, then the negation will be automatically handled. So, unless you're specifically doing object-space lighting in a shader, the normals should Just Work (tm).

Depending on how you're doing the rendering, it might also be a good idea to negate the normals. For example, a shader would be ideal for this, as you can pass the negation as a uniform parameter:

uniform float normalScale;

// in the vertex shader
OUT.normal = IN.normal * normalScale;

Now, if this was mirrored, you'd set normalScale = -1, otherwise normalScale = 1.

Share this post


Link to post
Share on other sites
Many thanks for your reply, agi_shi!

So I can change the culling mode at render time? That might not be such a problem at all. I didn't think of that (actually, I didn't realize I could change the culling mode until now either)!

I'd assume that'd fix it, but would the normals being flipped mess up my lighting?

For now I'm going to give that a shot; I'll let you know what happens when I do.

Share this post


Link to post
Share on other sites
Quote:
Original post by STufaro
So I can change the culling mode at render time? That might not be such a problem at all. I didn't think of that (actually, I didn't realize I could change the culling mode until now either)!

You can change the render state any time you want, and the next thing you render will be affected by this. Of course, don't get too wild with it, as the fewer the render state changes, the faster the rendering. So, basically, you'd render your mesh in two parts - the positive scaled part with back face culling, and the negative scaled part with front face culling.
Quote:

I'd assume that'd fix it, but would the normals being flipped mess up my lighting?

See my edited post above.
Quote:

For now I'm going to give that a shot; I'll let you know what happens when I do.


I'm honestly not 100% sure myself, so do tell us how it goes [grin].

Share this post


Link to post
Share on other sites
Well, looks like you were right. The normals did Just Work (TM). And I like it when things Just Work.

Thanks again agi for the advice. Now I'm a mesh-flipping machine.

- Steve.

Edit:

I'm also not doing any object-space lighting (luckily), so I did not have to flip them. Just as you advised.

Thanks!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!