Repository: google/filament
File: libs/filamat/src/MaterialBuilder.cpp (C++)

Code before:
                static_cast<uint8_t>(mCullingMode));

        uint64_t properties = 0;
        UTILS_NOUNROLL
        for (size_t i = 0; i < MATERIAL_PROPERTIES_COUNT; i++) {
            if (mProperties[i]) {
                properties |= uint64_t(1u) << i;
            }
        }
        container.emplace<uint64_t>(MaterialProperties, properties);
        container.emplace<uint8_t>(MaterialStereoscopicType, static_cast<uint8_t>(mStereoscopicType));
    }

    // create a unique material id
    auto const& vert = mMaterialVertexCode.getCode();
    auto const& frag = mMaterialFragmentCode.getCode();
    std::hash<std::string_view> const hasher;
    size_t const materialId = hash::combine(
            MATERIAL_VERSION,
            hash::combine(
                    hasher({ vert.data(), vert.size() }),
                    hasher({ frag.data(), frag.size() })));

    container.emplace<uint64_t>(MaterialCacheId, materialId);
    if (!mMaterialSource.empty()) {
        container.push<CompressedStringChunk>(MaterialSource, mMaterialSource.data());
    }
}

void MaterialBuilder::writeSurfaceChunks(ChunkContainer& container) const noexcept {
    if (mBlendingMode == BlendingMode::MASKED) {
        container.emplace<float>(MaterialMaskThreshold, mMaskThreshold);
    }

    container.emplace<uint8_t>(MaterialShading, static_cast<uint8_t>(mShading));

    if (mShading == Shading::UNLIT) {
        container.emplace<bool>(MaterialShadowMultiplier, mShadowMultiplier);
    }

    container.emplace<uint8_t>(MaterialRefraction, static_cast<uint8_t>(mRefractionMode));
    container.emplace<uint8_t>(MaterialRefractionType,
            static_cast<uint8_t>(mRefractionType));
    container.emplace<bool>(MaterialClearCoatIorChange, mClearCoatIorChange);
    container.emplace<uint32_t>(MaterialRequiredAttributes,
            mRequiredAttributes.getValue());
    container.emplace<bool>(MaterialSpecularAntiAliasing, mSpecularAntiAliasing);
    container.emplace<float>(MaterialSpecularAntiAliasingVariance,
            mSpecularAntiAliasingVariance);
    container.emplace<float>(MaterialSpecularAntiAliasingThreshold,
            mSpecularAntiAliasingThreshold);

Review comment (suggestion):
```suggestion
        container.push<CompressedStringChunk>(MaterialSource, mMaterialSource);
```

Code after:
                static_cast<uint8_t>(mCullingMode));

        uint64_t properties = 0;
        UTILS_NOUNROLL
        for (size_t i = 0; i < MATERIAL_PROPERTIES_COUNT; i++) {
            if (mProperties[i]) {
                properties |= uint64_t(1u) << i;
            }
        }
        container.emplace<uint64_t>(MaterialProperties, properties);
        container.emplace<uint8_t>(MaterialStereoscopicType, static_cast<uint8_t>(mStereoscopicType));
    }

    // create a unique material id
    auto const& vert = mMaterialVertexCode.getCode();
    auto const& frag = mMaterialFragmentCode.getCode();
    std::hash<std::string_view> const hasher;
    size_t const materialId = hash::combine(
            MATERIAL_VERSION,
            hash::combine(
                    hasher({ vert.data(), vert.size() }),
                    hasher({ frag.data(), frag.size() })));

    container.emplace<uint64_t>(MaterialCacheId, materialId);
    if (!mMaterialSource.empty()) {
        container.push<CompressedStringChunk>(
                MaterialSource, mMaterialSource,
                CompressedStringChunk::CompressionLevel::MAX);
    }
}

void MaterialBuilder::writeSurfaceChunks(ChunkContainer& container) const noexcept {
    if (mBlendingMode == BlendingMode::MASKED) {
        container.emplace<float>(MaterialMaskThreshold, mMaskThreshold);
    }

    container.emplace<uint8_t>(MaterialShading, static_cast<uint8_t>(mShading));

    if (mShading == Shading::UNLIT) {
        container.emplace<bool>(MaterialShadowMultiplier, mShadowMultiplier);
    }

    container.emplace<uint8_t>(MaterialRefraction, static_cast<uint8_t>(mRefractionMode));
    container.emplace<uint8_t>(MaterialRefractionType,
            static_cast<uint8_t>(mRefractionType));
    container.emplace<bool>(MaterialClearCoatIorChange, mClearCoatIorChange);
    container.emplace<uint32_t>(MaterialRequiredAttributes,
            mRequiredAttributes.getValue());
    container.emplace<bool>(MaterialSpecularAntiAliasing, mSpecularAntiAliasing);
    container.emplace<float>(MaterialSpecularAntiAliasingVariance,
            mSpecularAntiAliasingVariance);