Skip to content

Commit f6248d3

Browse files
authored
Merge pull request #5283 from JetStarBlues/add_uModelViewProjectionMatrix
Add a uModelViewProjectionMatrix uniform
2 parents b725a6c + d00e9c6 commit f6248d3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/webgl/p5.Shader.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ p5.Shader.prototype.unbindTextures = function() {
253253
};
254254

255255
p5.Shader.prototype._setMatrixUniforms = function() {
256-
this.setUniform('uProjectionMatrix', this._renderer.uPMatrix.mat4);
256+
const viewMatrix = this._renderer._curCamera.cameraMatrix;
257+
const projectionMatrix = this._renderer.uPMatrix;
258+
const modelViewMatrix = this._renderer.uMVMatrix;
259+
260+
const modelViewProjectionMatrix = modelViewMatrix.copy();
261+
modelViewProjectionMatrix.mult(projectionMatrix);
262+
257263
if (this.isStrokeShader()) {
258264
if (this._renderer._curCamera.cameraType === 'default') {
259265
// strokes scale up as they approach camera, default
@@ -263,8 +269,10 @@ p5.Shader.prototype._setMatrixUniforms = function() {
263269
this.setUniform('uPerspective', 0);
264270
}
265271
}
266-
this.setUniform('uModelViewMatrix', this._renderer.uMVMatrix.mat4);
267-
this.setUniform('uViewMatrix', this._renderer._curCamera.cameraMatrix.mat4);
272+
this.setUniform('uViewMatrix', viewMatrix.mat4);
273+
this.setUniform('uProjectionMatrix', projectionMatrix.mat4);
274+
this.setUniform('uModelViewMatrix', modelViewMatrix.mat4);
275+
this.setUniform('uModelViewProjectionMatrix', modelViewProjectionMatrix.mat4);
268276
if (this.uniforms.uNormalMatrix) {
269277
this._renderer.uNMatrix.inverseTranspose(this._renderer.uMVMatrix);
270278
this.setUniform('uNormalMatrix', this._renderer.uNMatrix.mat3);

0 commit comments

Comments
 (0)