Enable negative transform scale to flip objects without inverted normals

Right now there is a parameter in the shaders that lets you render backfaces. It does so by setting CCW and it inverts the normals:

FlipSided changes CCW:

https://github.com/mrdoob/three.js/blob/master/src/renderers/WebGLRenderer.js#L5285

FlipSided also changes normal:

https://github.com/mrdoob/three.js/blob/master/src/renderers/webgl/WebGLProgram.js#L140

https://github.com/mrdoob/three.js/blob/master/src/renderers/shaders/ShaderChunk.js#L1355

But sometimes one has a negative scale in the transform matrix — in DCC programs like 3DS Max, Maya, Softimage, etc, it means flip the object. The way to do this is to have CCW set (as opposed to CW) but keep the normals the way they are (because they are already flipped by the matrix transform.) To achieve this efficiently with ThreeJS it is necessary to be able to set CCW/CW independently of flipping the normals.

Right now there is no flag that allows for CCW but without inverting the normals. Can we add some option that enables this?

Even if we had another option called FLIP_NORMAL/flipNormals that would just invert normals from whatever they are set via flipSided/FLIP_SIDED. In our case we could set both flipSided and flipNormals to achieve our desired result. This would be backwards compatible.

We can make the PR if this is acceptable.

Author: Fantashit

1 thought on “Enable negative transform scale to flip objects without inverted normals

Comments are closed.