History

Replace ShapePipelineLib abstract with ShapePlumber instanced class

Zach Pomerantz committed 10 years ago

Commit 4ff2b851 parent 533287310 files · +330 −329Browse files

Showing the changes to libraries/render-utils/src/RenderDeferredTask.cpp (1 of 10 files). Show all

Unified · Split

libraries/render-utils/src/RenderDeferredTask.cpp+163−6
@@ -28,6 +28,26 @@ · 27 unmodified lines
2828 #include "AmbientOcclusionEffect.h"
2929 #include "AntialiasingEffect.h"
3030
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+
3151 #include "overlay3D_vert.h"
3252 #include "overlay3D_frag.h"
3353
@@ -35,6 +55,7 @@ · 1 unmodified line
3555
3656 using namespace render;
3757
58+void initDeferredPipelines(render::ShapePlumber& plumber);
3859
3960 void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
4061 DependencyManager::get<DeferredLightingEffect>()->prepare(renderContext->getArgs());
@@ -50,6 +71,15 @@ void ToneMappingDeferred::run(const SceneContextPointer& sceneContext, const Ren · 9 unmodified lines
5071 }
5172
5273 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+
5383 // CPU only, create the list of renderedOpaques items
5484 _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque",
5585 FetchItems([](const RenderContextPointer& context, int count) {
@@ -75,7 +105,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() { · 19 unmodified lines
75105 _jobs.push_back(Job(new PrepareDeferred::JobModel("PrepareDeferred")));
76106
77107 // 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))));
79109
80110 // Once opaque is all rendered create stencil background
81111 _jobs.push_back(Job(new DrawStencilDeferred::JobModel("DrawOpaqueStencil")));
@@ -100,7 +130,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() { · 18 unmodified lines
100130 _antialiasingJobIndex = (int)_jobs.size() - 1;
101131
102132 // 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))));
104134
105135 // Lighting Buffer ready for tone mapping
106136 _jobs.push_back(Job(new ToneMappingDeferred::JobModel("ToneMapping")));
@@ -121,7 +151,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() { · 14 unmodified lines
121151 _drawStatusJobIndex = (int)_jobs.size() - 1;
122152 }
123153
124− _jobs.push_back(Job(new DrawOverlay3D::JobModel("DrawOverlay3D")));
154+ _jobs.push_back(Job(new DrawOverlay3D::JobModel("DrawOverlay3D", DrawOverlay3D(shapePlumber))));
125155
126156 _jobs.push_back(Job(new HitEffect::JobModel("HitEffect")));
127157 _jobs.back().setEnabled(false);
@@ -193,7 +223,7 @@ void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const Rend · 65 unmodified lines
193223 batch.setProjectionTransform(projMat);
194224 batch.setViewTransform(viewMat);
195225
196− renderShapes(sceneContext, renderContext, _deferredPipelineLib, inItems, opaque.maxDrawn);
226+ renderShapes(sceneContext, renderContext, _shapePlumber, inItems, opaque.maxDrawn);
197227 args->_batch = nullptr;
198228 });
199229 }
@@ -219,11 +249,12 @@ void DrawTransparentDeferred::run(const SceneContextPointer& sceneContext, const · 19 unmodified lines
219249 batch.setProjectionTransform(projMat);
220250 batch.setViewTransform(viewMat);
221251
222− renderShapes(sceneContext, renderContext, _deferredPipelineLib, inItems, transparent.maxDrawn);
252+ renderShapes(sceneContext, renderContext, _shapePlumber, inItems, transparent.maxDrawn);
223253 args->_batch = nullptr;
224254 });
225255 }
226256
257+// TODO: Move this to the shapePlumber
227258 gpu::PipelinePointer DrawOverlay3D::_opaquePipeline;
228259 const gpu::PipelinePointer& DrawOverlay3D::getOpaquePipeline() {
229260 if (!_opaquePipeline) {
@@ -292,7 +323,7 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon · 62 unmodified lines
292323
293324 batch.setPipeline(getOpaquePipeline());
294325 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);
296327 });
297328 args->_batch = nullptr;
298329 args->_whiteTexture.reset();
@@ -485,3 +516,129 @@ int RenderDeferredTask::getToneMappingToneCurve() const { · 186 unmodified lines
485516 }
486517 }
487518
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+