From fba383f6d3dce3b1c2498745c9037a5cbed0fbb2 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 14 Oct 2014 15:21:45 -0700 Subject: [PATCH] Render voxel cursor on heightfields, too. --- ...oxel_cursor.frag => metavoxel_cursor.frag} | 0 .../shaders/metavoxel_heightfield_cursor.frag | 32 ------------------- .../shaders/metavoxel_heightfield_cursor.vert | 3 +- interface/src/MetavoxelSystem.cpp | 23 ++++++++++--- interface/src/ui/MetavoxelEditor.cpp | 8 +++-- 5 files changed, 25 insertions(+), 41 deletions(-) rename interface/resources/shaders/{metavoxel_voxel_cursor.frag => metavoxel_cursor.frag} (100%) delete mode 100644 interface/resources/shaders/metavoxel_heightfield_cursor.frag diff --git a/interface/resources/shaders/metavoxel_voxel_cursor.frag b/interface/resources/shaders/metavoxel_cursor.frag similarity index 100% rename from interface/resources/shaders/metavoxel_voxel_cursor.frag rename to interface/resources/shaders/metavoxel_cursor.frag diff --git a/interface/resources/shaders/metavoxel_heightfield_cursor.frag b/interface/resources/shaders/metavoxel_heightfield_cursor.frag deleted file mode 100644 index 0bb5e21e7d..0000000000 --- a/interface/resources/shaders/metavoxel_heightfield_cursor.frag +++ /dev/null @@ -1,32 +0,0 @@ -#version 120 - -// -// metavoxel_heightfield_cursor.frag -// fragment shader -// -// Created by Andrzej Kapolka on 8/7/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// 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) { - // 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/resources/shaders/metavoxel_heightfield_cursor.vert b/interface/resources/shaders/metavoxel_heightfield_cursor.vert index 93ed36449e..8a9f443a2b 100644 --- a/interface/resources/shaders/metavoxel_heightfield_cursor.vert +++ b/interface/resources/shaders/metavoxel_heightfield_cursor.vert @@ -21,7 +21,8 @@ void main(void) { gl_Position = gl_ProjectionMatrix * viewPosition; // generate the texture coordinates from the view position - gl_TexCoord[0] = vec4(dot(viewPosition, gl_EyePlaneS[4]), dot(viewPosition, gl_EyePlaneT[4]), 0.0, 1.0); + gl_TexCoord[0] = vec4(dot(viewPosition, gl_EyePlaneS[4]), dot(viewPosition, gl_EyePlaneT[4]), + dot(viewPosition, gl_EyePlaneR[4]), 1.0); // the zero height should be invisible gl_FrontColor = vec4(1.0, 1.0, 1.0, 1.0 - step(height, 0.0)); diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 8ed00be93b..e9cfde60f9 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -533,8 +533,10 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r float scale = 1.0f / radius; glm::vec4 sCoefficients(scale, 0.0f, 0.0f, -scale * position.x); glm::vec4 tCoefficients(0.0f, 0.0f, scale, -scale * position.z); + glm::vec4 rCoefficients(0.0f, 0.0f, 0.0f, 0.0f); glTexGenfv(GL_S, GL_EYE_PLANE, (const GLfloat*)&sCoefficients); glTexGenfv(GL_T, GL_EYE_PLANE, (const GLfloat*)&tCoefficients); + glTexGenfv(GL_R, GL_EYE_PLANE, (const GLfloat*)&rCoefficients); glActiveTexture(GL_TEXTURE0); glm::vec3 extents(radius, radius, radius); @@ -575,12 +577,23 @@ void MetavoxelSystem::renderVoxelCursor(const glm::vec3& position, float radius) glActiveTexture(GL_TEXTURE0); glm::vec3 extents(radius, radius, radius); - CursorRenderVisitor visitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), - Box(position - extents, position + extents)); - guideToAugmented(visitor); + Box bounds(position - extents, position + extents); + CursorRenderVisitor voxelVisitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute(), bounds); + guideToAugmented(voxelVisitor); DefaultMetavoxelRendererImplementation::getVoxelCursorProgram().release(); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + DefaultMetavoxelRendererImplementation::getHeightfieldCursorProgram().bind(); + + CursorRenderVisitor heightfieldVisitor(Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute(), + bounds); + guideToAugmented(heightfieldVisitor); + + DefaultMetavoxelRendererImplementation::getHeightfieldCursorProgram().release(); + + glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisable(GL_POLYGON_OFFSET_FILL); @@ -1450,7 +1463,7 @@ void DefaultMetavoxelRendererImplementation::init() { _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/metavoxel_heightfield_cursor.vert"); _heightfieldCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + - "shaders/metavoxel_heightfield_cursor.frag"); + "shaders/metavoxel_cursor.frag"); _heightfieldCursorProgram.link(); _heightfieldCursorProgram.bind(); @@ -1468,7 +1481,7 @@ void DefaultMetavoxelRendererImplementation::init() { _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/metavoxel_voxel_cursor.vert"); _voxelCursorProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + - "shaders/metavoxel_voxel_cursor.frag"); + "shaders/metavoxel_cursor.frag"); _voxelCursorProgram.link(); } } diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index bda6cfcf23..b2c2190618 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -1477,12 +1477,14 @@ void VoxelBrushTool::render() { glm::vec3 origin = Application::getInstance()->getMouseRayOrigin(); glm::vec3 direction = Application::getInstance()->getMouseRayDirection(); - float distance; - if (!Application::getInstance()->getMetavoxels()->findFirstRayVoxelIntersection(origin, direction, distance)) { + float heightfieldDistance = FLT_MAX, voxelDistance = FLT_MAX; + if (!(Application::getInstance()->getMetavoxels()->findFirstRayHeightfieldIntersection( + origin, direction, heightfieldDistance) | + Application::getInstance()->getMetavoxels()->findFirstRayVoxelIntersection(origin, direction, voxelDistance))) { return; } Application::getInstance()->getMetavoxels()->renderVoxelCursor( - _position = origin + distance * direction, _radius->value()); + _position = origin + qMin(heightfieldDistance, voxelDistance) * direction, _radius->value()); } bool VoxelBrushTool::eventFilter(QObject* watched, QEvent* event) {