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

Frustum culling problem #1760

Closed
TheLeonsver1 opened this issue Mar 25, 2021 · 7 comments
Closed

Frustum culling problem #1760

TheLeonsver1 opened this issue Mar 25, 2021 · 7 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@TheLeonsver1
Copy link

TheLeonsver1 commented Mar 25, 2021

Bevy version

https://github.com/bevyengine/bevy?branch=main#1d7196da4fff00bbc15fe75a04849de915f587d5

Operating system & version

Windows 10

What you did

tried to use frustum culling

I spawn a camera like this:

let mut orth_camera = OrthographicCameraBundle::new_2d();
    orth_camera.transform.scale = Vec2::new(2.0, 2.0).extend(1.0);
commands
    .spawn()
    .insert_bundle(orth_camera)
    .insert(MainCamera);

I spawn the sprites like this:

local_commands.spawn().insert_bundle(HarvestableResouce {
    pickable: PickableBundle::default(),
    sprite: SpriteSheetBundle{
        texture_atlas:game_sprites.atlas_handle.clone(),
        sprite:TextureAtlasSprite { index: map[&texture_names[1].to_string()].index_in_atlas as u32,..Default::default()},
                                        transform:Transform::from_translation(
                                            area_cells[j].as_f32().mul(UNIT_TO_WORLD).extend(0.0)
                                                + Vec2::new(
                                                    thread_rng.gen_range(-15.0..15.0),
                                                    thread_rng.gen_range(-15.0..15.0),
                                                )
                                                .extend(0.0),
                                        ),
                                        ..Default::default()
                                    } 
                                });

What you expected to happen

expected

What actually happened

problem

Additional information

not really..

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen labels Mar 25, 2021
@alice-i-cecile alice-i-cecile added this to the Bevy 0.5 milestone Mar 25, 2021
@cart
Copy link
Member

cart commented Mar 25, 2021

Removing this from the 0.5 milestone in favor of #1761

@cart cart removed this from the Bevy 0.5 milestone Mar 25, 2021
@Byteron
Copy link
Contributor

Byteron commented Apr 12, 2021

From Discord:

the example works, so the math seems correct (at least for normal sprites).
Though I realize the math should probably use global transforms rather than local transforms. That would break when sprites or camera is child of some other entity.

Also, given the issue uses texture_atlas I suspect there is something odd going on in bevy_sprite/src/frustum_culling.rs inside of the atlas system. That would be my starting point for looking for issues.

@rparrett
Copy link
Contributor

Here is a simple test case involving sprite scaling.

https://github.com/rparrett/bevy-test/tree/culling

With culling disabled, you get a blue bar on the left side rotating into view. Enabled, nothing.

@alice-i-cecile
Copy link
Member

@cart do you think we should try to tackle this for 0.6? It feels very much in the flavor of "rendering performance and usability optimizations" that the rest of the release is about.

@cart
Copy link
Member

cart commented Aug 24, 2021

There is a chance that we'll add a proper frustum culling implementation prior to 0.6, but I don't want to block the release on it. Imo we need to start narrowing focus to get 0.6 out asap instead of expanding it.

@fuzzbuck
Copy link

Here is a simple test case involving sprite scaling.

https://github.com/rparrett/bevy-test/tree/culling

With culling disabled, you get a blue bar on the left side rotating into view. Enabled, nothing.

submitted PR based on this example ^
#2753

@nicopap
Copy link
Contributor

nicopap commented Jan 31, 2023

The new 2d renderer doesn't do frustrum culling as far as I can tell. Culling happen in bevy_pbr for light meshes and in bevy_render for things that have an Aabb. Sprites do not have an Aabb.

Mesh2d doesn't have an Aabb either, so nothing that has to do with 2d rendering is culled.

@nicopap nicopap closed this as completed Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

7 participants