From 1791ed01ca050d9c9ff505610a12c7b8871c9d07 Mon Sep 17 00:00:00 2001 From: luiscuenca Date: Wed, 8 Nov 2017 18:35:26 -0700 Subject: [PATCH] add width param to vertex shader --- interface/src/raypick/LaserPointer.cpp | 11 ++++++----- interface/src/ui/overlays/Line3DOverlay.cpp | 10 +--------- interface/src/ui/overlays/Line3DOverlay.h | 3 --- libraries/render-utils/src/GeometryCache.cpp | 6 +++--- libraries/render-utils/src/GeometryCache.h | 4 ++-- libraries/render-utils/src/glowLine.slf | 3 +-- libraries/render-utils/src/glowLine.slv | 6 ++---- 7 files changed, 15 insertions(+), 28 deletions(-) diff --git a/interface/src/raypick/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp index 5f2549deea..14af9b336f 100644 --- a/interface/src/raypick/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -14,6 +14,8 @@ #include "avatar/AvatarManager.h" #include "RayPickScriptingInterface.h" +static const float DEFAULT_LASER_POINTER_SIZE = 0.02f; + LaserPointer::LaserPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, const bool faceAvatar, const bool centerEndY, const bool lockEnd, const bool distanceScaleEnd, const bool scaleWithAvatar, const bool enabled) : _renderingEnabled(enabled), @@ -163,11 +165,10 @@ void LaserPointer::updateRenderState(const RenderState& renderState, const Inter pathProps.insert("end", end); pathProps.insert("visible", true); pathProps.insert("ignoreRayIntersection", renderState.doesPathIgnoreRays()); - if (_scaleWithAvatar) { - auto glowScaleProp = qApp->getOverlays().getProperty(renderState.getPathID(), "glowScale").value; - float glowScale = glowScaleProp.isValid() ? avatarScale * glowScaleProp.toFloat() : avatarScale; - pathProps.insert("glowScale", glowScale); - } + + float glowWidth = _scaleWithAvatar ? DEFAULT_LASER_POINTER_SIZE * avatarScale : DEFAULT_LASER_POINTER_SIZE; + pathProps.insert("glowWidth", glowWidth); + qApp->getOverlays().editOverlay(renderState.getPathID(), pathProps); } if (!renderState.getEndID().isNull()) { diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 0dc8fddd04..82a3c46727 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -35,7 +35,6 @@ Line3DOverlay::Line3DOverlay(const Line3DOverlay* line3DOverlay) : _endParentJointIndex = line3DOverlay->getEndJointIndex(); _glow = line3DOverlay->getGlow(); _glowWidth = line3DOverlay->getGlowWidth(); - _glowScale = line3DOverlay->getGlowScale(); } Line3DOverlay::~Line3DOverlay() { @@ -146,7 +145,7 @@ void Line3DOverlay::render(RenderArgs* args) { geometryCache->renderDashedLine(*batch, start, end, colorv4, _geometryCacheID); } else { // renderGlowLine handles both glow = 0 and glow > 0 cases - geometryCache->renderGlowLine(*batch, start, end, colorv4, _glow, _glowWidth, _glowScale, _geometryCacheID); + geometryCache->renderGlowLine(*batch, start, end, colorv4, _glow, _glowWidth, _geometryCacheID); } } } @@ -244,13 +243,6 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { if (glowWidth.isValid()) { setGlowWidth(glowWidth.toFloat()); } - - auto glowScale = properties["glowScale"]; - if (glowScale.isValid()) { - float gscale = glowScale.toFloat(); - setGlowScale(gscale); - } - } QVariant Line3DOverlay::getProperty(const QString& property) { diff --git a/interface/src/ui/overlays/Line3DOverlay.h b/interface/src/ui/overlays/Line3DOverlay.h index 39e6436683..bcb65b1f1e 100644 --- a/interface/src/ui/overlays/Line3DOverlay.h +++ b/interface/src/ui/overlays/Line3DOverlay.h @@ -33,7 +33,6 @@ public: glm::vec3 getEnd() const; const float& getGlow() const { return _glow; } const float& getGlowWidth() const { return _glowWidth; } - const float& getGlowScale() const { return _glowScale; } // setters void setStart(const glm::vec3& start); @@ -44,7 +43,6 @@ public: void setGlow(const float& glow) { _glow = glow; } void setGlowWidth(const float& glowWidth) { _glowWidth = glowWidth; } - void setGlowScale(const float& glowScale) { _glowScale = glowScale; } void setProperties(const QVariantMap& properties) override; QVariant getProperty(const QString& property) override; @@ -74,7 +72,6 @@ private: float _glow { 0.0 }; float _glowWidth { 0.0 }; - float _glowScale { 1.0 }; int _geometryCacheID; }; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 90b3ca402d..ebf0f13d97 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1868,7 +1868,7 @@ void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm void GeometryCache::renderGlowLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, - const glm::vec4& color, float glowIntensity, float glowWidth, float glowScale, int id) { + const glm::vec4& color, float glowIntensity, float glowWidth, int id) { // Disable glow lines on OSX #ifndef Q_OS_WIN @@ -1931,10 +1931,10 @@ void GeometryCache::renderGlowLine(gpu::Batch& batch, const glm::vec3& p1, const vec4 p1; vec4 p2; vec4 color; - float scale; + float width; }; - LineData lineData { vec4(p1, 1.0f), vec4(p2, 1.0f), color, glowScale }; + LineData lineData { vec4(p1, 1.0f), vec4(p2, 1.0f), color, glowWidth }; details.uniformBuffer->resize(sizeof(LineData)); details.uniformBuffer->setSubData(0, lineData); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index a325026914..cd8c43f1df 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -314,10 +314,10 @@ public: const glm::vec4& color1, const glm::vec4& color2, int id); void renderGlowLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, - const glm::vec4& color, float glowIntensity, float glowWidth, float glowScale, int id); + const glm::vec4& color, float glowIntensity, float glowWidth, int id); void renderGlowLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color, int id) - { renderGlowLine(batch, p1, p2, color, 1.0f, 0.05f, 1.0f, id); } + { renderGlowLine(batch, p1, p2, color, 1.0f, 0.05f, id); } void renderDashedLine(gpu::Batch& batch, const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { renderDashedLine(batch, start, end, color, 0.05f, 0.025f, id); } diff --git a/libraries/render-utils/src/glowLine.slf b/libraries/render-utils/src/glowLine.slf index be1c6842e3..6a7a6157a4 100644 --- a/libraries/render-utils/src/glowLine.slf +++ b/libraries/render-utils/src/glowLine.slf @@ -10,7 +10,6 @@ // in vec4 _color; -in float _scale; in float distanceFromCenter; out vec4 _fragColor; @@ -22,7 +21,7 @@ void main(void) { float alpha = 1.0 - abs(distanceFromCenter); // Convert from a linear alpha curve to a sharp peaked one - alpha = _color.a * pow(alpha, 10.0/_scale); + alpha = _color.a * pow(alpha, 10.0); // Drop everything where the curve falls off to nearly nothing if (alpha <= 0.05) { diff --git a/libraries/render-utils/src/glowLine.slv b/libraries/render-utils/src/glowLine.slv index 7b69943b7a..4532ed7b9f 100644 --- a/libraries/render-utils/src/glowLine.slv +++ b/libraries/render-utils/src/glowLine.slv @@ -16,17 +16,15 @@ layout(std140) uniform lineData { vec4 p1; vec4 p2; vec4 color; - float scale; + float width; }; out vec4 _color; -out float _scale; // the distance from the center in 'quad space' out float distanceFromCenter; void main(void) { _color = color; - _scale = scale; TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); @@ -42,7 +40,7 @@ void main(void) { // Find the vector from the eye to one of the points vec3 v2 = normalize(p1eye.xyz); // The orthogonal vector is the cross product of these two - vec3 orthogonal = cross(v1, v2) * 0.02; + vec3 orthogonal = cross(v1, v2) * width; // Deteremine which end to emit based on the vertex id (even / odd) vec4 eye = (0 == gl_VertexID % 2) ? p1eye : p2eye;