Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLShadowMap: cleanup and optimization #11198

Merged
merged 2 commits into from
Apr 19, 2017
Merged

Conversation

jaxry
Copy link
Contributor

@jaxry jaxry commented Apr 19, 2017

A simple pull request which reorganizes some shadow mapping code.

  • A Matrix4 (shadowMatrix) was calculated six times every frame for each point shadow used, despite only being used for spot/directional lights. Moved this calculation so it's only done for spot/directional lights.
  • Moved a matrix calculation from WebGlRenderer to WebGLShadowMap so that point shadows are organized the same way as spotlight/directional shadows.

// equal to inverse of the light's position

var elements = light.matrixWorld.elements;
shadowMatrix.makeTranslation( - elements[ 12 ], - elements[ 13 ], - elements[ 14 ] );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating shadowMatrix declaratively as before, I create it directly. Avoids an intermediate Vector3 but loses clarity. Is an intermediate Vector3 preferable after all?

_vector3.setFromMatrixPosition( light.matrixWorld ).negate();
_lights.pointShadowMatrix[ pointLength ].identity().setPosition( _vector3 );

_lights.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern resembles the pattern used by spotlights and directinal lights a few blocks above.

@mrdoob mrdoob merged commit 40a0920 into mrdoob:dev Apr 19, 2017
@mrdoob
Copy link
Owner

mrdoob commented Apr 19, 2017

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants