History

correct lighting of layered shapes

SamGondelman committed 7 years ago

Commit 5dd59dd1 parent 10068cc3 files · +54 −18Browse files

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

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+38−15
@@ -721,11 +721,16 @@ QHash<SimpleProgramKey, gpu::PipelinePointer> GeometryCache::_simplePrograms; · 720 unmodified lines
721721 gpu::ShaderPointer GeometryCache::_simpleShader;
722722 gpu::ShaderPointer GeometryCache::_transparentShader;
723723 gpu::ShaderPointer GeometryCache::_unlitShader;
724+gpu::ShaderPointer GeometryCache::_forwardSimpleShader;
725+gpu::ShaderPointer GeometryCache::_forwardTransparentShader;
726+gpu::ShaderPointer GeometryCache::_forwardUnlitShader;
724727 gpu::ShaderPointer GeometryCache::_simpleFadeShader;
725728 gpu::ShaderPointer GeometryCache::_unlitFadeShader;
726729
727730 render::ShapePipelinePointer GeometryCache::_simpleOpaquePipeline;
728731 render::ShapePipelinePointer GeometryCache::_simpleTransparentPipeline;
732+render::ShapePipelinePointer GeometryCache::_forwardSimpleOpaquePipeline;
733+render::ShapePipelinePointer GeometryCache::_forwardSimpleTransparentPipeline;
729734 render::ShapePipelinePointer GeometryCache::_simpleOpaqueFadePipeline;
730735 render::ShapePipelinePointer GeometryCache::_simpleTransparentFadePipeline;
731736 render::ShapePipelinePointer GeometryCache::_simpleWirePipeline;
@@ -805,6 +810,8 @@ void GeometryCache::initializeShapePipelines() { · 73 unmodified lines
805810 if (!_simpleOpaquePipeline) {
806811 _simpleOpaquePipeline = getShapePipeline(false, false, true, false);
807812 _simpleTransparentPipeline = getShapePipeline(false, true, true, false);
813+ _forwardSimpleOpaquePipeline = getShapePipeline(false, false, true, false, false, true);
814+ _forwardSimpleTransparentPipeline = getShapePipeline(false, true, true, false, false, true);
808815 _simpleOpaqueFadePipeline = getFadingShapePipeline(false, false, false, false, false);
809816 _simpleTransparentFadePipeline = getFadingShapePipeline(false, true, false, false, false);
810817 _simpleWirePipeline = getShapePipeline(false, false, true, true);
@@ -812,9 +819,9 @@ void GeometryCache::initializeShapePipelines() { · 1 unmodified line
812819 }
813820
814821 render::ShapePipelinePointer GeometryCache::getShapePipeline(bool textured, bool transparent, bool culled,
815− bool unlit, bool depthBias) {
822+ bool unlit, bool depthBias, bool forward) {
816823
817− return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, culled, unlit, depthBias, false, true), nullptr,
824+ return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, culled, unlit, depthBias, false, true, forward), nullptr,
818825 [](const render::ShapePipeline& pipeline, gpu::Batch& batch, render::Args* args) {
819826 batch.setResourceTexture(gr::Texture::MaterialAlbedo, DependencyManager::get<TextureCache>()->getWhiteTexture());
820827 DependencyManager::get<DeferredLightingEffect>()->setupKeyLightBatch(args, batch);
@@ -2165,6 +2172,7 @@ public: · 1344 unmodified lines
21652172 HAS_DEPTH_BIAS_FLAG,
21662173 IS_FADING_FLAG,
21672174 IS_ANTIALIASED_FLAG,
2175+ IS_FORWARD_FLAG,
21682176
21692177 NUM_FLAGS,
21702178 };
@@ -2177,6 +2185,7 @@ public: · 6 unmodified lines
21772185 HAS_DEPTH_BIAS = (1 << HAS_DEPTH_BIAS_FLAG),
21782186 IS_FADING = (1 << IS_FADING_FLAG),
21792187 IS_ANTIALIASED = (1 << IS_ANTIALIASED_FLAG),
2188+ IS_FORWARD = (1 << IS_FORWARD_FLAG),
21802189 };
21812190 typedef unsigned short Flags;
21822191
@@ -2189,6 +2198,7 @@ public: · 6 unmodified lines
21892198 bool hasDepthBias() const { return isFlag(HAS_DEPTH_BIAS); }
21902199 bool isFading() const { return isFlag(IS_FADING); }
21912200 bool isAntiAliased() const { return isFlag(IS_ANTIALIASED); }
2201+ bool isForward() const { return isFlag(IS_FORWARD); }
21922202
21932203 Flags _flags = 0;
21942204 #if defined(__clang__)
@@ -2200,9 +2210,9 @@ public: · 5 unmodified lines
22002210
22012211
22022212 SimpleProgramKey(bool textured = false, bool transparent = false, bool culled = true,
2203− bool unlit = false, bool depthBias = false, bool fading = false, bool isAntiAliased = true) {
2213+ bool unlit = false, bool depthBias = false, bool fading = false, bool isAntiAliased = true, bool forward = false) {
22042214 _flags = (textured ? IS_TEXTURED : 0) | (transparent ? IS_TRANSPARENT : 0) | (culled ? IS_CULLED : 0) |
2205− (unlit ? IS_UNLIT : 0) | (depthBias ? HAS_DEPTH_BIAS : 0) | (fading ? IS_FADING : 0) | (isAntiAliased ? IS_ANTIALIASED : 0);
2215+ (unlit ? IS_UNLIT : 0) | (depthBias ? HAS_DEPTH_BIAS : 0) | (fading ? IS_FADING : 0) | (isAntiAliased ? IS_ANTIALIASED : 0) | (forward ? IS_FORWARD : 0);
22062216 }
22072217
22082218 SimpleProgramKey(int bitmask) : _flags(bitmask) {}
@@ -2255,8 +2265,8 @@ void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool tra · 46 unmodified lines
22552265 }
22562266 }
22572267
2258−gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transparent, bool culled, bool unlit, bool depthBiased, bool fading, bool isAntiAliased) {
2259− SimpleProgramKey config { textured, transparent, culled, unlit, depthBiased, fading, isAntiAliased };
2268+gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transparent, bool culled, bool unlit, bool depthBiased, bool fading, bool isAntiAliased, bool forward) {
2269+ SimpleProgramKey config { textured, transparent, culled, unlit, depthBiased, fading, isAntiAliased, forward };
22602270
22612271 // If the pipeline already exists, return it
22622272 auto it = _simplePrograms.find(config);
@@ -2269,13 +2279,20 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp · 6 unmodified lines
22692279 static std::once_flag once;
22702280 std::call_once(once, [&]() {
22712281 using namespace shader::render_utils::program;
2272− auto PS = DISABLE_DEFERRED ? forward_simple_textured : simple_textured;
2273− // Use the forward pipeline for both here, otherwise transparents will be unlit
2274− auto PSTransparent = DISABLE_DEFERRED ? forward_simple_textured_transparent : forward_simple_textured_transparent;
2275− auto PSUnlit = DISABLE_DEFERRED ? forward_simple_textured_unlit : simple_textured_unlit;
2276− _simpleShader = gpu::Shader::createProgram(PS);
2277− _transparentShader = gpu::Shader::createProgram(PSTransparent);
2278− _unlitShader = gpu::Shader::createProgram(PSUnlit);
2282+
2283+ _forwardSimpleShader = gpu::Shader::createProgram(forward_simple_textured);
2284+ _forwardTransparentShader = gpu::Shader::createProgram(forward_simple_textured_transparent);
2285+ _forwardUnlitShader = gpu::Shader::createProgram(forward_simple_textured_unlit);
2286+ if (DISABLE_DEFERRED) {
2287+ _simpleShader = _forwardSimpleShader;
2288+ _transparentShader = _forwardTransparentShader;
2289+ _unlitShader = _forwardUnlitShader;
2290+ } else {
2291+ _simpleShader = gpu::Shader::createProgram(simple_textured);
2292+ // Use the forward pipeline for both here, otherwise transparents will be unlit
2293+ _transparentShader = gpu::Shader::createProgram(forward_simple_textured_transparent);
2294+ _unlitShader = gpu::Shader::createProgram(simple_textured_unlit);
2295+ }
22792296 });
22802297 } else {
22812298 static std::once_flag once;
@@ -2308,8 +2325,14 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp · 26 unmodified lines
23082325 PrepareStencil::testMaskDrawShapeNoAA(*state);
23092326 }
23102327
2311− gpu::ShaderPointer program = (config.isUnlit()) ? (config.isFading() ? _unlitFadeShader : _unlitShader) :
2312− (config.isFading() ? _simpleFadeShader : (config.isTransparent() ? _transparentShader : _simpleShader));
2328+ gpu::ShaderPointer program;
2329+ if (config.isForward()) {
2330+ program = (config.isUnlit()) ? (config.isFading() ? _unlitFadeShader : _forwardUnlitShader) :
2331+ (config.isFading() ? _simpleFadeShader : (config.isTransparent() ? _forwardTransparentShader : _forwardSimpleShader));
2332+ } else {
2333+ program = (config.isUnlit()) ? (config.isFading() ? _unlitFadeShader : _unlitShader) :
2334+ (config.isFading() ? _simpleFadeShader : (config.isTransparent() ? _transparentShader : _simpleShader));
2335+ }
23132336 gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state);
23142337 _simplePrograms.insert(config, pipeline);
23152338 return pipeline;