diff --git a/interface/resources/shaders/metavoxel_heightfield_cursor.frag b/interface/resources/shaders/metavoxel_heightfield_cursor.frag index 20efc51e08..0bb5e21e7d 100644 --- a/interface/resources/shaders/metavoxel_heightfield_cursor.frag +++ b/interface/resources/shaders/metavoxel_heightfield_cursor.frag @@ -11,10 +11,22 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// the cursor texture -uniform sampler2D cursorMap; +// the inner radius of the outline, squared +const float SQUARED_OUTLINE_INNER_RADIUS = 0.81; + +// the outer radius of the outline, squared +const float SQUARED_OUTLINE_OUTER_RADIUS = 1.0; + +// the inner radius of the inset, squared +const float SQUARED_INSET_INNER_RADIUS = 0.855625; + +// the outer radius of the inset, squared +const float SQUARED_INSET_OUTER_RADIUS = 0.950625; void main(void) { - // just multiply the color by the cursor texture - gl_FragColor = gl_Color * texture2D(cursorMap, gl_TexCoord[0].st); + // use the distance to compute the ring color, then multiply it by the varying color + float squaredDistance = dot(gl_TexCoord[0].st, gl_TexCoord[0].st); + float alpha = step(SQUARED_OUTLINE_INNER_RADIUS, squaredDistance) * step(squaredDistance, SQUARED_OUTLINE_OUTER_RADIUS); + float white = step(SQUARED_INSET_INNER_RADIUS, squaredDistance) * step(squaredDistance, SQUARED_INSET_OUTER_RADIUS); + gl_FragColor = gl_Color * vec4(white, white, white, alpha); } diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 85a1f5a1fc..f62a85025b 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -31,10 +31,6 @@ REGISTER_META_OBJECT(StaticModelRenderer) static int bufferPointVectorMetaTypeId = qRegisterMetaType(); -MetavoxelSystem::MetavoxelSystem() : - _cursorTexture(QOpenGLTexture::Target2D) { -} - void MetavoxelSystem::init() { MetavoxelClientManager::init(); DefaultMetavoxelRendererImplementation::init(); @@ -155,33 +151,6 @@ int HeightfieldCursorRenderVisitor::visit(MetavoxelInfo& info) { } void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float radius) { - // create the cursor texture lazily - if (!_cursorTexture.isCreated()) { - const int CURSOR_TEXTURE_SIZE = 512; - QImage cursorImage(CURSOR_TEXTURE_SIZE, CURSOR_TEXTURE_SIZE, QImage::Format_ARGB32_Premultiplied); - cursorImage.fill(0x0); - { - QPainter painter(&cursorImage); - const int ELLIPSE_EDGE = 10; - const int OUTER_WIDTH = 10; - QPen outerPen; - outerPen.setWidth(OUTER_WIDTH); - painter.setPen(outerPen); - const int HALF_TEXTURE_SIZE = CURSOR_TEXTURE_SIZE / 2; - painter.drawEllipse(QPoint(HALF_TEXTURE_SIZE, HALF_TEXTURE_SIZE), HALF_TEXTURE_SIZE - ELLIPSE_EDGE, - HALF_TEXTURE_SIZE - ELLIPSE_EDGE); - QPen innerPen(Qt::white); - const int INNER_WIDTH = 6; - innerPen.setWidth(INNER_WIDTH); - painter.setPen(innerPen); - painter.drawEllipse(QPoint(HALF_TEXTURE_SIZE, HALF_TEXTURE_SIZE), HALF_TEXTURE_SIZE - ELLIPSE_EDGE, - HALF_TEXTURE_SIZE - ELLIPSE_EDGE); - } - _cursorTexture.setData(cursorImage, QOpenGLTexture::DontGenerateMipMaps); - _cursorTexture.setWrapMode(QOpenGLTexture::ClampToEdge); - _cursorTexture.setMinificationFilter(QOpenGLTexture::Linear); - } - glDepthFunc(GL_LEQUAL); glEnable(GL_CULL_FACE); glEnable(GL_POLYGON_OFFSET_FILL); @@ -196,21 +165,16 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r glActiveTexture(GL_TEXTURE4); float scale = 1.0f / radius; - glm::vec4 sCoefficients(scale, 0.0f, 0.0f, 0.5f - scale * position.x); - glm::vec4 tCoefficients(0.0f, 0.0f, scale, 0.5f - scale * position.z); + glm::vec4 sCoefficients(scale, 0.0f, 0.0f, -scale * position.x); + glm::vec4 tCoefficients(0.0f, 0.0f, scale, -scale * position.z); glTexGenfv(GL_S, GL_EYE_PLANE, (const GLfloat*)&sCoefficients); glTexGenfv(GL_T, GL_EYE_PLANE, (const GLfloat*)&tCoefficients); - - _cursorTexture.bind(1); glActiveTexture(GL_TEXTURE0); glm::vec3 extents(radius, radius, radius); HeightfieldCursorRenderVisitor visitor(getLOD(), Box(position - extents, position + extents)); guideToAugmented(visitor); - _cursorTexture.release(1); - glActiveTexture(GL_TEXTURE0); - DefaultMetavoxelRendererImplementation::getHeightfieldCursorProgram().release(); glDisableClientState(GL_TEXTURE_COORD_ARRAY); diff --git a/interface/src/MetavoxelSystem.h b/interface/src/MetavoxelSystem.h index a2d3128cb7..7b681ff3a9 100644 --- a/interface/src/MetavoxelSystem.h +++ b/interface/src/MetavoxelSystem.h @@ -14,7 +14,6 @@ #include #include -#include #include #include @@ -32,8 +31,6 @@ class MetavoxelSystem : public MetavoxelClientManager { public: - MetavoxelSystem(); - virtual void init(); virtual MetavoxelLOD getLOD(); @@ -64,8 +61,6 @@ private: MetavoxelLOD _lod; QReadWriteLock _lodLock; Frustum _frustum; - - QOpenGLTexture _cursorTexture; }; /// Describes contents of a point in a point buffer.