Skip to content

Commit

Permalink
Optimize matrix calculation (#3022)
Browse files Browse the repository at this point in the history
* optimize matrix calculation

* optimize matrix calculation

* remove vague changelog of no interest to package consumers

Co-authored-by: Paul Connelly <[email protected]>
  • Loading branch information
MarcNeely and pmconne authored Jan 11, 2022
1 parent faab1c3 commit d9f1974
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-frontend",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/core-frontend"
}
14 changes: 8 additions & 6 deletions core/frontend/src/render/webgl/BranchUniforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { UniformHandle } from "./UniformHandle";
import { Matrix3, Matrix4 } from "./Matrix";
import { RenderCommands } from "./RenderCommands";
import { desync, sync, SyncToken } from "./Sync";
import { System } from "./System";
import { Target } from "./Target";
import { ClipStack } from "./ClipStack";

Expand Down Expand Up @@ -242,16 +243,17 @@ export class BranchUniforms {
Matrix4d.createTransform(mv, this._mv);
this._mv32.initFromTransform(mv);

const inv = this._mv.createInverse();
if (undefined !== inv) {
const invTr = inv.cloneTransposed();
this._mvn32.initFromMatrix3d(invTr.matrixPart());
}

// Don't bother computing mvp for instanced geometry - it's not used.
if (!this._isInstanced) {
uniforms.projectionMatrix.multiplyMatrixMatrix(this._mv, this._mvp);
this._mvp32.initFromMatrix4d(this._mvp);
if (!System.instance.capabilities.isWebGL2) { // inverse model to view is only used if not instanced and not WebGL2
const inv = this._mv.createInverse();
if (undefined !== inv) {
const invTr = inv.cloneTransposed();
this._mvn32.initFromMatrix3d(invTr.matrixPart());
}
}
}

return true;
Expand Down

0 comments on commit d9f1974

Please sign in to comment.