diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 8547c5adb0..e0192b5f85 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -159,6 +159,11 @@ RenderDeferredTask::RenderDeferredTask(RenderFetchCullSortTask::Output items) { // Debugging stages { + + + // Bounds do not draw on stencil buffer, so they must come last + addJob("DrawMetaBounds", metas); + // Debugging Deferred buffer job const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer)); addJob("DebugDeferredBuffer", debugFramebuffers); diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index 7550d2326b..45a32c1aaf 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -24,8 +24,6 @@ #include -#include -#include #include "nop_frag.h" using namespace render; @@ -182,57 +180,4 @@ void DrawBackground::run(const SceneContextPointer& sceneContext, const RenderCo args->_batch = nullptr; } -const gpu::PipelinePointer DrawBounds::getPipeline() { - if (!_boundsPipeline) { - auto vs = gpu::Shader::createVertex(std::string(drawItemBounds_vert)); - auto ps = gpu::Shader::createPixel(std::string(drawItemBounds_frag)); - gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps); - gpu::Shader::BindingSet slotBindings; - gpu::Shader::makeProgram(*program, slotBindings); - - _cornerLocation = program->getUniforms().findLocation("inBoundPos"); - _scaleLocation = program->getUniforms().findLocation("inBoundDim"); - - auto state = std::make_shared(); - state->setDepthTest(true, false, gpu::LESS_EQUAL); - state->setBlendFunction(true, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::DEST_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ZERO); - - _boundsPipeline = gpu::Pipeline::create(program, state); - } - return _boundsPipeline; -} - -void DrawBounds::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, - const Inputs& items) { - RenderArgs* args = renderContext->args; - - gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { - args->_batch = &batch; - - // Setup projection - glm::mat4 projMat; - Transform viewMat; - args->getViewFrustum().evalProjectionMatrix(projMat); - args->getViewFrustum().evalViewTransform(viewMat); - batch.setProjectionTransform(projMat); - batch.setViewTransform(viewMat); - batch.setModelTransform(Transform()); - - // Bind program - batch.setPipeline(getPipeline()); - assert(_cornerLocation >= 0); - assert(_scaleLocation >= 0); - - // Render bounds - for (const auto& item : items) { - batch._glUniform3fv(_cornerLocation, 1, (const float*)(&item.bound.getCorner())); - batch._glUniform3fv(_scaleLocation, 1, (const float*)(&item.bound.getScale())); - - static const int NUM_VERTICES_PER_CUBE = 24; - batch.draw(gpu::LINES, NUM_VERTICES_PER_CUBE, 0); - } - }); -} diff --git a/libraries/render-utils/src/RenderForwardTask.h b/libraries/render-utils/src/RenderForwardTask.h index a957f7493e..62cbca4382 100755 --- a/libraries/render-utils/src/RenderForwardTask.h +++ b/libraries/render-utils/src/RenderForwardTask.h @@ -68,25 +68,4 @@ public: const Inputs& background); }; -class DrawBounds { -public: - class Config : public render::JobConfig { - public: - Config() : JobConfig(false) {} - }; - - using Inputs = render::ItemBounds; - using JobModel = render::Job::ModelI; - - void configure(const Config& configuration) {} - void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, - const Inputs& items); - -private: - const gpu::PipelinePointer getPipeline(); - gpu::PipelinePointer _boundsPipeline; - int _cornerLocation { -1 }; - int _scaleLocation { -1 }; -}; - #endif // hifi_RenderForwardTask_h diff --git a/libraries/render/src/render/DrawTask.cpp b/libraries/render/src/render/DrawTask.cpp index 1c9a92c511..2829c6f8e7 100755 --- a/libraries/render/src/render/DrawTask.cpp +++ b/libraries/render/src/render/DrawTask.cpp @@ -19,6 +19,10 @@ #include #include + +#include +#include + using namespace render; void render::renderItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems, int maxDrawnItems) { @@ -134,3 +138,59 @@ void DrawLight::run(const SceneContextPointer& sceneContext, const RenderContext auto config = std::static_pointer_cast(renderContext->jobConfig); config->setNumDrawn((int)inLights.size()); } + +const gpu::PipelinePointer DrawBounds::getPipeline() { + if (!_boundsPipeline) { + auto vs = gpu::Shader::createVertex(std::string(drawItemBounds_vert)); + auto ps = gpu::Shader::createPixel(std::string(drawItemBounds_frag)); + gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps); + + gpu::Shader::BindingSet slotBindings; + gpu::Shader::makeProgram(*program, slotBindings); + + _cornerLocation = program->getUniforms().findLocation("inBoundPos"); + _scaleLocation = program->getUniforms().findLocation("inBoundDim"); + + auto state = std::make_shared(); + state->setDepthTest(true, false, gpu::LESS_EQUAL); + state->setBlendFunction(true, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::DEST_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ZERO); + + _boundsPipeline = gpu::Pipeline::create(program, state); + } + return _boundsPipeline; +} + +void DrawBounds::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, + const Inputs& items) { + RenderArgs* args = renderContext->args; + + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { + args->_batch = &batch; + + // Setup projection + glm::mat4 projMat; + Transform viewMat; + args->getViewFrustum().evalProjectionMatrix(projMat); + args->getViewFrustum().evalViewTransform(viewMat); + batch.setProjectionTransform(projMat); + batch.setViewTransform(viewMat); + batch.setModelTransform(Transform()); + + // Bind program + batch.setPipeline(getPipeline()); + assert(_cornerLocation >= 0); + assert(_scaleLocation >= 0); + + // Render bounds + for (const auto& item : items) { + batch._glUniform3fv(_cornerLocation, 1, (const float*)(&item.bound.getCorner())); + batch._glUniform3fv(_scaleLocation, 1, (const float*)(&item.bound.getScale())); + + static const int NUM_VERTICES_PER_CUBE = 24; + batch.draw(gpu::LINES, NUM_VERTICES_PER_CUBE, 0); + } + }); +} + diff --git a/libraries/render/src/render/DrawTask.h b/libraries/render/src/render/DrawTask.h index aa564980c4..27f07921c3 100755 --- a/libraries/render/src/render/DrawTask.h +++ b/libraries/render/src/render/DrawTask.h @@ -50,6 +50,27 @@ protected: int _maxDrawn; // initialized by Config }; +class DrawBounds { +public: + class Config : public render::JobConfig { + public: + Config() : JobConfig(false) {} + }; + + using Inputs = render::ItemBounds; + using JobModel = render::Job::ModelI; + + void configure(const Config& configuration) {} + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, + const Inputs& items); + +private: + const gpu::PipelinePointer getPipeline(); + gpu::PipelinePointer _boundsPipeline; + int _cornerLocation { -1 }; + int _scaleLocation { -1 }; +}; + } #endif // hifi_render_DrawTask_h