filament icon indicating copy to clipboard operation
filament copied to clipboard

Flickering on updating Morph target of Larger GLBs

Open ritik619 opened this issue 2 years ago • 5 comments

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 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 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()}")
                    }
                }()
            }

        }
    }

}

ritik619 avatar Jan 15 '23 06:01 ritik619

@prideout

ritik619 avatar Jan 15 '23 06:01 ritik619

This is happening with most of the phones. Also black dark spots appears..

atul161 avatar Jan 17 '23 02:01 atul161

@prideout Sorry for tagging again but can you help me out

ritik619 avatar Jan 18 '23 11:01 ritik619

@ritik619 Hi there, did you fix this?

anliyuan avatar Apr 16 '24 13:04 anliyuan