Showing the changes to libraries/render-utils/src/Model.cpp (1 of 4 files). Show all
Unified · Split
| @@ -1633,6 +1633,8 @@ Blender::Blender(ModelPointer model, int blendNumber, const Geometry::WeakPointe · 1632 unmodified lines | ||
| 1633 | 1633 | } |
| 1634 | 1634 | |
| 1635 | 1635 | |
| 1636 | +//#define DEBUG_PACKED_BLENDSHAPE_OFFSET 1 | |
| 1637 | + | |
| 1636 | 1638 | void Blender::run() { |
| 1637 | 1639 | QVector<BlendshapeOffset> blendshapeOffsets; |
| 1638 | 1640 | if (_model && _model->isLoaded()) { |
| @@ -1651,8 +1653,7 @@ void Blender::run() { · 12 unmodified lines | ||
| 1651 | 1653 | offset += modelMeshBlendshapeOffsets->second.size(); |
| 1652 | 1654 | std::vector<BlendshapeOffsetUnpacked> unpackedBlendshapeOffsets(modelMeshBlendshapeOffsets->second.size()); |
| 1653 | 1655 | |
| 1654 | − // const float NORMAL_COEFFICIENT_SCALE = 0.01f; | |
| 1655 | − const float NORMAL_COEFFICIENT_SCALE = 1.0f; | |
| 1656 | + const float NORMAL_COEFFICIENT_SCALE = 0.01f; | |
| 1656 | 1657 | for (int i = 0, n = qMin(_blendshapeCoefficients.size(), mesh.blendshapes.size()); i < n; i++) { |
| 1657 | 1658 | float vertexCoefficient = _blendshapeCoefficients.at(i); |
| 1658 | 1659 | const float EPSILON = 0.0001f; |
| @@ -1668,38 +1669,37 @@ void Blender::run() { · 9 unmodified lines | ||
| 1668 | 1669 | for (auto j = range.begin(); j < range.end(); j++) { |
| 1669 | 1670 | int index = blendshape.indices.at(j); |
| 1670 | 1671 | |
| 1671 | −#ifdef PACKED_BLENDSHAPE_OFFSET | |
| 1672 | 1672 | auto& currentBlendshapeOffset = unpackedBlendshapeOffsets[index]; |
| 1673 | 1673 | currentBlendshapeOffset.positionOffsetAndSpare += blendshape.vertices.at(j) * vertexCoefficient; |
| 1674 | 1674 | |
| 1675 | 1675 | currentBlendshapeOffset.normalOffsetAndSpare += blendshape.normals.at(j) * normalCoefficient; |
| 1676 | 1676 | if (doTangent) { |
| 1677 | − currentBlendshapeOffset.tangentOffsetAndSpare += blendshape.tangents.at(j) * normalCoefficient; | |
| 1678 | − } | |
| 1679 | −#else | |
| 1680 | − auto& currentBlendshapeOffset = blendshapeOffsets[index]; | |
| 1681 | − currentBlendshapeOffset.positionOffsetAndSpare += glm::vec4(blendshape.vertices.at(j) * vertexCoefficient, 0.0f); | |
| 1682 | − | |
| 1683 | − currentBlendshapeOffset.normalOffsetAndSpare += glm::vec4(blendshape.normals.at(j) * normalCoefficient, 0.0f); | |
| 1684 | − if (index < mesh.tangents.size()) { | |
| 1685 | 1677 | if ((int)j < blendshape.tangents.size()) { |
| 1686 | − currentBlendshapeOffset.tangentOffsetAndSpare += glm::vec4(blendshape.tangents.at(j) * normalCoefficient, 0.0f); | |
| 1678 | + currentBlendshapeOffset.tangentOffsetAndSpare += blendshape.tangents.at(j) * normalCoefficient; | |
| 1687 | 1679 | } |
| 1688 | 1680 | } |
| 1681 | + | |
| 1682 | +#ifdef DEBUG_PACKED_BLENDSHAPE_OFFSET | |
| 1683 | + if (glm::any(glm::greaterThan(glm::abs(currentBlendshapeOffset.normalOffsetAndSpare), glm::vec3(1.0f)))) { | |
| 1684 | + currentBlendshapeOffset.normalOffsetAndSpare = glm::clamp(currentBlendshapeOffset.normalOffsetAndSpare, glm::vec3(-1.0f), glm::vec3(1.0f)); | |
| 1685 | + } | |
| 1686 | + if (glm::any(glm::greaterThan(glm::abs(currentBlendshapeOffset.tangentOffsetAndSpare), glm::vec3(1.0f)))) { | |
| 1687 | + currentBlendshapeOffset.tangentOffsetAndSpare = glm::clamp(currentBlendshapeOffset.tangentOffsetAndSpare, glm::vec3(-1.0f), glm::vec3(1.0f)); | |
| 1688 | + } | |
| 1689 | 1689 | #endif |
| 1690 | 1690 | } |
| 1691 | 1691 | }); |
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | −#ifdef PACKED_BLENDSHAPE_OFFSET | |
| 1694 | + // Blendshape offsets are generrated, now let's pack it on its way to gpu | |
| 1695 | 1695 | tbb::parallel_for(tbb::blocked_range<int>(0, (int) unpackedBlendshapeOffsets.size()), [&](const tbb::blocked_range<int>& range) { |
| 1696 | 1696 | auto unpacked = unpackedBlendshapeOffsets.data() + range.begin(); |
| 1697 | 1697 | auto packed = meshBlendshapeOffsets + range.begin(); |
| 1698 | 1698 | for (auto j = range.begin(); j < range.end(); j++) { |
| 1699 | 1699 | (*packed).packedPosNorTan = glm::uvec4( |
| 1700 | 1700 | glm::packHalf2x16(glm::vec2(unpacked->positionOffsetAndSpare)), |
| 1701 | − glm::packHalf2x16(glm::vec2(unpacked->positionOffsetAndSpare.z, unpacked->normalOffsetAndSpare.z)), | |
| 1702 | − glm::packHalf2x16(glm::vec2(unpacked->normalOffsetAndSpare)), | |
| 1701 | + glm::packHalf2x16(glm::vec2(unpacked->positionOffsetAndSpare.z, 0.0f)), | |
| 1702 | + glm::packSnorm3x10_1x2(glm::vec4(unpacked->normalOffsetAndSpare, 0.0f)), | |
| 1703 | 1703 | glm::packSnorm3x10_1x2(glm::vec4(unpacked->tangentOffsetAndSpare, 0.0f)) |
| 1704 | 1704 | ); |
| 1705 | 1705 | |
| @@ -1707,8 +1707,6 @@ void Blender::run() { · 1 unmodified line | ||
| 1707 | 1707 | packed++; |
| 1708 | 1708 | } |
| 1709 | 1709 | }); |
| 1710 | −#endif | |
| 1711 | − | |
| 1712 | 1710 | } |
| 1713 | 1711 | } |
| 1714 | 1712 | // post the result to the ModelBlender, which will dispatch to the model if still alive |