History

add plain forward model shaders

Zach Pomerantz committed 9 years ago

Commit f7cb2ec1 parent a414ba44 files · +84 −1Browse files

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

Unified · Split

libraries/render-utils/src/RenderForwardTask.cpp+41−1
@@ -26,12 +26,15 @@ · 25 unmodified lines
2626
2727 #include <render/drawItemBounds_vert.h>
2828 #include <render/drawItemBounds_frag.h>
29+#include "nop_frag.h"
2930
3031 using namespace render;
32+extern void initForwardPipelines(ShapePlumber& plumber);
3133
3234 RenderForwardTask::RenderForwardTask(RenderFetchCullSortTask::Output items) {
3335 // Prepare the ShapePipelines
3436 ShapePlumberPointer shapePlumber = std::make_shared<ShapePlumber>();
37+ initForwardPipelines(*shapePlumber);
3538
3639 // Extract opaques / transparents / lights / overlays
3740 const auto opaques = items[0];
@@ -44,9 +47,10 @@ RenderForwardTask::RenderForwardTask(RenderFetchCullSortTask::Output items) { · 6 unmodified lines
4447 const auto framebuffer = addJob<PrepareFramebuffer>("PrepareFramebuffer");
4548
4649 addJob<Draw>("DrawOpaques", opaques, shapePlumber);
50+ addJob<Stencil>("Stencil");
4751 addJob<DrawBackground>("DrawBackground", background);
4852
49− // bounds do not draw on stencil buffer, so they must come last
53+ // Bounds do not draw on stencil buffer, so they must come last
5054 addJob<DrawBounds>("DrawBounds", opaques);
5155
5256 // Blit!
@@ -116,6 +120,42 @@ void Draw::run(const SceneContextPointer& sceneContext, const RenderContextPoint · 63 unmodified lines
116120 args->_batch = nullptr;
117121 }
118122
123+const gpu::PipelinePointer Stencil::getPipeline() {
124+ if (!_stencilPipeline) {
125+ auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS();
126+ auto ps = gpu::Shader::createPixel(std::string(nop_frag));
127+ gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
128+ gpu::Shader::makeProgram(*program);
129+
130+ auto state = std::make_shared<gpu::State>();
131+ state->setDepthTest(true, false, gpu::LESS_EQUAL);
132+ const gpu::int8 STENCIL_OPAQUE = 1;
133+ state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS,
134+ gpu::State::STENCIL_OP_REPLACE,
135+ gpu::State::STENCIL_OP_REPLACE,
136+ gpu::State::STENCIL_OP_KEEP));
137+
138+ _stencilPipeline = gpu::Pipeline::create(program, state);
139+ }
140+ return _stencilPipeline;
141+}
142+
143+void Stencil::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
144+ RenderArgs* args = renderContext->args;
145+
146+ gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
147+ args->_batch = &batch;
148+
149+ batch.enableStereo(false);
150+ batch.setViewportTransform(args->_viewport);
151+ batch.setStateScissorRect(args->_viewport);
152+
153+ batch.setPipeline(getPipeline());
154+ batch.draw(gpu::TRIANGLE_STRIP, 4);
155+ });
156+ args->_batch = nullptr;
157+}
158+
119159 void DrawBackground::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext,
120160 const Inputs& background) {
121161 RenderArgs* args = renderContext->args;