History

Move pipeline init to separate file

Zach Pomerantz committed 10 years ago

Commit 5d49eac1 parent df894d32 files · +240 −222Browse files

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

Unified · Split

libraries/render-utils/src/RenderDeferredTask.cpp+6−222
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 // render-utils/src/
55 //
66 // Created by Sam Gateau on 5/29/15.
7−// Copyright 20154 High Fidelity, Inc.
7+// Copyright 2016 High Fidelity, Inc.
88 //
99 // Distributed under the Apache License, Version 2.0.
1010 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@@ -15,7 +15,6 @@ · 4 unmodified lines
1515 #include <RenderArgs.h>
1616 #include <ViewFrustum.h>
1717 #include <gpu/Context.h>
18−#include <gpu/StandardShaderLib.h>
1918
2019 #include "DebugDeferredBuffer.h"
2120 #include "DeferredLightingEffect.h"
@@ -31,34 +30,11 @@ · 9 unmodified lines
3130
3231 #include "RenderDeferredTask.h"
3332
34−#include "model_vert.h"
35−#include "model_shadow_vert.h"
36−#include "model_normal_map_vert.h"
37−#include "model_lightmap_vert.h"
38−#include "model_lightmap_normal_map_vert.h"
39−#include "skin_model_vert.h"
40−#include "skin_model_shadow_vert.h"
41−#include "skin_model_normal_map_vert.h"
42−
43−#include "model_frag.h"
44−#include "model_shadow_frag.h"
45−#include "model_normal_map_frag.h"
46−#include "model_normal_specular_map_frag.h"
47−#include "model_specular_map_frag.h"
48−#include "model_lightmap_frag.h"
49−#include "model_lightmap_normal_map_frag.h"
50−#include "model_lightmap_normal_specular_map_frag.h"
51−#include "model_lightmap_specular_map_frag.h"
52−#include "model_translucent_frag.h"
53−
54−#include "overlay3D_vert.h"
55−#include "overlay3D_frag.h"
56−
57−#include "drawOpaqueStencil_frag.h"
58−
5933 using namespace render;
6034
61−void initDeferredPipelines(render::ShapePlumber& plumber);
35+extern void initOverlay3DPipelines(render::ShapePlumber& plumber);
36+extern void initStencilPipelines(render::ShapePlumber& plumber);
37+extern void initDeferredPipelines(render::ShapePlumber& plumber);
6238
6339 void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
6440 DependencyManager::get<DeferredLightingEffect>()->prepare(renderContext->args);
@@ -181,25 +157,7 @@ void DrawDeferred::run(const SceneContextPointer& sceneContext, const RenderCont · 116 unmodified lines
181157 }
182158
183159 DrawOverlay3D::DrawOverlay3D() : _shapePlumber{ std::make_shared<ShapePlumber>() } {
184− auto vs = gpu::Shader::createVertex(std::string(overlay3D_vert));
185− auto ps = gpu::Shader::createPixel(std::string(overlay3D_frag));
186− auto program = gpu::Shader::createProgram(vs, ps);
187−
188− auto opaqueState = std::make_shared<gpu::State>();
189− opaqueState->setDepthTest(false);
190− opaqueState->setBlendFunction(true,
191− // Additive blending
192− gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
193−
194− auto transparentState = std::make_shared<gpu::State>();
195− transparentState->setDepthTest(false);
196− transparentState->setBlendFunction(true,
197− // For transparency, keep the highlight intensity
198− gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
199− gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
200−
201− _shapePlumber->addPipeline(ShapeKey::Filter::Builder().withOpaque(), program, opaqueState);
202− _shapePlumber->addPipeline(ShapeKey::Filter::Builder().withTranslucent(), program, transparentState);
160+ initOverlay3DPipelines(*_shapePlumber);
203161 }
204162
205163 void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
@@ -260,18 +218,7 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon · 54 unmodified lines
260218 }
261219
262220 DrawStencilDeferred::DrawStencilDeferred() : _shapePlumber{ std::make_shared<ShapePlumber>() } {
263− const gpu::int8 STENCIL_OPAQUE = 1;
264− auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS();
265− auto ps = gpu::Shader::createPixel(std::string(drawOpaqueStencil_frag));
266− auto program = gpu::Shader::createProgram(vs, ps);
267− gpu::Shader::makeProgram((*program));
268−
269− auto state = std::make_shared<gpu::State>();
270− state->setDepthTest(true, false, gpu::LESS_EQUAL);
271− state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_REPLACE));
272− state->setColorWriteMask(0);
273−
274− _shapePlumber->addPipeline(ShapeKey::Filter::Builder(), program, state);
221+ initStencilPipelines(*_shapePlumber);
275222 }
276223
277224 void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
@@ -411,166 +358,3 @@ void Blit::run(const SceneContextPointer& sceneContext, const RenderContextPoint · 133 unmodified lines
411358 }
412359 });
413360 }
414−
415−void pipelineBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) {
416− if (pipeline.locations->normalFittingMapUnit > -1) {
417− batch.setResourceTexture(pipeline.locations->normalFittingMapUnit,
418− DependencyManager::get<TextureCache>()->getNormalFittingTexture());
419− }
420−}
421−
422−void initDeferredPipelines(render::ShapePlumber& plumber) {
423− using Key = render::ShapeKey;
424− using ShaderPointer = gpu::ShaderPointer;
425−
426− auto addPipeline = [&plumber](const Key& key, const ShaderPointer& vertexShader, const ShaderPointer& pixelShader) {
427− auto state = std::make_shared<gpu::State>();
428−
429− // Cull backface
430− state->setCullMode(gpu::State::CULL_BACK);
431−
432− // Z test depends on transparency
433− state->setDepthTest(true, !key.isTranslucent(), gpu::LESS_EQUAL);
434−
435− // Blend if transparent
436− state->setBlendFunction(key.isTranslucent(),
437− // For transparency, keep the highlight intensity
438− gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
439− gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
440−
441− ShaderPointer program = gpu::Shader::createProgram(vertexShader, pixelShader);
442− plumber.addPipeline(key, program, state, &pipelineBatchSetter);
443−
444− // Add a wireframe version
445− if (!key.isWireFrame()) {
446− auto wireFrameKey = Key::Builder(key).withWireframe();
447− auto wireFrameState = std::make_shared<gpu::State>(state->getValues());
448−
449− wireFrameState->setFillMode(gpu::State::FILL_LINE);
450−
451− plumber.addPipeline(wireFrameKey, program, wireFrameState, &pipelineBatchSetter);
452− }
453− };
454−
455− // Vertex shaders
456− auto modelVertex = gpu::Shader::createVertex(std::string(model_vert));
457− auto modelNormalMapVertex = gpu::Shader::createVertex(std::string(model_normal_map_vert));
458− auto modelLightmapVertex = gpu::Shader::createVertex(std::string(model_lightmap_vert));
459− auto modelLightmapNormalMapVertex = gpu::Shader::createVertex(std::string(model_lightmap_normal_map_vert));
460− auto modelShadowVertex = gpu::Shader::createVertex(std::string(model_shadow_vert));
461− auto skinModelVertex = gpu::Shader::createVertex(std::string(skin_model_vert));
462− auto skinModelNormalMapVertex = gpu::Shader::createVertex(std::string(skin_model_normal_map_vert));
463− auto skinModelShadowVertex = gpu::Shader::createVertex(std::string(skin_model_shadow_vert));
464−
465− // Pixel shaders
466− auto modelPixel = gpu::Shader::createPixel(std::string(model_frag));
467− auto modelNormalMapPixel = gpu::Shader::createPixel(std::string(model_normal_map_frag));
468− auto modelSpecularMapPixel = gpu::Shader::createPixel(std::string(model_specular_map_frag));
469− auto modelNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_normal_specular_map_frag));
470− auto modelTranslucentPixel = gpu::Shader::createPixel(std::string(model_translucent_frag));
471− auto modelShadowPixel = gpu::Shader::createPixel(std::string(model_shadow_frag));
472− auto modelLightmapPixel = gpu::Shader::createPixel(std::string(model_lightmap_frag));
473− auto modelLightmapNormalMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_map_frag));
474− auto modelLightmapSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_specular_map_frag));
475− auto modelLightmapNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_specular_map_frag));
476−
477− // Fill the pipelineLib
478− addPipeline(
479− Key::Builder(),
480− modelVertex, modelPixel);
481−
482− addPipeline(
483− Key::Builder().withTangents(),
484− modelNormalMapVertex, modelNormalMapPixel);
485−
486− addPipeline(
487− Key::Builder().withSpecular(),
488− modelVertex, modelSpecularMapPixel);
489−
490− addPipeline(
491− Key::Builder().withTangents().withSpecular(),
492− modelNormalMapVertex, modelNormalSpecularMapPixel);
493−
494−
495− addPipeline(
496− Key::Builder().withTranslucent(),
497− modelVertex, modelTranslucentPixel);
498− // FIXME Ignore lightmap for translucents meshpart
499− addPipeline(
500− Key::Builder().withTranslucent().withLightmap(),
501− modelVertex, modelTranslucentPixel);
502−
503− addPipeline(
504− Key::Builder().withTangents().withTranslucent(),
505− modelNormalMapVertex, modelTranslucentPixel);
506−
507− addPipeline(
508− Key::Builder().withSpecular().withTranslucent(),
509− modelVertex, modelTranslucentPixel);
510−
511− addPipeline(
512− Key::Builder().withTangents().withSpecular().withTranslucent(),
513− modelNormalMapVertex, modelTranslucentPixel);
514−
515−
516− addPipeline(
517− Key::Builder().withLightmap(),
518− modelLightmapVertex, modelLightmapPixel);
519−
520− addPipeline(
521− Key::Builder().withLightmap().withTangents(),
522− modelLightmapNormalMapVertex, modelLightmapNormalMapPixel);
523−
524− addPipeline(
525− Key::Builder().withLightmap().withSpecular(),
526− modelLightmapVertex, modelLightmapSpecularMapPixel);
527−
528− addPipeline(
529− Key::Builder().withLightmap().withTangents().withSpecular(),
530− modelLightmapNormalMapVertex, modelLightmapNormalSpecularMapPixel);
531−
532−
533− addPipeline(
534− Key::Builder().withSkinned(),
535− skinModelVertex, modelPixel);
536−
537− addPipeline(
538− Key::Builder().withSkinned().withTangents(),
539− skinModelNormalMapVertex, modelNormalMapPixel);
540−
541− addPipeline(
542− Key::Builder().withSkinned().withSpecular(),
543− skinModelVertex, modelSpecularMapPixel);
544−
545− addPipeline(
546− Key::Builder().withSkinned().withTangents().withSpecular(),
547− skinModelNormalMapVertex, modelNormalSpecularMapPixel);
548−
549−
550− addPipeline(
551− Key::Builder().withSkinned().withTranslucent(),
552− skinModelVertex, modelTranslucentPixel);
553−
554− addPipeline(
555− Key::Builder().withSkinned().withTangents().withTranslucent(),
556− skinModelNormalMapVertex, modelTranslucentPixel);
557−
558− addPipeline(
559− Key::Builder().withSkinned().withSpecular().withTranslucent(),
560− skinModelVertex, modelTranslucentPixel);
561−
562− addPipeline(
563− Key::Builder().withSkinned().withTangents().withSpecular().withTranslucent(),
564− skinModelNormalMapVertex, modelTranslucentPixel);
565−
566−
567− addPipeline(
568− Key::Builder().withDepthOnly(),
569− modelShadowVertex, modelShadowPixel);
570−
571−
572− addPipeline(
573− Key::Builder().withSkinned().withDepthOnly(),
574− skinModelShadowVertex, modelShadowPixel);
575−}
576−

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t