Repository navigation
Interpolate Canvas gradient stops in straight RGBA - #1889
bkaradzic-microsoft merged 2 commits into
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Updates Canvas gradient interpolation to blend RGB and alpha channels independently in straight RGBA space, while retaining NanoVG premultiplication during compositing.
Changes:
- Replaces premultiplied/unpremultiplied interpolation in linear and radial gradients with straight RGBA interpolation.
- Adds CPU regression coverage for translucent, opaque, fully transparent, and coincident stops.
- Adds GPU readback coverage for linear and radial translucent gradients over an opaque backdrop.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
Polyfills/Canvas/Source/Gradient.cpp |
Implements straight RGBA interpolation for gradient ramps and color sampling. |
Apps/UnitTests/Source/Tests.Canvas.Readback.cpp |
Adds CPU and GPU regression tests for gradient interpolation behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
8b6e8f4 to
49ba5b1
Compare
Review-Group: E7/H4 Source: PR BabylonJS#1889 Squashed final review changes, including regressions and review follow-ups. Status: held for runtime type tags / Canvas upload-alpha coordination. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
a0f9880 to
4fe3249
Compare
4fe3249 to
f02a443
Compare
Brings Babylon Native rendering closer to Babylon.js/WebGL2 parity. The guiding rule: anything that works in browser WebGL2 (ANGLE) is fixed in Babylon Native C++, not worked around in Babylon.js. Each commit is self-contained and is meant to be reviewed commit by commit. ## Commits 1. **Use SPIRV-Cross with the HLSL varying fixes from BabylonJS/SPIRV-Cross**: pins the merged BabylonJS/SPIRV-Cross `main` (`2b078efc`), which includes BabylonJS/SPIRV-Cross#15, #16 and #17. 2. **Expand line loops and triangle fans into indexed lists**: bgfx has neither topology. Expands them with draw ranges, primitive restart and dynamic index updates, and advertises `supportsPrimitiveModeExpansion`. Babylon.js 9.29 doesn't use it yet, so this changes nothing for current releases. 3. **Keep texture bindings across clears like WebGL**: replays bound material textures after `FrameBuffer::Clear`. 4. **Restore additive rendering commands and integration regressions**: keeps protocol 9 and adds `CLEAR2`, `SETSTENCIL2` and a float-preserving `readTexture2`. 5. **Handle native rendering compatibility without shared shader workarounds**: GLSL preprocessing, aliasing of intrinsic and predefined uniforms, integer conversions, ordering of repeated raw uploads, and plain-Array matrices plus default ranges in the native vertex transforms. 6. **Reset the back buffer's depth and stencil each frame**: matches WebGL's per-frame drawing-buffer reset. `PerFrameValue` now shares ownership of the engine's cancellation source, so a reset task scheduled by a disposed engine can't touch a freed source (this crashed on QuickJS). 7. **Render cube faces in GL row order like ANGLE**: mirrors rendering into cube-face render targets on top-left-origin backends. 8. **Widen RGB uploads and generate mips for raw texture updates**: RGB float, half-float and 16-bit normalized uploads, sub-buffer reads, and `generateMipmap` for raw textures. 9. **Add internal compute shader support**: native-only plumbing with no JavaScript surface. Compute shaders use bgfx shader binary v13, like graphics shaders since #1930. The OpenGL shader compiler names interface-block instances after their block, so ES 3.00 stages link when instance names differ. 10. **Emulate WebGL2 transform feedback with compute**: GPUParticleSystem runs unchanged on the WebGL2 path. Buffers the compute shaders write are filled from the CPU through a staging buffer and a GPU copy, because bgfx doesn't allow CPU updates of them. 11. **Regenerate the UnitTests JavaScript bundle**: so CI runs the new JavaScript tests. The commit messages have the details. ## Not included Everything here passes with the Babylon.js 9.29 npm release that CI uses. Changes that need unreleased Babylon.js are kept on [`shotgun-landing-support`](https://github.com/bkaradzic-microsoft/BabylonNative/tree/shotgun-landing-support): - Canvas gradient interpolation in straight RGBA (#1889). It needs Babylon.js to forward the alpha mode in `updateDynamicTexture`; without that, `GUI Gradient Linear with transparency` fails. - WebGL's global viewport. Babylon.js 9.29's `bindFramebuffer(..., forceFullscreenViewport)` relies on each framebuffer starting with a full viewport; without that, `Depth of field` fails. - Tests that need Babylon.js changes not yet released: primitive-mode expansion, Canvas alpha representations, float `readTexture2`, engine creation options and volume textures. Multisampled depth resolve for ordinary samplers is no longer part of this branch. bgfx now does it, and master reports the sampler metadata it needs (#1930). ## Known limitations - `Apps/PrecompiledShaderTest` is unchanged. Its particle effect needs transform-feedback support from a Babylon.js release that hasn't shipped yet. - Builds without a shader compiler don't cache the `readTransformFeedbackBuffer` readback kernel. ## Testing (Windows, D3D11, Release, Babylon.js 9.29) Rebased onto master `3f82b7e4` (includes #1930). - `Playground app:///Scripts/validation_native.js`: 371 ran, 371 passed. - UnitTests: 169 passed, 0 failed. - The Compute commit builds and passes unit tests on its own. - Full Babylon.js visualization sweep on `shotgun-landing-support` (720 tests, using the Babylon.js changes that drop the matching native workarounds): 705 pass. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
Interpolate RGB and alpha independently in linear and radial gradient baking. NanoVG performs premultiplication when compositing the ramp. Cover exact ramp bytes, radial interpolation, transparent and opaque stops, coincident-stop behavior, and GPU compositing over an opaque backdrop without relying on JavaScript upload-alpha changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
f02a443 to
c04c4c0
Compare
Straight-RGBA gradient interpolation matches Chrome only when Babylon.js requests unpremultiplied canvas textures (Babylon.js #19041). With the current Babylon.js the legacy raw-premultiplied copy applies alpha again (165 vs 191 at (50,50)); with #19041 and without this change it is 224. Exclude until the Babylon.js npm update, so both PRs can land. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
|
CI was failing only on GUI Gradient Linear with transparency on all 3 visual-validation jobs. This PR is correct only when paired with BabylonJS/Babylon.js#19041, which requests unpremultiplied canvas textures. With the current Babylon.js, the legacy raw-premultiplied copy applies alpha a second time (165 vs 191). I reproduced this locally: this PR plus the #19041 snapshot gives no pixel difference. bdb5ffb temporarily excludes the test so this PR can land first and unblock BabylonJS/Babylon.js#19041. Re-enable it after the Babylon.js npm update that includes #19041. |
## Problem The BabylonNative Nightly CI pipeline hasn't published a build since #1889 landed: | Run | BN commit | Nightly job | Packaged VisualizationTests | |---|---|---|---| | 61289 (last success) | bac047b | 59 min (just under the limit) | 34 min | | 61325 (manual) | c181462 | cancelled at 60 min, during UnitTests | 39 min | | 61329 (scheduled) | c181462 | cancelled at 60 min, during Upload Playground | 38 min | The `Nightly` job has no `timeoutInMinutes`, so Azure applies its 60-minute default. As more validation tests are enabled, the packaged visualization run has grown, and the job now overruns before publishing `BabylonNativeNightlyPlayground`. Babylon.js CI only uses fully succeeded nightly runs, so it is still testing against bac047b. That is why BabylonJS/Babylon.js#19041 keeps failing on "GUI Gradient Linear with transparency", which #1889 addresses. Each failure re-runs the whole native suite 3 times, which then hits B.js's own 90-minute limit. ## Fix Set `timeoutInMinutes: 180` on the `Nightly` job. Run 61329 also had an unrelated agent-lost failure on Android macOS JavaScriptCore during the ccache restore. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60c2ec68-6de1-445d-9fc9-b699db737eae
Draft: the stock Babylon.js upload-alpha dependency still blocks landing.
Interpolate Canvas gradient RGB and alpha independently, with exact CPU controls and linear/radial GPU controls over an opaque backdrop. Rebased onto
3428526fafter #1913 merged, preserving its newer Canvas identity, lifetime, callback, and blur regressions.Windows V8/D3D11 with stock Babylon.js 9.29.0: all 11 selected native Canvas/gradient cases pass. The unchanged
GUI Gradient Linear with transparencyscene still fails: 81,174 / 240,000 pixels (33.8225%), above its 2.5% allowance.Stock
updateDynamicTexturedoes not forward the requested alpha representation togetCanvasTexture. The standalone interpolation correction therefore remains dependent on the paired JavaScript upload change. No references, tolerances, exclusions, dependencies, or CI scripts are changed by this PR.