Skip to content

Commit

Permalink
Solves issue #4214
Browse files Browse the repository at this point in the history
  • Loading branch information
Garima3110 committed Jan 12, 2024
1 parent bf0a48d commit ba0f02e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ const defineStrokeJoinEnum = function (key, val) {
STROKE_JOIN_ENUM[constants[key]] = val;
};

p5.prototype.linePerspective = function (enable) {
if (enable) {
this.drawingContext.linePerspective = true;
} else {
this.drawingContext.linePerspective = false;
}
};


// Define constants in line shaders for each type of cap/join, and also record
// the values in JS objects
defineStrokeCapEnum('ROUND', 0);
Expand Down
13 changes: 9 additions & 4 deletions src/webgl/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,15 @@ p5.Shader = class {

if (this.isStrokeShader()) {
if (this._renderer._curCamera.cameraType === 'default') {
// strokes scale up as they approach camera, default
this.setUniform('uPerspective', 1);
} else {
// strokes have uniform scale regardless of distance from camera
// Check if line perspective is enabled
if (this._renderer.drawingContext.linePerspective) {
// strokes scale up as they approach camera, default
this.setUniform('uPerspective', 1);
} else {
this.setUniform('uPerspective', 0);
}
}else{
// Strokes have a uniform scale regardless of the distance from the camera
this.setUniform('uPerspective', 0);
}
}
Expand Down

0 comments on commit ba0f02e

Please sign in to comment.