Showing the changes to libraries/render-utils/src/RenderDeferredTask.cpp (1 of 7 files). Show all
Unified · Split
| @@ -44,8 +44,6 @@ · 43 unmodified lines | |||
| 44 | #include "DrawHaze.h" | 44 | #include "DrawHaze.h" |
| 45 | #include "HighlightEffect.h" | 45 | #include "HighlightEffect.h" |
| 46 | 46 | ||
| 47 | #include <gpu/StandardShaderLib.h> | ||
| 48 | |||
| 49 | #include <sstream> | 47 | #include <sstream> |
| 50 | 48 | ||
| 51 | using namespace render; | 49 | using namespace render; |
| @@ -193,14 +191,18 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren · 141 unmodified lines | |||
| 193 | 191 | ||
| 194 | task.addJob<EndGPURangeTimer>("HighlightRangeTimer", outlineRangeTimer); | 192 | task.addJob<EndGPURangeTimer>("HighlightRangeTimer", outlineRangeTimer); |
| 195 | 193 | ||
| 196 | { // DEbug the bounds of the rendered items, still look at the zbuffer | 194 | { // Debug the bounds of the rendered items, still look at the zbuffer |
| 197 | task.addJob<DrawBounds>("DrawMetaBounds", metas); | 195 | task.addJob<DrawBounds>("DrawMetaBounds", metas); |
| 198 | task.addJob<DrawBounds>("DrawOpaqueBounds", opaques); | 196 | task.addJob<DrawBounds>("DrawOpaqueBounds", opaques); |
| 199 | task.addJob<DrawBounds>("DrawTransparentBounds", transparents); | 197 | task.addJob<DrawBounds>("DrawTransparentBounds", transparents); |
| 200 | 198 | ||
| 201 | task.addJob<DrawBounds>("DrawLightBounds", lights); | 199 | task.addJob<DrawBounds>("DrawLightBounds", lights); |
| 202 | task.addJob<DrawBounds>("DrawZones", zones); | 200 | task.addJob<DrawBounds>("DrawZones", zones); |
| 203 | task.addJob<DrawFrustums>("DrawFrustums"); | 201 | const auto frustums = task.addJob<ExtractFrustums>("ExtractFrustums"); |
| 202 | const auto viewFrustum = frustums.getN<ExtractFrustums::Output>(ExtractFrustums::VIEW_FRUSTUM); | ||
| 203 | const auto shadowFrustum = frustums.getN<ExtractFrustums::Output>(ExtractFrustums::SHADOW_FRUSTUM); | ||
| 204 | task.addJob<DrawFrustum>("DrawViewFrustum", viewFrustum, glm::vec3(1.0f, 1.0f, 0.0f)); | ||
| 205 | task.addJob<DrawFrustum>("DrawShadowFrustum", shadowFrustum, glm::vec3(0.0f, 0.0f, 1.0f)); | ||
| 204 | 206 | ||
| 205 | // Render.getConfig("RenderMainView.DrawSelectionBounds").enabled = true | 207 | // Render.getConfig("RenderMainView.DrawSelectionBounds").enabled = true |
| 206 | task.addJob<DrawBounds>("DrawSelectionBounds", selectedItems); | 208 | task.addJob<DrawBounds>("DrawSelectionBounds", selectedItems); |
| @@ -533,88 +535,32 @@ void Blit::run(const RenderContextPointer& renderContext, const gpu::Framebuffer · 326 unmodified lines | |||
| 533 | }); | 535 | }); |
| 534 | } | 536 | } |
| 535 | 537 | ||
| 536 | void DrawFrustums::configure(const Config& configuration) { | 538 | void ExtractFrustums::run(const render::RenderContextPointer& renderContext, Output& output) { |
| 537 | _updateFrustums = !configuration.isFrozen; | ||
| 538 | } | ||
| 539 | |||
| 540 | void DrawFrustums::run(const render::RenderContextPointer& renderContext) { | ||
| 541 | assert(renderContext->args); | 539 | assert(renderContext->args); |
| 542 | assert(renderContext->args->_context); | 540 | assert(renderContext->args->_context); |
| 543 | 541 | ||
| 544 | RenderArgs* args = renderContext->args; | 542 | RenderArgs* args = renderContext->args; |
| 545 | static uint8_t indexData[] = { 0, 1, 2, 3, 0, 4, 5, 6, 7, 4, 5, 1, 2, 6, 7, 3 }; | ||
| 546 | |||
| 547 | if (!_frustumMeshIndices._buffer) { | ||
| 548 | auto indices = std::make_shared<gpu::Buffer>(sizeof(indexData), indexData); | ||
| 549 | _frustumMeshIndices = gpu::BufferView(indices, gpu::Element(gpu::SCALAR, gpu::UINT8, gpu::INDEX)); | ||
| 550 | _viewFrustumMeshVertices = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(glm::vec3) * 8, nullptr), gpu::Element::VEC3F_XYZ); | ||
| 551 | _viewFrustumMeshStream.addBuffer(_viewFrustumMeshVertices._buffer, _viewFrustumMeshVertices._offset, _viewFrustumMeshVertices._stride); | ||
| 552 | _shadowFrustumMeshVertices = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(glm::vec3) * 8, nullptr), gpu::Element::VEC3F_XYZ); | ||
| 553 | _shadowFrustumMeshStream.addBuffer(_shadowFrustumMeshVertices._buffer, _shadowFrustumMeshVertices._offset, _shadowFrustumMeshVertices._stride); | ||
| 554 | } | ||
| 555 | 543 | ||
| 556 | if (_updateFrustums) { | 544 | // Return view frustum |
| 557 | updateFrustum(args->getViewFrustum(), _viewFrustumMeshVertices); | 545 | auto& viewFrustum = output[VIEW_FRUSTUM].edit<ViewFrustumPointer>(); |
| 546 | if (!viewFrustum) { | ||
| 547 | viewFrustum = std::make_shared<ViewFrustum>(args->getViewFrustum()); | ||
| 548 | } else { | ||
| 549 | *viewFrustum = args->getViewFrustum(); | ||
| 550 | } | ||
| 558 | 551 | ||
| 559 | auto lightStage = renderContext->_scene->getStage<LightStage>(); | 552 | // Return shadow frustum |
| 560 | assert(lightStage); | 553 | auto& shadowFrustum = output[SHADOW_FRUSTUM].edit<ViewFrustumPointer>(); |
| 554 | auto lightStage = args->_scene->getStage<LightStage>(LightStage::getName()); | ||
| 555 | if (lightStage) { | ||
| 556 | auto globalShadow = lightStage->getCurrentKeyShadow(); | ||
| 561 | 557 | ||
| 562 | const auto globalShadow = lightStage->getCurrentKeyShadow(); | ||
| 563 | if (globalShadow) { | 558 | if (globalShadow) { |
| 564 | updateFrustum(*globalShadow->getFrustum(), _shadowFrustumMeshVertices); | 559 | shadowFrustum = globalShadow->getFrustum(); |
| 560 | } else { | ||
| 561 | shadowFrustum.reset(); | ||
| 565 | } | 562 | } |
| 563 | } else { | ||
| 564 | shadowFrustum.reset(); | ||
| 566 | } | 565 | } |
| 567 | |||
| 568 | if (!_pipeline) { | ||
| 569 | auto vs = gpu::StandardShaderLib::getDrawTransformVertexPositionVS(); | ||
| 570 | auto ps = gpu::StandardShaderLib::getDrawColorPS(); | ||
| 571 | gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps); | ||
| 572 | |||
| 573 | gpu::Shader::BindingSet slotBindings; | ||
| 574 | slotBindings.insert(gpu::Shader::Binding("color", 0)); | ||
| 575 | gpu::Shader::makeProgram(*program, slotBindings); | ||
| 576 | |||
| 577 | gpu::StatePointer state = gpu::StatePointer(new gpu::State()); | ||
| 578 | state->setDepthTest(gpu::State::DepthTest(true, false)); | ||
| 579 | _pipeline = gpu::Pipeline::create(program, state); | ||
| 580 | } | ||
| 581 | |||
| 582 | // Render the frustums in wireframe | ||
| 583 | gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { | ||
| 584 | args->_batch = &batch; | ||
| 585 | batch.setViewportTransform(args->_viewport); | ||
| 586 | batch.setStateScissorRect(args->_viewport); | ||
| 587 | |||
| 588 | glm::mat4 projMat; | ||
| 589 | Transform viewMat; | ||
| 590 | args->getViewFrustum().evalProjectionMatrix(projMat); | ||
| 591 | args->getViewFrustum().evalViewTransform(viewMat); | ||
| 592 | |||
| 593 | batch.setProjectionTransform(projMat); | ||
| 594 | batch.setViewTransform(viewMat); | ||
| 595 | batch.setPipeline(_pipeline); | ||
| 596 | batch.setIndexBuffer(_frustumMeshIndices); | ||
| 597 | |||
| 598 | batch._glUniform4f(0, 1.0f, 1.0f, 0.0f, 1.0f); | ||
| 599 | batch.setInputStream(0, _viewFrustumMeshStream); | ||
| 600 | batch.drawIndexed(gpu::LINE_STRIP, sizeof(indexData) / sizeof(indexData[0]), 0U); | ||
| 601 | |||
| 602 | batch._glUniform4f(0, 1.0f, 0.0f, 0.0f, 1.0f); | ||
| 603 | batch.setInputStream(0, _shadowFrustumMeshStream); | ||
| 604 | batch.drawIndexed(gpu::LINE_STRIP, sizeof(indexData) / sizeof(indexData[0]), 0U); | ||
| 605 | |||
| 606 | args->_batch = nullptr; | ||
| 607 | }); | ||
| 608 | } | ||
| 609 | |||
| 610 | void DrawFrustums::updateFrustum(const ViewFrustum& frustum, gpu::BufferView& vertexBuffer) { | ||
| 611 | auto& vertices = vertexBuffer.edit<std::array<glm::vec3, 8U> >(); | ||
| 612 | vertices[0] = frustum.getNearTopLeft(); | ||
| 613 | vertices[1] = frustum.getNearTopRight(); | ||
| 614 | vertices[2] = frustum.getNearBottomRight(); | ||
| 615 | vertices[3] = frustum.getNearBottomLeft(); | ||
| 616 | vertices[4] = frustum.getFarTopLeft(); | ||
| 617 | vertices[5] = frustum.getFarTopRight(); | ||
| 618 | vertices[6] = frustum.getFarBottomRight(); | ||
| 619 | vertices[7] = frustum.getFarBottomLeft(); | ||
| 620 | } | 566 | } |