janhohenheim / pixelate_mesh

Apply a pixelation effect to any Bevy mesh or scene without post-processing.
Apache License 2.0
77 stars 5 forks source link

Support Orthographic Projection #5

Open orclev opened 1 year ago

orclev commented 1 year ago

I was looking at this as a way to generate what looks like a 2D sprite based game easily by using 3D meshes and this plugin to simulate sprites but with dynamic lighting.

Much like the transform is being copied from the main camera, I think it would be possible to also copy the projection from the main camera onto the pixelation camera.

janhohenheim commented 1 year ago

So you mean simply syncing the projections is enough?

orclev commented 1 year ago

So you mean simply syncing the projections is enough?

I think so? I tested it out with a scene setup with a orthographic projection and while the model was pixelated, it was also very clearly using a perspective projection. I experimented with adjusting the sync_cameras system to copy the projection from the other cameras onto the PixelationCamera just like it does with the transform, which kind of worked, although there seemed to be a weird clipping artifact where parts of the model would vanish. I'm assuming something about the way the canvas entity is used also needs changes due to using a orthographic projection, but I'm not entirely understanding how this works currently. I'm going to keep poking around at this to see if I can figure out what needs to be done to fix it. Maybe something in this chunk of logic?

                const DISTANCE_FACTOR: f32 = 3.2;
                pixelation_camera_transform.translation += back * radius * DISTANCE_FACTOR;
janhohenheim commented 1 year ago

Feel free to open a draft PR, I might mayyyyybe be able to help 🙂