fix(flame_3d): Fix alpha blend factors for transparent background compositing#3812
fix(flame_3d): Fix alpha blend factors for transparent background compositing#3812agnath18K wants to merge 1 commit intoflame-engine:mainfrom
Conversation
288146a to
32b5264
Compare
There was a problem hiding this comment.
Pull request overview
This PR attempts to fix transparent background compositing in flame_3d by correcting the alpha blend factors used in the GPU pipeline. The issue was that the alpha channel was being zeroed out for opaque fragments due to incorrect blend factor configuration, making rendered 3D scenes invisible when composited over Flutter widgets.
Changes:
- Modified alpha blend factor configuration in
GraphicsDevice.begin()to use premultiplied alpha "over" operator
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -84,9 +84,9 @@ class GraphicsDevice { | |||
| ..setColorBlendEnable(true) | |||
| ..setColorBlendEquation( | |||
| gpu.ColorBlendEquation( | |||
There was a problem hiding this comment.
The fix is incomplete. According to the PR description and issue #3811, the correct premultiplied "over" operator requires setting BOTH source and destination alpha blend factors:
- sourceAlphaBlendFactor: one (to preserve source alpha)
- destinationAlphaBlendFactor: oneMinusSourceAlpha (to blend with destination)
The current change only sets destinationAlphaBlendFactor without setting sourceAlphaBlendFactor. This means the source alpha blend factor is not configured at all, which may result in undefined or default behavior that doesn't match the intended fix. The ColorBlendEquation constructor should include both parameters.
| gpu.ColorBlendEquation( | |
| gpu.ColorBlendEquation( | |
| sourceAlphaBlendFactor: gpu.BlendFactor.one, |
Description
Fixes #3811
The
alphaBlendpath inGraphicsDevice.begin()setssourceAlphaBlendFactor: oneMinusSourceAlpha, which zeroes the alpha channel for opaque fragments:The GPU texture has valid RGB but zero alpha, so it becomes invisible when composited onto the Flutter canvas via
srcOver.This swaps the factors to match the standard premultiplied "over" operator:
sourceAlphaBlendFactor: one— preserves source alphadestinationAlphaBlendFactor: oneMinusSourceAlpha— blends with destinationChecklist
docsand added dartdoc comments with///.examplesordocs.The blend equation change is purely in the GPU pipeline — not feasible to unit test without a real GPU context. Verified manually by rendering models with
clearColor: 0x00000000and compositing over Flutter widgets.Breaking Change?