History

material entities support cullFaceMode and support gltf doubleSided

HifiExperiments committed 6 years ago

Commit 69714a81 parent b4c9a3e18 files · +261 −122Browse files

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

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+70−57
@@ -723,7 +723,7 @@ gpu::ShaderPointer GeometryCache::_forwardUnlitShader; · 722 unmodified lines
723723 gpu::ShaderPointer GeometryCache::_forwardSimpleFadeShader;
724724 gpu::ShaderPointer GeometryCache::_forwardUnlitFadeShader;
725725
726−std::map<std::tuple<bool, bool, bool>, render::ShapePipelinePointer> GeometryCache::_shapePipelines;
726+std::map<std::tuple<bool, bool, bool, graphics::MaterialKey::CullFaceMode>, render::ShapePipelinePointer> GeometryCache::_shapePipelines;
727727
728728 GeometryCache::GeometryCache() :
729729 _nextID(0) {
@@ -776,15 +776,18 @@ void GeometryCache::initializeShapePipelines() { · 46 unmodified lines
776776 bool transparent = i & 1;
777777 bool unlit = i & 2;
778778 bool forward = i & 4;
779− _shapePipelines[std::make_tuple(transparent, unlit, forward)] = getShapePipeline(false, transparent, true, unlit, false, forward);
779+ for (int cullFaceMode = graphics::MaterialKey::CullFaceMode::CULL_NONE; cullFaceMode < graphics::MaterialKey::CullFaceMode::NUM_CULL_FACE_MODES; cullFaceMode++) {
780+ auto cullMode = (graphics::MaterialKey::CullFaceMode)cullFaceMode;
781+ _shapePipelines[std::make_tuple(transparent, unlit, forward, cullMode)] = getShapePipeline(false, transparent, unlit, false, forward, cullMode);
782+ }
780783 }
781784 }
782785 }
783786
784−render::ShapePipelinePointer GeometryCache::getShapePipeline(bool textured, bool transparent, bool culled,
785− bool unlit, bool depthBias, bool forward) {
787+render::ShapePipelinePointer GeometryCache::getShapePipeline(bool textured, bool transparent, bool unlit, bool depthBias, bool forward,
788+ graphics::MaterialKey::CullFaceMode cullFaceMode) {
786789
787− return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, culled, unlit, depthBias, false, true, forward), nullptr,
790+ return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, unlit, depthBias, false, true, forward, cullFaceMode), nullptr,
788791 [](const render::ShapePipeline& pipeline, gpu::Batch& batch, render::Args* args) {
789792 batch.setResourceTexture(gr::Texture::MaterialAlbedo, DependencyManager::get<TextureCache>()->getWhiteTexture());
790793 DependencyManager::get<DeferredLightingEffect>()->setupKeyLightBatch(args, batch);
@@ -792,12 +795,12 @@ render::ShapePipelinePointer GeometryCache::getShapePipeline(bool textured, bool · 1 unmodified line
792795 );
793796 }
794797
795−render::ShapePipelinePointer GeometryCache::getFadingShapePipeline(bool textured, bool transparent, bool culled,
796− bool unlit, bool depthBias, bool forward) {
798+render::ShapePipelinePointer GeometryCache::getFadingShapePipeline(bool textured, bool transparent, bool unlit, bool depthBias, bool forward,
799+ graphics::MaterialKey::CullFaceMode cullFaceMode) {
797800 auto fadeEffect = DependencyManager::get<FadeEffect>();
798801 auto fadeBatchSetter = fadeEffect->getBatchSetter();
799802 auto fadeItemSetter = fadeEffect->getItemUniformSetter();
800− return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, culled, unlit, depthBias, true, true, forward), nullptr,
803+ return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, unlit, depthBias, true, true, forward, cullFaceMode), nullptr,
801804 [fadeBatchSetter, fadeItemSetter](const render::ShapePipeline& shapePipeline, gpu::Batch& batch, render::Args* args) {
802805 batch.setResourceTexture(gr::Texture::MaterialAlbedo, DependencyManager::get<TextureCache>()->getWhiteTexture());
803806 fadeBatchSetter(shapePipeline, batch, args);
@@ -2049,54 +2052,60 @@ void GeometryCache::useGridPipeline(gpu::Batch& batch, GridBuffer gridBuffer, bo · 1245 unmodified lines
20492052 class SimpleProgramKey {
20502053 public:
20512054 enum FlagBit {
2052− IS_TEXTURED_FLAG = 0,
2053− IS_TRANSPARENT_FLAG,
2054− IS_CULLED_FLAG,
2055− IS_UNLIT_FLAG,
2056− HAS_DEPTH_BIAS_FLAG,
2057− IS_FADING_FLAG,
2058− IS_ANTIALIASED_FLAG,
2059− IS_FORWARD_FLAG,
2055+ IS_TEXTURED_BIT = 0,
2056+ IS_TRANSPARENT_BIT,
2057+ IS_UNLIT_BIT,
2058+ IS_DEPTH_BIASED_BIT,
2059+ IS_FADING_BIT,
2060+ IS_ANTIALIASED_BIT,
2061+ IS_FORWARD_BIT,
2062+ IS_CULL_FACE_NONE_BIT, // if neither of these are set, we're CULL_FACE_BACK
2063+ IS_CULL_FACE_FRONT_BIT,
20602064
20612065 NUM_FLAGS,
20622066 };
2063−
2064− enum Flag {
2065− IS_TEXTURED = (1 << IS_TEXTURED_FLAG),
2066− IS_TRANSPARENT = (1 << IS_TRANSPARENT_FLAG),
2067− IS_CULLED = (1 << IS_CULLED_FLAG),
2068− IS_UNLIT = (1 << IS_UNLIT_FLAG),
2069− HAS_DEPTH_BIAS = (1 << HAS_DEPTH_BIAS_FLAG),
2070− IS_FADING = (1 << IS_FADING_FLAG),
2071− IS_ANTIALIASED = (1 << IS_ANTIALIASED_FLAG),
2072− IS_FORWARD = (1 << IS_FORWARD_FLAG),
2073− };
2074− typedef unsigned short Flags;
2075−
2076− bool isFlag(short flagNum) const { return bool((_flags & flagNum) != 0); }
2077−
2078− bool isTextured() const { return isFlag(IS_TEXTURED); }
2079− bool isTransparent() const { return isFlag(IS_TRANSPARENT); }
2080− bool isCulled() const { return isFlag(IS_CULLED); }
2081− bool isUnlit() const { return isFlag(IS_UNLIT); }
2082− bool hasDepthBias() const { return isFlag(HAS_DEPTH_BIAS); }
2083− bool isFading() const { return isFlag(IS_FADING); }
2084− bool isAntiAliased() const { return isFlag(IS_ANTIALIASED); }
2085− bool isForward() const { return isFlag(IS_FORWARD); }
2067+ typedef std::bitset<NUM_FLAGS> Flags;
2068+
2069+ bool isTextured() const { return _flags[IS_TEXTURED_BIT]; }
2070+ bool isTransparent() const { return _flags[IS_TRANSPARENT_BIT]; }
2071+ bool isUnlit() const { return _flags[IS_UNLIT_BIT]; }
2072+ bool hasDepthBias() const { return _flags[IS_DEPTH_BIASED_BIT]; }
2073+ bool isFading() const { return _flags[IS_FADING_BIT]; }
2074+ bool isAntiAliased() const { return _flags[IS_ANTIALIASED_BIT]; }
2075+ bool isForward() const { return _flags[IS_FORWARD_BIT]; }
2076+ bool isCullFaceNone() const { return _flags[IS_CULL_FACE_NONE_BIT]; }
2077+ bool isCullFaceFront() const { return _flags[IS_CULL_FACE_FRONT_BIT]; }
20862078
20872079 Flags _flags = 0;
2088−#if defined(__clang__)
2089− __attribute__((unused))
2090−#endif
2091− short _spare = 0; // Padding
2092−
2093− int getRaw() const { return *reinterpret_cast<const int*>(this); }
20942080
2095−
2096− SimpleProgramKey(bool textured = false, bool transparent = false, bool culled = true,
2097− bool unlit = false, bool depthBias = false, bool fading = false, bool isAntiAliased = true, bool forward = false) {
2098− _flags = (textured ? IS_TEXTURED : 0) | (transparent ? IS_TRANSPARENT : 0) | (culled ? IS_CULLED : 0) |
2099− (unlit ? IS_UNLIT : 0) | (depthBias ? HAS_DEPTH_BIAS : 0) | (fading ? IS_FADING : 0) | (isAntiAliased ? IS_ANTIALIASED : 0) | (forward ? IS_FORWARD : 0);
2081+ unsigned long getRaw() const { return _flags.to_ulong(); }
2082+
2083+ SimpleProgramKey(bool textured = false, bool transparent = false, bool unlit = false, bool depthBias = false, bool fading = false,
2084+ bool isAntiAliased = true, bool forward = false, graphics::MaterialKey::CullFaceMode cullFaceMode = graphics::MaterialKey::CULL_BACK) {
2085+ _flags.set(IS_TEXTURED_BIT, textured);
2086+ _flags.set(IS_TRANSPARENT_BIT, transparent);
2087+ _flags.set(IS_UNLIT_BIT, unlit);
2088+ _flags.set(IS_DEPTH_BIASED_BIT, depthBias);
2089+ _flags.set(IS_FADING_BIT, fading);
2090+ _flags.set(IS_ANTIALIASED_BIT, isAntiAliased);
2091+ _flags.set(IS_FORWARD_BIT, forward);
2092+
2093+ switch (cullFaceMode) {
2094+ case graphics::MaterialKey::CullFaceMode::CULL_NONE:
2095+ _flags.set(IS_CULL_FACE_NONE_BIT);
2096+ _flags.reset(IS_CULL_FACE_FRONT_BIT);
2097+ break;
2098+ case graphics::MaterialKey::CullFaceMode::CULL_FRONT:
2099+ _flags.reset(IS_CULL_FACE_NONE_BIT);
2100+ _flags.set(IS_CULL_FACE_FRONT_BIT);
2101+ break;
2102+ case graphics::MaterialKey::CullFaceMode::CULL_BACK:
2103+ _flags.reset(IS_CULL_FACE_NONE_BIT);
2104+ _flags.reset(IS_CULL_FACE_FRONT_BIT);
2105+ break;
2106+ default:
2107+ break;
2108+ }
21002109 }
21012110
21022111 SimpleProgramKey(int bitmask) : _flags(bitmask) {}
@@ -2141,8 +2150,9 @@ gpu::PipelinePointer GeometryCache::getWebBrowserProgram(bool transparent, bool · 38 unmodified lines
21412150 return _webPipelines[{ transparent, forward }];
21422151 }
21432152
2144−void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool transparent, bool culled, bool unlit, bool depthBiased, bool isAntiAliased, bool forward) {
2145− batch.setPipeline(getSimplePipeline(textured, transparent, culled, unlit, depthBiased, false, isAntiAliased, forward));
2153+void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool transparent, bool unlit, bool depthBiased, bool isAntiAliased,
2154+ bool forward, graphics::MaterialKey::CullFaceMode cullFaceMode) {
2155+ batch.setPipeline(getSimplePipeline(textured, transparent, unlit, depthBiased, false, isAntiAliased, forward, cullFaceMode));
21462156
21472157 // If not textured, set a default albedo map
21482158 if (!textured) {
@@ -2151,8 +2161,9 @@ void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool tra · 2 unmodified lines
21512161 }
21522162 }
21532163
2154−gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transparent, bool culled, bool unlit, bool depthBiased, bool fading, bool isAntiAliased, bool forward) {
2155− SimpleProgramKey config { textured, transparent, culled, unlit, depthBiased, fading, isAntiAliased, forward };
2164+gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transparent, bool unlit, bool depthBiased, bool fading, bool isAntiAliased,
2165+ bool forward, graphics::MaterialKey::CullFaceMode cullFaceMode) {
2166+ SimpleProgramKey config { textured, transparent, unlit, depthBiased, fading, isAntiAliased, forward, cullFaceMode };
21562167
21572168 // If the pipeline already exists, return it
21582169 auto it = _simplePrograms.find(config);
@@ -2189,10 +2200,12 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp · 30 unmodified lines
21892200
21902201 // If the pipeline did not exist, make it
21912202 auto state = std::make_shared<gpu::State>();
2192− if (config.isCulled()) {
2193− state->setCullMode(gpu::State::CULL_BACK);
2194− } else {
2203+ if (config.isCullFaceNone()) {
21952204 state->setCullMode(gpu::State::CULL_NONE);
2205+ } else if (config.isCullFaceFront()) {
2206+ state->setCullMode(gpu::State::CULL_FRONT);
2207+ } else {
2208+ state->setCullMode(gpu::State::CULL_BACK);
21962209 }
21972210 state->setDepthTest(true, true, gpu::LESS_EQUAL);
21982211 if (config.hasDepthBias()) {