From ba0f02ea38c913e2977bc3aaef923218d14bcf46 Mon Sep 17 00:00:00 2001 From: Garima Date: Fri, 12 Jan 2024 23:57:05 +0530 Subject: [PATCH] Solves issue #4214 --- src/webgl/p5.RendererGL.js | 9 +++++++++ src/webgl/p5.Shader.js | 13 +++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index 097c9ab8c1..3c95d335f6 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -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); diff --git a/src/webgl/p5.Shader.js b/src/webgl/p5.Shader.js index 3bb6c63a1a..90bbca439f 100644 --- a/src/webgl/p5.Shader.js +++ b/src/webgl/p5.Shader.js @@ -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); } }