Fix: wrong face cull for shadows of freshly inserted mirrored objects.#15825
Fix: wrong face cull for shadows of freshly inserted mirrored objects.#15825mrdoob merged 2 commits intomrdoob:devfrom
Conversation
b4336c9 to
1968a0d
Compare
|
Hmm... Would you be willing to investigate the history of this, working backwards from #14379? Perhaps this can be refactored, and the determinant can be computed only once as |
|
The determinant is already computed for each object for both normal and shadow rendering before this fix. All this fix adds it matrix inversion computation for the shadow object rendering (the same computation already is present in normal object rendering). Unless there is some experiment which shows this fix introduces a measurable performance impact, I suggest leaving possible optimizations for separate issues / PRs. |
|
Does your edge case go away if we did this, instead? var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 ); |
|
Yes, that fixes it fine, as I think this is a good idea for a proper fix, as the computations done are: I think we can safely assume camera matrix is a non-mirroring one. Other operations do not change matrix determinant sign. |
Actually, not, apparently. (#14372) This is why I asked you to study the history of #14379. If you look at #12787, the original PR used Personally, I do not think reflections in |
|
Sigh. A proper fix could then be to multiply signs of |
Pushed a commit implementing this.
While this is possible to add, the current implementation computing two 3x3 determinants should be faster then the previous one which computed a 4x4 one, therefore I am not convinced adding the logic to handle the global value computation is worth the effort. |
599e9d1 to
9af8bca
Compare
|
@WestLangley Does this look good to you? |
|
|
I am not in favor of this latest change to the PR. This is overkill, IMO. I would implement what I suggested above: var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );which is the approach originally used in #12787. The approach in #12787 was modified in a later PR to accommodate a user who wanted to negatively-scale the camera matrix. But the modification did not test shadows or the effects on other features like the controls. The library does not fully-support a negative scale on the camera. I would restore the approach used in #12787. Shadows will then work correctly. I would also not worry about Instead, if there is a performance issue, we can optimize the code in |
9af8bca to
d50c891
Compare
|
Ok, I have no preference on this. Back to the previous commit. |
|
Thanks! |
|
@OndrejSpanel Thank you for working on this. |
PR for #15821
As the function
renderBufferDirectuses aobject.normalMatrixvalue to determine the face cull direction, it needs to be set inWebGLShadowMap.renderObjectas well, not only in theWebGLRenderer.renderObject.Note:
normalMatrixis computed asthis.setFromMatrix4( matrix4 ).getInverse( this ).transpose(). I hope the performance impact caused by this is acceptable. If not, I suggest adding parametermirroredto therenderBufferDirectfunction and to compute matrix determinant directly without inverting the matrix (matrix inversion does not change determinant sign).