Skip to content

fix(core): graded media crops at the same object-position as ungraded media - #5471

Closed
WaterrrForever wants to merge 1 commit into
mainfrom
fix/color-grading-object-position-y
Closed

WaterrrForever wants to merge 1 commit into
mainfrom
fix/color-grading-object-position-y

Conversation

@WaterrrForever

Copy link
Copy Markdown
Collaborator

What was wrong

A <video> or <img> with data-color-grading cropped vertically from the opposite end of the source in preview, snapshot and render. object-position: 50% 0% showed the bottom, and 50% 100% showed the top. The same element without the grading attribute cropped correctly.

Why

The grading canvas uploads its source texture with UNPACK_FLIP_Y_WEBGL = true, so the shader works in bottom-origin UVs. calculateObjectFitUv computed the vertical offset as (box - draw) * position.y, which measures from the top the way CSS does. The fix measures from the bottom: (box - draw) * (1 - position.y).

The horizontal axis was already correct, since CSS and GL both start at the left. Both callers (the live grading canvas and the preview thumbnails) go through this one function, so the one-line fix covers both.

Tests

  • New colorGrading.test.ts cases cover cover-fit at 0%, 22% and 100% on both axes, using a 9:16 source in a 3:4 box for Y and a 16:9 source in a 4:3 box for X. Each case reads back which source fraction the shader puts at the box's top-left edge and compares it with CSS. With the old code the three Y cases fail and the three X cases pass.
  • I checked end to end on a real project with a 1080×1920 clip in a 1080×1440 box using the locally built CLI. A graded and an ungraded copy at the same object-position now match: snapshot SSIM 0.947 at 0% and 0.949 at 100%, and draft render SSIM 0.913 at 0%. The remaining gap is the grade's own colour change. Copies at opposite positions score SSIM ≈ 0.47.

Note for existing projects

Any composition that worked around this by inverting the vertical percentage needs changing back. For example, the viral-clone-lab ugc-product-tryon project uses object-position: 50% 78% on .shot-tall to get a top-22% crop. After this fix that value should become 50% 22%.

… media

The grading canvas uploads its source texture flipped, so shader UVs are
bottom-origin, but calculateObjectFitUv measured the vertical
object-position offset from the top like CSS. object-position: 50% 0%
showed the bottom of the source and 100% the top. Measure the y offset
from the bottom. The x axis was already correct.
@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 2061 (base branch 2061), smooth 1621 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@WaterrrForever

Copy link
Copy Markdown
Collaborator Author

Closing as covered: main already measures the graded texture's y offset from the bottom (positionFromBottom = 1 - position.y in calculateObjectFitUv), which is this PR's fix. It landed with #6884.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant