# Negative Scale Factor

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

## 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 on other sites
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 shaderOUT.normal = IN.normal * normalScale;

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

##### Share on other sites

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 on other sites
Quote:
 Original post by STufaroSo 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 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!

1. 1
2. 2
3. 3
Rutin
20
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633656
• Total Posts
3013190
×