MCPcopy
hub / github.com/visgl/deck.gl / getViewProjectionMatrices

Function getViewProjectionMatrices

modules/core/src/shaderlib/shadow/shadow.ts:169–207  ·  view source on GitHub ↗
({
  viewport,
  shadowMatrices
}: {
  viewport: Viewport;
  shadowMatrices: Matrix4[];
})

Source from the content-addressed store, hash-verified

167}
168
169function getViewProjectionMatrices({
170 viewport,
171 shadowMatrices
172}: {
173 viewport: Viewport;
174 shadowMatrices: Matrix4[];
175}): Matrix4[] {
176 const projectionMatrices: Matrix4[] = [];
177 const pixelUnprojectionMatrix = viewport.pixelUnprojectionMatrix;
178 const farZ = viewport.isGeospatial ? undefined : 1;
179 const corners = [
180 [0, 0, farZ], // top left ground
181 [viewport.width, 0, farZ], // top right ground
182 [0, viewport.height, farZ], // bottom left ground
183 [viewport.width, viewport.height, farZ], // bottom right ground
184 [0, 0, -1], // top left near
185 [viewport.width, 0, -1], // top right near
186 [0, viewport.height, -1], // bottom left near
187 [viewport.width, viewport.height, -1] // bottom right near
188 ].map(pixel =>
189 // @ts-expect-error z may be undefined
190 screenToCommonSpace(pixel, pixelUnprojectionMatrix)
191 );
192
193 for (const shadowMatrix of shadowMatrices) {
194 const viewMatrix = shadowMatrix.clone().translate(new Vector3(viewport.center).negate());
195 const positions = corners.map(corner => viewMatrix.transform(corner));
196 const projectionMatrix = new Matrix4().ortho({
197 left: Math.min(...positions.map(position => position[0])),
198 right: Math.max(...positions.map(position => position[0])),
199 bottom: Math.min(...positions.map(position => position[1])),
200 top: Math.max(...positions.map(position => position[1])),
201 near: Math.min(...positions.map(position => -position[2])),
202 far: Math.max(...positions.map(position => -position[2]))
203 });
204 projectionMatrices.push(projectionMatrix.multiplyRight(shadowMatrix));
205 }
206 return projectionMatrices;
207}
208
209/* eslint-disable camelcase */
210

Callers

nothing calls this directly

Calls 2

screenToCommonSpaceFunction · 0.85
cloneMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…