google / google/filament

Flickering on updating Morph target of Larger GLBs

Open
#6,462 5 comments 0 reactions 1 assignee Claimed by @poweifeng View on GitHub
gltf
Dominant language
C++
Stars
20.5k
Forks
2.3k
Avg merge
2d 14h
Merged PRs (30d)
83

Description

**Describe the bug**
I'm facing flickering issue on all low to high end devices on updating morph weights on GLBs with bigger size
Please give a special attention to the eyes of the model for each blink there's a flicker on heavy model .
I've attached the code that I'm using for updating morph Targets at the end .

**To Reproduce**
Steps to reproduce the behaviour:
1. Here's the larger GLB `https://api.readyplayer.me/v1/avatars/63aef7ebd16b67196c59652a.glb`
2. Try updating morph target for the same

**Expected behaviour**
There should be no flicker

**Screenshots**
This is a heavy [glb](https://api.readyplayer.me/v1/avatars/63aef7ebd16b67196c59652a.glb
) and there's a flicker everytime you change morph targets.

https://user-images.githubusercontent.com/35389814/212525456-0b5a0c90-88c2-49e2-a98c-35e7e6099107.mov

This is a lightweight [glb](https://api.readyplayer.me/v1/avatars/63aef887d16b67196c5965af.glb) and there's no flickering issue as you can see.

https://user-images.githubusercontent.com/35389814/212525445-add6fff8-b9f6-4470-a28d-8be264659c2a.mov

**Smartphone (please complete the following information):**
- Device: . Realme 9 pro , One plus 10, redmi note 10]
- OS: [Android 11.0 and above]

**Additional context**
Here's a code snippet that I'm using for updating morph target

private fun updateMorphTargets() {
var finalEntity = modelViewer.asset!!.getFirstEntityByName(MorphRpm.Wolf3D_Avatar)
if (finalEntity == 0) {
finalEntity = modelViewer.asset!!.getFirstEntityByName(MorphRpm.Wolf3D_Head)
}
val faceEntity = modelViewer.engine.renderableManager.getInstance(
finalEntity
)

morphingJobs = lifecycle.coroutineScope.launch(Dispatchers.Main) {
if (isActive) {
launch {
suspend {
try {
// A normal human blinks 22 time in a minute.
// So just calculate total seconds.
var totalSeconds: Long = 0
var commonDifference = 0.01
var progress = 0.01
val smileUpperLimit = 0.99
val smileLowerLimit = progress
var eyeBlinkValue = 0
while (isActive) {
// create Ap series []
// common difference is d = 10 and first no is 10
val randomDelay = (50..100).random().toLong()
delay(randomDelay)
totalSeconds += randomDelay

if (totalSeconds > 3000) {
totalSeconds = 0
eyeBlinkValue = if (eyeBlinkValue == 0) 1 else 0
// close both eye
RpmMorph.smileWithBlink(
progress.toFloat(),
eyeBlinkValue.toFloat()
)
?.let {
modelViewer.engine.renderableManager.setMorphWeights(
faceEntity,
it,
0
)
modelViewer.animator?.updateBoneMatrices()
}
progress += commonDifference
if (String.format("%.2f", progress)
.toDouble() == smileUpperLimit
) {
// making common difference negative
commonDifference = -commonDifference
delay(2000)
}
if (String.format("%.2f", progress)
.toDouble() == smileLowerLimit
) {
// now the common difference is negative.
// Make it positive.
commonDifference = -commonDifference
delay(1000)
}
continue
} else if (totalSeconds in 500..600) {
eyeBlinkValue = if (eyeBlinkValue == 0) 1 else 0
// close both eye
RpmMorph.smileWithBlink(
progress.toFloat(),
eyeBlinkValue.toFloat()
)
?.let {
modelViewer.engine.renderableManager.setMorphWeights(
faceEntity,
it,
0
)
modelViewer.animator?.updateBoneMatrices()
}
progress += commonDifference
if (String.format("%.2f", progress)
.toDouble() == smileUpperLimit
) {
// making common difference negative
commonDifference = -commonDifference
delay(2000)
}
if (String.format("%.2f", progress)
.toDouble() == smileLowerLimit
) {
// now the common difference is negative.
// Make it positive.
commonDifference = -commonDifference
delay(1000)
}
continue
}
// else
RpmMorph.smileWithBlink(progress.toFloat(), 0F)
?.let {
modelViewer.engine.renderableManager.setMorphWeights(
faceEntity,
it,
0
)
modelViewer.animator?.updateBoneMatrices()
}
progress += commonDifference
if (String.format("%.2f", progress).toDouble() == smileUpperLimit) {
// making common difference negative
commonDifference = -commonDifference
delay(2000)
}
if (String.format("%.2f", progress).toDouble() == smileLowerLimit) {
// now the common difference is negative.
// Make it positive.
commonDifference = -commonDifference
delay(1000)
}
// Logic for eye blink.
}
} catch (e: CancellationException) {
Log.d("Job Cancellation", "parent job has been cancelled")
} catch (e: Exception) {
Log.d("Error", "Something weird happen ${e.message.toString()}")
}
}()
}

}
}

}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.