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
721gpu::ShaderPointer GeometryCache::_simpleShader;721gpu::ShaderPointer GeometryCache::_simpleShader;
722gpu::ShaderPointer GeometryCache::_transparentShader;722gpu::ShaderPointer GeometryCache::_transparentShader;
723gpu::ShaderPointer GeometryCache::_unlitShader;723gpu::ShaderPointer GeometryCache::_unlitShader;
724gpu::ShaderPointer GeometryCache::_forwardSimpleShader;
725gpu::ShaderPointer GeometryCache::_forwardTransparentShader;
726gpu::ShaderPointer GeometryCache::_forwardUnlitShader;
724gpu::ShaderPointer GeometryCache::_simpleFadeShader;727gpu::ShaderPointer GeometryCache::_simpleFadeShader;
725gpu::ShaderPointer GeometryCache::_unlitFadeShader;728gpu::ShaderPointer GeometryCache::_unlitFadeShader;
726 729
727render::ShapePipelinePointer GeometryCache::_simpleOpaquePipeline;730render::ShapePipelinePointer GeometryCache::_simpleOpaquePipeline;
728render::ShapePipelinePointer GeometryCache::_simpleTransparentPipeline;731render::ShapePipelinePointer GeometryCache::_simpleTransparentPipeline;
732render::ShapePipelinePointer GeometryCache::_forwardSimpleOpaquePipeline;
733render::ShapePipelinePointer GeometryCache::_forwardSimpleTransparentPipeline;
729render::ShapePipelinePointer GeometryCache::_simpleOpaqueFadePipeline;734render::ShapePipelinePointer GeometryCache::_simpleOpaqueFadePipeline;
730render::ShapePipelinePointer GeometryCache::_simpleTransparentFadePipeline;735render::ShapePipelinePointer GeometryCache::_simpleTransparentFadePipeline;
731render::ShapePipelinePointer GeometryCache::_simpleWirePipeline;736render::ShapePipelinePointer GeometryCache::_simpleWirePipeline;
@@ -805,6 +810,8 @@ void GeometryCache::initializeShapePipelines() { · 73 unmodified lines
805 if (!_simpleOpaquePipeline) {810 if (!_simpleOpaquePipeline) {
806 _simpleOpaquePipeline = getShapePipeline(false, false, true, false);811 _simpleOpaquePipeline = getShapePipeline(false, false, true, false);
807 _simpleTransparentPipeline = getShapePipeline(false, true, true, false);812 _simpleTransparentPipeline = getShapePipeline(false, true, true, false);
813 _forwardSimpleOpaquePipeline = getShapePipeline(false, false, true, false, false, true);
814 _forwardSimpleTransparentPipeline = getShapePipeline(false, true, true, false, false, true);
808 _simpleOpaqueFadePipeline = getFadingShapePipeline(false, false, false, false, false);815 _simpleOpaqueFadePipeline = getFadingShapePipeline(false, false, false, false, false);
809 _simpleTransparentFadePipeline = getFadingShapePipeline(false, true, false, false, false);816 _simpleTransparentFadePipeline = getFadingShapePipeline(false, true, false, false, false);
810 _simpleWirePipeline = getShapePipeline(false, false, true, true);817 _simpleWirePipeline = getShapePipeline(false, false, true, true);
@@ -812,9 +819,9 @@ void GeometryCache::initializeShapePipelines() { · 1 unmodified line
812}819}
813 820
814render::ShapePipelinePointer GeometryCache::getShapePipeline(bool textured, bool transparent, bool culled,821render::ShapePipelinePointer GeometryCache::getShapePipeline(bool textured, bool transparent, bool culled,
815 bool unlit, bool depthBias) {822 bool unlit, bool depthBias, bool forward) {
816 823
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,
818 [](const render::ShapePipeline& pipeline, gpu::Batch& batch, render::Args* args) {825 [](const render::ShapePipeline& pipeline, gpu::Batch& batch, render::Args* args) {
819 batch.setResourceTexture(gr::Texture::MaterialAlbedo, DependencyManager::get<TextureCache>()->getWhiteTexture());826 batch.setResourceTexture(gr::Texture::MaterialAlbedo, DependencyManager::get<TextureCache>()->getWhiteTexture());
820 DependencyManager::get<DeferredLightingEffect>()->setupKeyLightBatch(args, batch);827 DependencyManager::get<DeferredLightingEffect>()->setupKeyLightBatch(args, batch);
@@ -2165,6 +2172,7 @@ public: · 1344 unmodified lines
2165 HAS_DEPTH_BIAS_FLAG,2172 HAS_DEPTH_BIAS_FLAG,
2166 IS_FADING_FLAG,2173 IS_FADING_FLAG,
2167 IS_ANTIALIASED_FLAG,2174 IS_ANTIALIASED_FLAG,
2175 IS_FORWARD_FLAG,
2168 2176
2169 NUM_FLAGS,2177 NUM_FLAGS,
2170 };2178 };
@@ -2177,6 +2185,7 @@ public: · 6 unmodified lines
2177 HAS_DEPTH_BIAS = (1 << HAS_DEPTH_BIAS_FLAG),2185 HAS_DEPTH_BIAS = (1 << HAS_DEPTH_BIAS_FLAG),
2178 IS_FADING = (1 << IS_FADING_FLAG),2186 IS_FADING = (1 << IS_FADING_FLAG),
2179 IS_ANTIALIASED = (1 << IS_ANTIALIASED_FLAG),2187 IS_ANTIALIASED = (1 << IS_ANTIALIASED_FLAG),
2188 IS_FORWARD = (1 << IS_FORWARD_FLAG),
2180 };2189 };
2181 typedef unsigned short Flags;2190 typedef unsigned short Flags;
2182 2191
@@ -2189,6 +2198,7 @@ public: · 6 unmodified lines
2189 bool hasDepthBias() const { return isFlag(HAS_DEPTH_BIAS); }2198 bool hasDepthBias() const { return isFlag(HAS_DEPTH_BIAS); }
2190 bool isFading() const { return isFlag(IS_FADING); }2199 bool isFading() const { return isFlag(IS_FADING); }
2191 bool isAntiAliased() const { return isFlag(IS_ANTIALIASED); }2200 bool isAntiAliased() const { return isFlag(IS_ANTIALIASED); }
2201 bool isForward() const { return isFlag(IS_FORWARD); }
2192 2202
2193 Flags _flags = 0;2203 Flags _flags = 0;
2194#if defined(__clang__)2204#if defined(__clang__)
@@ -2200,9 +2210,9 @@ public: · 5 unmodified lines
2200 2210
2201 2211
2202 SimpleProgramKey(bool textured = false, bool transparent = false, bool culled = true,2212 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) {
2204 _flags = (textured ? IS_TEXTURED : 0) | (transparent ? IS_TRANSPARENT : 0) | (culled ? IS_CULLED : 0) |2214 _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);
2206 }2216 }
2207 2217
2208 SimpleProgramKey(int bitmask) : _flags(bitmask) {}2218 SimpleProgramKey(int bitmask) : _flags(bitmask) {}
@@ -2255,8 +2265,8 @@ void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool tra · 46 unmodified lines
2255 }2265 }
2256}2266}
2257 2267
2258gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transparent, bool culled, bool unlit, bool depthBiased, bool fading, bool isAntiAliased) {2268gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transparent, bool culled, bool unlit, bool depthBiased, bool fading, bool isAntiAliased, bool forward) {
2259 SimpleProgramKey config { textured, transparent, culled, unlit, depthBiased, fading, isAntiAliased };2269 SimpleProgramKey config { textured, transparent, culled, unlit, depthBiased, fading, isAntiAliased, forward };
2260 2270
2261 // If the pipeline already exists, return it2271 // If the pipeline already exists, return it
2262 auto it = _simplePrograms.find(config);2272 auto it = _simplePrograms.find(config);
@@ -2269,13 +2279,20 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp · 6 unmodified lines
2269 static std::once_flag once;2279 static std::once_flag once;
2270 std::call_once(once, [&]() {2280 std::call_once(once, [&]() {
2271 using namespace shader::render_utils::program;2281 using namespace shader::render_utils::program;
2272 auto PS = DISABLE_DEFERRED ? forward_simple_textured : simple_textured;2282
2273 // Use the forward pipeline for both here, otherwise transparents will be unlit2283 _forwardSimpleShader = gpu::Shader::createProgram(forward_simple_textured);
2274 auto PSTransparent = DISABLE_DEFERRED ? forward_simple_textured_transparent : forward_simple_textured_transparent;2284 _forwardTransparentShader = gpu::Shader::createProgram(forward_simple_textured_transparent);
2275 auto PSUnlit = DISABLE_DEFERRED ? forward_simple_textured_unlit : simple_textured_unlit;2285 _forwardUnlitShader = gpu::Shader::createProgram(forward_simple_textured_unlit);
2276 _simpleShader = gpu::Shader::createProgram(PS);2286 if (DISABLE_DEFERRED) {
2277 _transparentShader = gpu::Shader::createProgram(PSTransparent);2287 _simpleShader = _forwardSimpleShader;
2278 _unlitShader = gpu::Shader::createProgram(PSUnlit);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 }
2279 });2296 });
2280 } else {2297 } else {
2281 static std::once_flag once;2298 static std::once_flag once;
@@ -2308,8 +2325,14 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp · 26 unmodified lines
2308 PrepareStencil::testMaskDrawShapeNoAA(*state);2325 PrepareStencil::testMaskDrawShapeNoAA(*state);
2309 }2326 }
2310 2327
2311 gpu::ShaderPointer program = (config.isUnlit()) ? (config.isFading() ? _unlitFadeShader : _unlitShader) :2328 gpu::ShaderPointer program;
2312 (config.isFading() ? _simpleFadeShader : (config.isTransparent() ? _transparentShader : _simpleShader));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 }
2313 gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state);2336 gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state);
2314 _simplePrograms.insert(config, pipeline);2337 _simplePrograms.insert(config, pipeline);
2315 return pipeline;2338 return pipeline;