Showing the changes to libraries/render-utils/src/RenderDeferredTask.cpp (1 of 10 files). Show all
Unified · Split
| @@ -28,6 +28,26 @@ · 27 unmodified lines | |||
| 28 | #include "AmbientOcclusionEffect.h" | 28 | #include "AmbientOcclusionEffect.h" |
| 29 | #include "AntialiasingEffect.h" | 29 | #include "AntialiasingEffect.h" |
| 30 | 30 | ||
| 31 | #include "model_vert.h" | ||
| 32 | #include "model_shadow_vert.h" | ||
| 33 | #include "model_normal_map_vert.h" | ||
| 34 | #include "model_lightmap_vert.h" | ||
| 35 | #include "model_lightmap_normal_map_vert.h" | ||
| 36 | #include "skin_model_vert.h" | ||
| 37 | #include "skin_model_shadow_vert.h" | ||
| 38 | #include "skin_model_normal_map_vert.h" | ||
| 39 | |||
| 40 | #include "model_frag.h" | ||
| 41 | #include "model_shadow_frag.h" | ||
| 42 | #include "model_normal_map_frag.h" | ||
| 43 | #include "model_normal_specular_map_frag.h" | ||
| 44 | #include "model_specular_map_frag.h" | ||
| 45 | #include "model_lightmap_frag.h" | ||
| 46 | #include "model_lightmap_normal_map_frag.h" | ||
| 47 | #include "model_lightmap_normal_specular_map_frag.h" | ||
| 48 | #include "model_lightmap_specular_map_frag.h" | ||
| 49 | #include "model_translucent_frag.h" | ||
| 50 | |||
| 31 | #include "overlay3D_vert.h" | 51 | #include "overlay3D_vert.h" |
| 32 | #include "overlay3D_frag.h" | 52 | #include "overlay3D_frag.h" |
| 33 | 53 | ||
| @@ -35,6 +55,7 @@ · 1 unmodified line | |||
| 35 | 55 | ||
| 36 | using namespace render; | 56 | using namespace render; |
| 37 | 57 | ||
| 58 | void initDeferredPipelines(render::ShapePlumber& plumber); | ||
| 38 | 59 | ||
| 39 | void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { | 60 | void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { |
| 40 | DependencyManager::get<DeferredLightingEffect>()->prepare(renderContext->getArgs()); | 61 | DependencyManager::get<DeferredLightingEffect>()->prepare(renderContext->getArgs()); |
| @@ -50,6 +71,15 @@ void ToneMappingDeferred::run(const SceneContextPointer& sceneContext, const Ren · 9 unmodified lines | |||
| 50 | } | 71 | } |
| 51 | 72 | ||
| 52 | RenderDeferredTask::RenderDeferredTask() : Task() { | 73 | RenderDeferredTask::RenderDeferredTask() : Task() { |
| 74 | // Prepare the ShapePipelines | ||
| 75 | ShapePlumberPointer shapePlumber = std::make_shared<ShapePlumber>([](gpu::Batch& batch, ShapePipelinePointer pipeline) { | ||
| 76 | if ((pipeline->locations->normalFittingMapUnit > -1)) { | ||
| 77 | batch.setResourceTexture(pipeline->locations->normalFittingMapUnit, | ||
| 78 | DependencyManager::get<TextureCache>()->getNormalFittingTexture()); | ||
| 79 | } | ||
| 80 | }); | ||
| 81 | initDeferredPipelines(*shapePlumber); | ||
| 82 | |||
| 53 | // CPU only, create the list of renderedOpaques items | 83 | // CPU only, create the list of renderedOpaques items |
| 54 | _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque", | 84 | _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque", |
| 55 | FetchItems([](const RenderContextPointer& context, int count) { | 85 | FetchItems([](const RenderContextPointer& context, int count) { |
| @@ -75,7 +105,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() { · 19 unmodified lines | |||
| 75 | _jobs.push_back(Job(new PrepareDeferred::JobModel("PrepareDeferred"))); | 105 | _jobs.push_back(Job(new PrepareDeferred::JobModel("PrepareDeferred"))); |
| 76 | 106 | ||
| 77 | // Render opaque objects in DeferredBuffer | 107 | // Render opaque objects in DeferredBuffer |
| 78 | _jobs.push_back(Job(new DrawOpaqueDeferred::JobModel("DrawOpaqueDeferred", renderedOpaques))); | 108 | _jobs.push_back(Job(new DrawOpaqueDeferred::JobModel("DrawOpaqueDeferred", renderedOpaques, DrawOpaqueDeferred(shapePlumber)))); |
| 79 | 109 | ||
| 80 | // Once opaque is all rendered create stencil background | 110 | // Once opaque is all rendered create stencil background |
| 81 | _jobs.push_back(Job(new DrawStencilDeferred::JobModel("DrawOpaqueStencil"))); | 111 | _jobs.push_back(Job(new DrawStencilDeferred::JobModel("DrawOpaqueStencil"))); |
| @@ -100,7 +130,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() { · 18 unmodified lines | |||
| 100 | _antialiasingJobIndex = (int)_jobs.size() - 1; | 130 | _antialiasingJobIndex = (int)_jobs.size() - 1; |
| 101 | 131 | ||
| 102 | // Render transparent objects forward in LigthingBuffer | 132 | // Render transparent objects forward in LigthingBuffer |
| 103 | _jobs.push_back(Job(new DrawTransparentDeferred::JobModel("TransparentDeferred", renderedTransparents))); | 133 | _jobs.push_back(Job(new DrawTransparentDeferred::JobModel("TransparentDeferred", renderedTransparents, DrawTransparentDeferred(shapePlumber)))); |
| 104 | 134 | ||
| 105 | // Lighting Buffer ready for tone mapping | 135 | // Lighting Buffer ready for tone mapping |
| 106 | _jobs.push_back(Job(new ToneMappingDeferred::JobModel("ToneMapping"))); | 136 | _jobs.push_back(Job(new ToneMappingDeferred::JobModel("ToneMapping"))); |
| @@ -121,7 +151,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() { · 14 unmodified lines | |||
| 121 | _drawStatusJobIndex = (int)_jobs.size() - 1; | 151 | _drawStatusJobIndex = (int)_jobs.size() - 1; |
| 122 | } | 152 | } |
| 123 | 153 | ||
| 124 | _jobs.push_back(Job(new DrawOverlay3D::JobModel("DrawOverlay3D"))); | 154 | _jobs.push_back(Job(new DrawOverlay3D::JobModel("DrawOverlay3D", DrawOverlay3D(shapePlumber)))); |
| 125 | 155 | ||
| 126 | _jobs.push_back(Job(new HitEffect::JobModel("HitEffect"))); | 156 | _jobs.push_back(Job(new HitEffect::JobModel("HitEffect"))); |
| 127 | _jobs.back().setEnabled(false); | 157 | _jobs.back().setEnabled(false); |
| @@ -193,7 +223,7 @@ void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const Rend · 65 unmodified lines | |||
| 193 | batch.setProjectionTransform(projMat); | 223 | batch.setProjectionTransform(projMat); |
| 194 | batch.setViewTransform(viewMat); | 224 | batch.setViewTransform(viewMat); |
| 195 | 225 | ||
| 196 | renderShapes(sceneContext, renderContext, _deferredPipelineLib, inItems, opaque.maxDrawn); | 226 | renderShapes(sceneContext, renderContext, _shapePlumber, inItems, opaque.maxDrawn); |
| 197 | args->_batch = nullptr; | 227 | args->_batch = nullptr; |
| 198 | }); | 228 | }); |
| 199 | } | 229 | } |
| @@ -219,11 +249,12 @@ void DrawTransparentDeferred::run(const SceneContextPointer& sceneContext, const · 19 unmodified lines | |||
| 219 | batch.setProjectionTransform(projMat); | 249 | batch.setProjectionTransform(projMat); |
| 220 | batch.setViewTransform(viewMat); | 250 | batch.setViewTransform(viewMat); |
| 221 | 251 | ||
| 222 | renderShapes(sceneContext, renderContext, _deferredPipelineLib, inItems, transparent.maxDrawn); | 252 | renderShapes(sceneContext, renderContext, _shapePlumber, inItems, transparent.maxDrawn); |
| 223 | args->_batch = nullptr; | 253 | args->_batch = nullptr; |
| 224 | }); | 254 | }); |
| 225 | } | 255 | } |
| 226 | 256 | ||
| 257 | // TODO: Move this to the shapePlumber | ||
| 227 | gpu::PipelinePointer DrawOverlay3D::_opaquePipeline; | 258 | gpu::PipelinePointer DrawOverlay3D::_opaquePipeline; |
| 228 | const gpu::PipelinePointer& DrawOverlay3D::getOpaquePipeline() { | 259 | const gpu::PipelinePointer& DrawOverlay3D::getOpaquePipeline() { |
| 229 | if (!_opaquePipeline) { | 260 | if (!_opaquePipeline) { |
| @@ -292,7 +323,7 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon · 62 unmodified lines | |||
| 292 | 323 | ||
| 293 | batch.setPipeline(getOpaquePipeline()); | 324 | batch.setPipeline(getOpaquePipeline()); |
| 294 | batch.setResourceTexture(0, args->_whiteTexture); | 325 | batch.setResourceTexture(0, args->_whiteTexture); |
| 295 | renderShapes(sceneContext, renderContext, _deferredPipelineLib, inItems, renderContext->getItemsConfig().overlay3D.maxDrawn); | 326 | renderShapes(sceneContext, renderContext, _shapePlumber, inItems, renderContext->getItemsConfig().overlay3D.maxDrawn); |
| 296 | }); | 327 | }); |
| 297 | args->_batch = nullptr; | 328 | args->_batch = nullptr; |
| 298 | args->_whiteTexture.reset(); | 329 | args->_whiteTexture.reset(); |
| @@ -485,3 +516,129 @@ int RenderDeferredTask::getToneMappingToneCurve() const { · 186 unmodified lines | |||
| 485 | } | 516 | } |
| 486 | } | 517 | } |
| 487 | 518 | ||
| 519 | void initDeferredPipelines(render::ShapePlumber& plumber) { | ||
| 520 | using Key = render::ShapeKey; | ||
| 521 | |||
| 522 | // Vertex shaders | ||
| 523 | auto modelVertex = gpu::Shader::createVertex(std::string(model_vert)); | ||
| 524 | auto modelNormalMapVertex = gpu::Shader::createVertex(std::string(model_normal_map_vert)); | ||
| 525 | auto modelLightmapVertex = gpu::Shader::createVertex(std::string(model_lightmap_vert)); | ||
| 526 | auto modelLightmapNormalMapVertex = gpu::Shader::createVertex(std::string(model_lightmap_normal_map_vert)); | ||
| 527 | auto modelShadowVertex = gpu::Shader::createVertex(std::string(model_shadow_vert)); | ||
| 528 | auto skinModelVertex = gpu::Shader::createVertex(std::string(skin_model_vert)); | ||
| 529 | auto skinModelNormalMapVertex = gpu::Shader::createVertex(std::string(skin_model_normal_map_vert)); | ||
| 530 | auto skinModelShadowVertex = gpu::Shader::createVertex(std::string(skin_model_shadow_vert)); | ||
| 531 | |||
| 532 | // Pixel shaders | ||
| 533 | auto modelPixel = gpu::Shader::createPixel(std::string(model_frag)); | ||
| 534 | auto modelNormalMapPixel = gpu::Shader::createPixel(std::string(model_normal_map_frag)); | ||
| 535 | auto modelSpecularMapPixel = gpu::Shader::createPixel(std::string(model_specular_map_frag)); | ||
| 536 | auto modelNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_normal_specular_map_frag)); | ||
| 537 | auto modelTranslucentPixel = gpu::Shader::createPixel(std::string(model_translucent_frag)); | ||
| 538 | auto modelShadowPixel = gpu::Shader::createPixel(std::string(model_shadow_frag)); | ||
| 539 | auto modelLightmapPixel = gpu::Shader::createPixel(std::string(model_lightmap_frag)); | ||
| 540 | auto modelLightmapNormalMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_map_frag)); | ||
| 541 | auto modelLightmapSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_specular_map_frag)); | ||
| 542 | auto modelLightmapNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_specular_map_frag)); | ||
| 543 | |||
| 544 | // Fill the pipelineLib | ||
| 545 | |||
| 546 | plumber.addPipeline( | ||
| 547 | Key::Builder(), | ||
| 548 | modelVertex, modelPixel); | ||
| 549 | |||
| 550 | plumber.addPipeline( | ||
| 551 | Key::Builder().withTangents(), | ||
| 552 | modelNormalMapVertex, modelNormalMapPixel); | ||
| 553 | |||
| 554 | plumber.addPipeline( | ||
| 555 | Key::Builder().withSpecular(), | ||
| 556 | modelVertex, modelSpecularMapPixel); | ||
| 557 | |||
| 558 | plumber.addPipeline( | ||
| 559 | Key::Builder().withTangents().withSpecular(), | ||
| 560 | modelNormalMapVertex, modelNormalSpecularMapPixel); | ||
| 561 | |||
| 562 | |||
| 563 | plumber.addPipeline( | ||
| 564 | Key::Builder().withTranslucent(), | ||
| 565 | modelVertex, modelTranslucentPixel); | ||
| 566 | // FIXME Ignore lightmap for translucents meshpart | ||
| 567 | plumber.addPipeline( | ||
| 568 | Key::Builder().withTranslucent().withLightmap(), | ||
| 569 | modelVertex, modelTranslucentPixel); | ||
| 570 | |||
| 571 | plumber.addPipeline( | ||
| 572 | Key::Builder().withTangents().withTranslucent(), | ||
| 573 | modelNormalMapVertex, modelTranslucentPixel); | ||
| 574 | |||
| 575 | plumber.addPipeline( | ||
| 576 | Key::Builder().withSpecular().withTranslucent(), | ||
| 577 | modelVertex, modelTranslucentPixel); | ||
| 578 | |||
| 579 | plumber.addPipeline( | ||
| 580 | Key::Builder().withTangents().withSpecular().withTranslucent(), | ||
| 581 | modelNormalMapVertex, modelTranslucentPixel); | ||
| 582 | |||
| 583 | |||
| 584 | plumber.addPipeline( | ||
| 585 | Key::Builder().withLightmap(), | ||
| 586 | modelLightmapVertex, modelLightmapPixel); | ||
| 587 | |||
| 588 | plumber.addPipeline( | ||
| 589 | Key::Builder().withLightmap().withTangents(), | ||
| 590 | modelLightmapNormalMapVertex, modelLightmapNormalMapPixel); | ||
| 591 | |||
| 592 | plumber.addPipeline( | ||
| 593 | Key::Builder().withLightmap().withSpecular(), | ||
| 594 | modelLightmapVertex, modelLightmapSpecularMapPixel); | ||
| 595 | |||
| 596 | plumber.addPipeline( | ||
| 597 | Key::Builder().withLightmap().withTangents().withSpecular(), | ||
| 598 | modelLightmapNormalMapVertex, modelLightmapNormalSpecularMapPixel); | ||
| 599 | |||
| 600 | |||
| 601 | plumber.addPipeline( | ||
| 602 | Key::Builder().withSkinned(), | ||
| 603 | skinModelVertex, modelPixel); | ||
| 604 | |||
| 605 | plumber.addPipeline( | ||
| 606 | Key::Builder().withSkinned().withTangents(), | ||
| 607 | skinModelNormalMapVertex, modelNormalMapPixel); | ||
| 608 | |||
| 609 | plumber.addPipeline( | ||
| 610 | Key::Builder().withSkinned().withSpecular(), | ||
| 611 | skinModelVertex, modelSpecularMapPixel); | ||
| 612 | |||
| 613 | plumber.addPipeline( | ||
| 614 | Key::Builder().withSkinned().withTangents().withSpecular(), | ||
| 615 | skinModelNormalMapVertex, modelNormalSpecularMapPixel); | ||
| 616 | |||
| 617 | |||
| 618 | plumber.addPipeline( | ||
| 619 | Key::Builder().withSkinned().withTranslucent(), | ||
| 620 | skinModelVertex, modelTranslucentPixel); | ||
| 621 | |||
| 622 | plumber.addPipeline( | ||
| 623 | Key::Builder().withSkinned().withTangents().withTranslucent(), | ||
| 624 | skinModelNormalMapVertex, modelTranslucentPixel); | ||
| 625 | |||
| 626 | plumber.addPipeline( | ||
| 627 | Key::Builder().withSkinned().withSpecular().withTranslucent(), | ||
| 628 | skinModelVertex, modelTranslucentPixel); | ||
| 629 | |||
| 630 | plumber.addPipeline( | ||
| 631 | Key::Builder().withSkinned().withTangents().withSpecular().withTranslucent(), | ||
| 632 | skinModelNormalMapVertex, modelTranslucentPixel); | ||
| 633 | |||
| 634 | |||
| 635 | plumber.addPipeline( | ||
| 636 | Key::Builder().withDepthOnly(), | ||
| 637 | modelShadowVertex, modelShadowPixel); | ||
| 638 | |||
| 639 | |||
| 640 | plumber.addPipeline( | ||
| 641 | Key::Builder().withSkinned().withDepthOnly(), | ||
| 642 | skinModelShadowVertex, modelShadowPixel); | ||
| 643 | } | ||
| 644 | |||