Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render: Implement reposition in Z-axis #19405

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cookie-s
Copy link
Contributor

@cookie-s cookie-s commented Feb 1, 2025

Closes #8033 . See #8033 (comment) for the difference.

This PR implements DisplayObject.z property feature including its rendering with the default perspective projection.

Known limitations

  • The supported perspective projection is limited to the Flash Player's default one. It's hardcoded into render/wgpu/src/globals.rs.
    root.transform.perspectiveProjection.fieldOfView = 55
    root.transform.perspectiveProjection.projectionCenter = (x: stage.stageWidth / 2, y: stage.stageHeight / 2)
    
    doc: https://airsdk.dev/docs/development/display/working-in-three-dimensions/projecting-3d-objects-onto-a-2d-view
    • Change in root.transform.perspectiveProjection is not effective. (In fact, even its setter is not implemented in Ruffle.)
    • perspectiveProjection of any ancestors is not taken into account while the doc says:

      The specified projection matrix and transformation will then apply to all the display object's three-dimensional children.

  • This PR doesn't implement non-translation transformations in 3D space. e.g. rotationX, scaleZ.

The implementation might not be the good one. Especially the Transform struct now has the new tz in addition to the existing matrix (2D). The tz property will be removed at the implementation of the full 3D transformation.

0.0,
0.0,
0.0,
1.0 / (viewport_width as f64 / 2.0),
Copy link
Contributor Author

@cookie-s cookie-s Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find the official resource to justify this scaling in Z. It just worked in image comparison with my eyes.

m
};
let move_coord = {
// AS3 places Viewpoint at (0, 0, -focalLength).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +58 to +64
let mut m = Matrix3D::IDENTITY;
m.raw_data[0] = focal_length;
m.raw_data[5] = focal_length;
m.raw_data[10] = focal_length;
m.raw_data[11] = 1.0;
m.raw_data[14] = 0.0;
m.raw_data[15] = 0.0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cookie-s
Copy link
Contributor Author

cookie-s commented Feb 2, 2025

Existing tests are failing... Some are small differences (e.g. again the 1px border difference), but some have big differences (e.g. visual/blend_mode/multiply, visual/shumway_acid_tests/acid_blend_2). Need to figure out.

Edit: WGSL code for blending had some parameters that don't work well with z values. Fixed at a07df30.

@cookie-s cookie-s marked this pull request as ready for review February 2, 2025 16:56
@kjarosh kjarosh added A-rendering Area: Rendering & Graphics T-compat Type: Compatibility with Flash Player labels Feb 2, 2025
let pos = common__globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 1.0, 1.0);
let uv = vec2<f32>((pos.x + 1.0) / 2.0, -((pos.y - 1.0) / 2.0));
let pos = common__globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 0.0, 1.0);
let uv = vec2<f32>(in.position.xy);
Copy link
Contributor Author

@cookie-s cookie-s Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure of this change to be honest. Because in other WGSL files, the uv is independent of world_matrix (and sometimes uses another matrix texture_matrix), I thought this is correct, but not sure.

Copy link
Contributor Author

@cookie-s cookie-s Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct. I believe Ruffle uses those coordinate systems?:

  • in.position: [0, 1] * [0, 1] (e.g. Quad) (wgpu texture coordinate system)
  • world_matrix * in.position: [0, width] * [0, height] (FP coordinate system)
  • view_matrix * world_matrix * in.position: [-1, 1] * [-1, 1] (wgpu render coordinate system)

wgpu coordinate systems: https://github.com/gfx-rs/wgpu?tab=readme-ov-file#coordinate-systems

@cookie-s cookie-s force-pushed the render-matrix3d-tz branch 2 times, most recently from c272872 to 6078de0 Compare February 8, 2025 23:18
In Transform.Matrix3D setter, the transformation matrix was
crushed to 2D, ignoring 3D parameters.
This commit picks up tz element (i.e. raw_data[14] element) into
render.Transform and take it into account in wgpu rendering.
The projection matrix for the default perspective projection
(FOV: 55.0 deg, center: stage center) is introduced to rendering.
They replace flash.display.DisplayObject z getter/setter stubs.
The z value (z translation) is now taken into account in wgpu rendering.
displayobject_z is the test for rendering with different tz values
from a few places by the image comparison.
geom_transform test didn't have meaningful values for z-axis related
field on purpose because it was unsupported.
This commit adds some random values into fields supported by this patch,
translation in z-axis.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rendering Area: Rendering & Graphics T-compat Type: Compatibility with Flash Player
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chirumiru: Display Bug
2 participants