History

trying and failing andad trying and rince and repeat

sam gateau committed 8 years ago

Commit 392e2ff1 parent c12115b4 files · +38 −79Browse files

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

Unified · Split

libraries/render-utils/src/Model.cpp+15−17
@@ -1633,6 +1633,8 @@ Blender::Blender(ModelPointer model, int blendNumber, const Geometry::WeakPointe · 1632 unmodified lines
16331633 }
16341634
16351635
1636+//#define DEBUG_PACKED_BLENDSHAPE_OFFSET 1
1637+
16361638 void Blender::run() {
16371639 QVector<BlendshapeOffset> blendshapeOffsets;
16381640 if (_model && _model->isLoaded()) {
@@ -1651,8 +1653,7 @@ void Blender::run() { · 12 unmodified lines
16511653 offset += modelMeshBlendshapeOffsets->second.size();
16521654 std::vector<BlendshapeOffsetUnpacked> unpackedBlendshapeOffsets(modelMeshBlendshapeOffsets->second.size());
16531655
1654− // const float NORMAL_COEFFICIENT_SCALE = 0.01f;
1655− const float NORMAL_COEFFICIENT_SCALE = 1.0f;
1656+ const float NORMAL_COEFFICIENT_SCALE = 0.01f;
16561657 for (int i = 0, n = qMin(_blendshapeCoefficients.size(), mesh.blendshapes.size()); i < n; i++) {
16571658 float vertexCoefficient = _blendshapeCoefficients.at(i);
16581659 const float EPSILON = 0.0001f;
@@ -1668,38 +1669,37 @@ void Blender::run() { · 9 unmodified lines
16681669 for (auto j = range.begin(); j < range.end(); j++) {
16691670 int index = blendshape.indices.at(j);
16701671
1671−#ifdef PACKED_BLENDSHAPE_OFFSET
16721672 auto& currentBlendshapeOffset = unpackedBlendshapeOffsets[index];
16731673 currentBlendshapeOffset.positionOffsetAndSpare += blendshape.vertices.at(j) * vertexCoefficient;
16741674
16751675 currentBlendshapeOffset.normalOffsetAndSpare += blendshape.normals.at(j) * normalCoefficient;
16761676 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()) {
16851677 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;
16871679 }
16881680 }
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+ }
16891689 #endif
16901690 }
16911691 });
16921692 }
16931693
1694−#ifdef PACKED_BLENDSHAPE_OFFSET
1694+ // Blendshape offsets are generrated, now let's pack it on its way to gpu
16951695 tbb::parallel_for(tbb::blocked_range<int>(0, (int) unpackedBlendshapeOffsets.size()), [&](const tbb::blocked_range<int>& range) {
16961696 auto unpacked = unpackedBlendshapeOffsets.data() + range.begin();
16971697 auto packed = meshBlendshapeOffsets + range.begin();
16981698 for (auto j = range.begin(); j < range.end(); j++) {
16991699 (*packed).packedPosNorTan = glm::uvec4(
17001700 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)),
17031703 glm::packSnorm3x10_1x2(glm::vec4(unpacked->tangentOffsetAndSpare, 0.0f))
17041704 );
17051705
@@ -1707,8 +1707,6 @@ void Blender::run() { · 1 unmodified line
17071707 packed++;
17081708 }
17091709 });
1710−#endif
1711−
17121710 }
17131711 }
17141712 // post the result to the ModelBlender, which will dispatch to the model if still alive

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t