------------------------------------------------------------------------------
| 30 | |
| 31 | //------------------------------------------------------------------------------ |
| 32 | void vtkWebGPUCamera::CacheSceneTransforms(vtkRenderer* renderer) |
| 33 | { |
| 34 | if (renderer == nullptr && this->LastRenderer == nullptr) |
| 35 | { |
| 36 | return; |
| 37 | } |
| 38 | // has the camera changed? |
| 39 | if (renderer != this->LastRenderer || this->MTime > this->KeyMatrixTime || |
| 40 | renderer->GetMTime() > this->KeyMatrixTime) |
| 41 | { |
| 42 | vtkMatrix4x4* view = this->GetModelViewTransformMatrix(); |
| 43 | SceneTransforms& st = this->CachedSceneTransforms; |
| 44 | |
| 45 | for (int i = 0; i < 4; ++i) |
| 46 | { |
| 47 | for (int j = 0; j < 4; ++j) |
| 48 | { |
| 49 | st.ViewMatrix[i][j] = view->GetElement(j, i); |
| 50 | } |
| 51 | } |
| 52 | // since directx, vulkan and metal expect z-coordinate to lie in [0, 1] instead of [-1, 1], |
| 53 | // webgpu culls fragments that have a z outside of [0, 1]; even for opengl backend. |
| 54 | vtkMatrix4x4* projection = |
| 55 | this->GetProjectionTransformMatrix(renderer->GetTiledAspectRatio(), 0, 1); |
| 56 | for (int i = 0; i < 4; ++i) |
| 57 | { |
| 58 | for (int j = 0; j < 4; ++j) |
| 59 | { |
| 60 | // transpose because, shader will interpret it in a column-major order. |
| 61 | st.ProjectionMatrix[i][j] = projection->GetElement(j, i); |
| 62 | } |
| 63 | } |
| 64 | st.ProjectionMatrix[1][1] *= -1; |
| 65 | // normal matrix |
| 66 | for (int i = 0; i < 3; ++i) |
| 67 | { |
| 68 | for (int j = 0; j < 3; ++j) |
| 69 | { |
| 70 | // need to transpose. |
| 71 | // but do not transpose, shader will interpret it in a column-major order. |
| 72 | this->NormalMatrix->SetElement(i, j, view->GetElement(i, j)); |
| 73 | } |
| 74 | } |
| 75 | this->NormalMatrix->Invert(); |
| 76 | for (int i = 0; i < 3; ++i) |
| 77 | { |
| 78 | for (int j = 0; j < 3; ++j) |
| 79 | { |
| 80 | // transpose because, shader will interpret it in a column-major order. |
| 81 | st.NormalMatrix[i][j] = this->NormalMatrix->GetElement(i, j); |
| 82 | } |
| 83 | } |
| 84 | projection->Invert(); |
| 85 | for (int i = 0; i < 4; ++i) |
| 86 | { |
| 87 | for (int j = 0; j < 4; ++j) |
| 88 | { |
| 89 | // transpose because, shader will interpret it in a column-major order. |
no test coverage detected