Skip to content

Commit

Permalink
Merge pull request #5283 from JetStarBlues/add_uModelViewProjectionMa…
Browse files Browse the repository at this point in the history
…trix

Add a uModelViewProjectionMatrix uniform
  • Loading branch information
aferriss authored Dec 23, 2021
2 parents b725a6c + d00e9c6 commit f6248d3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/webgl/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,13 @@ p5.Shader.prototype.unbindTextures = function() {
};

p5.Shader.prototype._setMatrixUniforms = function() {
this.setUniform('uProjectionMatrix', this._renderer.uPMatrix.mat4);
const viewMatrix = this._renderer._curCamera.cameraMatrix;
const projectionMatrix = this._renderer.uPMatrix;
const modelViewMatrix = this._renderer.uMVMatrix;

const modelViewProjectionMatrix = modelViewMatrix.copy();
modelViewProjectionMatrix.mult(projectionMatrix);

if (this.isStrokeShader()) {
if (this._renderer._curCamera.cameraType === 'default') {
// strokes scale up as they approach camera, default
Expand All @@ -263,8 +269,10 @@ p5.Shader.prototype._setMatrixUniforms = function() {
this.setUniform('uPerspective', 0);
}
}
this.setUniform('uModelViewMatrix', this._renderer.uMVMatrix.mat4);
this.setUniform('uViewMatrix', this._renderer._curCamera.cameraMatrix.mat4);
this.setUniform('uViewMatrix', viewMatrix.mat4);
this.setUniform('uProjectionMatrix', projectionMatrix.mat4);
this.setUniform('uModelViewMatrix', modelViewMatrix.mat4);
this.setUniform('uModelViewProjectionMatrix', modelViewProjectionMatrix.mat4);
if (this.uniforms.uNormalMatrix) {
this._renderer.uNMatrix.inverseTranspose(this._renderer.uMVMatrix);
this.setUniform('uNormalMatrix', this._renderer.uNMatrix.mat3);
Expand Down

0 comments on commit f6248d3

Please sign in to comment.