From 9923e76968c8f37a71c96d6a9783ec620d7f87c0 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 5 Dec 2018 17:18:26 -0800 Subject: [PATCH] cleanup --- interface/src/ui/overlays/Grid3DOverlay.cpp | 2 +- .../src/RenderableGridEntityItem.cpp | 14 ++++-- libraries/render-utils/src/GeometryCache.cpp | 48 ++++++++++++------- libraries/render-utils/src/GeometryCache.h | 11 ++--- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/interface/src/ui/overlays/Grid3DOverlay.cpp b/interface/src/ui/overlays/Grid3DOverlay.cpp index 87ab0fb2e8..402d170ca9 100644 --- a/interface/src/ui/overlays/Grid3DOverlay.cpp +++ b/interface/src/ui/overlays/Grid3DOverlay.cpp @@ -85,7 +85,7 @@ void Grid3DOverlay::render(RenderArgs* args) { DependencyManager::get()->renderGrid(*batch, minCorner, maxCorner, _minorGridRowDivisions, _minorGridColDivisions, MINOR_GRID_EDGE, _majorGridRowDivisions, _majorGridColDivisions, MAJOR_GRID_EDGE, - gridColor, _drawInFront, _geometryId); + gridColor, _geometryId); } } diff --git a/libraries/entities-renderer/src/RenderableGridEntityItem.cpp b/libraries/entities-renderer/src/RenderableGridEntityItem.cpp index 9156ca33e9..22cf72cec6 100644 --- a/libraries/entities-renderer/src/RenderableGridEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableGridEntityItem.cpp @@ -91,7 +91,13 @@ Item::Bound GridEntityRenderer::getBound() { } ShapeKey GridEntityRenderer::getShapeKey() { - return render::ShapeKey::Builder().withOwnPipeline().withUnlit().withDepthBias(); + auto builder = render::ShapeKey::Builder().withOwnPipeline().withUnlit().withDepthBias(); + + if (isTransparent()) { + builder.withTranslucent(); + } + + return builder.build(); } void GridEntityRenderer::doRender(RenderArgs* args) { @@ -116,7 +122,7 @@ void GridEntityRenderer::doRender(RenderArgs* args) { if (_followCamera) { // Get the camera position rounded to the nearest major grid line // This grid is for UI and should lie on worldlines - glm::vec3 localCameraPosition = glm::inverse(transform.getRotation()) * args->getViewFrustum().getPosition(); + glm::vec3 localCameraPosition = glm::inverse(transform.getRotation()) * (args->getViewFrustum().getPosition() - renderTransform.getTranslation()); localCameraPosition.z = 0; localCameraPosition = (float)_majorGridEvery * glm::round(localCameraPosition / (float)_majorGridEvery); transform.setTranslation(renderTransform.getTranslation() + transform.getRotation() * localCameraPosition); @@ -135,10 +141,8 @@ void GridEntityRenderer::doRender(RenderArgs* args) { const float MINOR_GRID_EDGE = 0.0025f; const float MAJOR_GRID_EDGE = 0.005f; - // FIXME: add layered props to entities - const float LAYERED = false; DependencyManager::get()->renderGrid(*batch, minCorner, maxCorner, minorGridRowDivisions, minorGridColDivisions, MINOR_GRID_EDGE, majorGridRowDivisions, majorGridColDivisions, MAJOR_GRID_EDGE, - gridColor, LAYERED, _geometryId); + gridColor, _geometryId); } \ No newline at end of file diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 38c3106af6..14249f5b9b 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -946,7 +946,7 @@ void GeometryCache::renderWireSphere(gpu::Batch& batch, const glm::vec4& color) void GeometryCache::renderGrid(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, int majorRows, int majorCols, float majorEdge, int minorRows, int minorCols, float minorEdge, - const glm::vec4& color, bool isLayered, int id) { + const glm::vec4& color, int id) { static const glm::vec2 MIN_TEX_COORD(0.0f, 0.0f); static const glm::vec2 MAX_TEX_COORD(1.0f, 1.0f); @@ -978,7 +978,7 @@ void GeometryCache::renderGrid(gpu::Batch& batch, const glm::vec2& minCorner, co } // Set the grid pipeline - useGridPipeline(batch, _registeredGridBuffers[id], isLayered); + useGridPipeline(batch, _registeredGridBuffers[id], color.a < 1.0); renderQuad(batch, minCorner, maxCorner, MIN_TEX_COORD, MAX_TEX_COORD, color, id); } @@ -2115,26 +2115,38 @@ void GeometryCache::useSimpleDrawPipeline(gpu::Batch& batch, bool noBlend) { } } -void GeometryCache::useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer, bool isLayered) { - if (!_gridPipeline) { +void GeometryCache::useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer, bool transparent) { + if (!_gridPipelineOpaque || !_gridPipelineTransparent) { auto program = gpu::Shader::createProgram(shader::render_utils::program::grid); - _gridSlot = 0; - auto stateLayered = std::make_shared(); - stateLayered->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); - PrepareStencil::testMask(*stateLayered); - _gridPipelineLayered = gpu::Pipeline::create(program, stateLayered); - - auto state = std::make_shared(stateLayered->getValues()); const float DEPTH_BIAS = 0.001f; - state->setDepthBias(DEPTH_BIAS); - state->setDepthTest(true, false, gpu::LESS_EQUAL); - PrepareStencil::testMaskDrawShape(*state); - _gridPipeline = gpu::Pipeline::create(program, state); + + { + auto state = std::make_shared(); + state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setBlendFunction(false, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + PrepareStencil::testMaskDrawShape(*state); + state->setCullMode(gpu::State::CULL_NONE); + state->setDepthBias(DEPTH_BIAS); + _gridPipelineOpaque = gpu::Pipeline::create(program, state); + } + + { + auto state = std::make_shared(); + state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setBlendFunction(true, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + PrepareStencil::testMask(*state); + state->setCullMode(gpu::State::CULL_NONE); + state->setDepthBias(DEPTH_BIAS); + _gridPipelineTransparent = gpu::Pipeline::create(program, state); + } } - gpu::PipelinePointer pipeline = isLayered ? _gridPipelineLayered : _gridPipeline; - batch.setPipeline(pipeline); - batch.setUniformBuffer(_gridSlot, gridBuffer); + batch.setPipeline(transparent ? _gridPipelineTransparent : _gridPipelineOpaque); + batch.setUniformBuffer(0, gridBuffer); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index fcbf5ee128..589be4dcc1 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -270,11 +270,7 @@ public: void renderGrid(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, int majorRows, int majorCols, float majorEdge, int minorRows, int minorCols, float minorEdge, - const glm::vec4& color, bool isLayered, int id); - void renderGrid(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, - int rows, int cols, float edge, const glm::vec4& color, bool isLayered, int id) { - renderGrid(batch, minCorner, maxCorner, rows, cols, edge, 0, 0, 0.0f, color, isLayered, id); - } + const glm::vec4& color, int id); void renderBevelCornersRect(gpu::Batch& batch, int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id); @@ -414,9 +410,8 @@ private: }; using GridBuffer = gpu::BufferView; void useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer, bool isLayered); - gpu::PipelinePointer _gridPipeline; - gpu::PipelinePointer _gridPipelineLayered; - int _gridSlot; + gpu::PipelinePointer _gridPipelineOpaque; + gpu::PipelinePointer _gridPipelineTransparent; class BatchItemDetails { public: