Giter Club home page Giter Club logo

Comments (8)

lordbenedikt avatar lordbenedikt commented on June 19, 2024 2

I have the same issue. I found that Z ordering is arbitrary with these shapes. I ran the same program several times without any changes and the ordering changed.

from bevy_prototype_lyon.

wrnrlr avatar wrnrlr commented on June 19, 2024

In my experience this is not true. With this little system I can always make sure the orange line is drawn over the blue line.

fn setup_paint(mut cmd: Commands) {
  cmd.spawn_bundle(Camera2dBundle::default());
  let options = StrokeOptions::default().with_line_width(LINE_WIDTH);
  let mut path_builder = PathBuilder::new();
  path_builder.move_to(Vec2::ZERO);
  path_builder.line_to(100.0 * Vec2::ONE);
  let line = path_builder.build();
  cmd.spawn_bundle(GeometryBuilder::build_as(&line, DrawMode::Stroke(StrokeMode{color:Color::BLUE, options}), Transform::from_translation(Vec3::new(0.0, 0.0, 1.0))));
  cmd.spawn_bundle(GeometryBuilder::build_as(&line, DrawMode::Stroke(StrokeMode{color:Color::ORANGE, options}), Transform::from_translation(Vec3::new(0.0, 0.0, 4.0))));
}

Also from reading the code in src/rendering/mod.rs it states that it does:

  transparent_phase.add(Transparent2d {
      entity: *visible_entity,
      draw_function: draw_shape,
      pipeline: pipeline_id,
      // The 2d render items are sorted according to their z value before rendering,
      // in order to get correct transparency
      sort_key: FloatOrd(mesh_z),
      // This material is not batched
      batch_range: None,
  });

and the vertex shader just uses the z position of the clip_position.

I was confused myself about this because I was trying negative values for z which don't show at all. I think this is confusion between how z buffer and depth buffer work.

Please feel free to create an example if you see other behaviour.

from bevy_prototype_lyon.

andrewexton373 avatar andrewexton373 commented on June 19, 2024

I've also got this same problem. In the game I'm working on I've got 2 entities, one for the player and another for the base station (spawn point essentially). The ordering of these being drawn is non deterministic and the z-index seems to be disregarded. My repository https://github.com/andrewexton373/geometry-wars is an example of this problem occurring, and the gif in the README shows the non deterministic ordering results when the player is over the base.

let base_station = commands.spawn()
            .insert_bundle(lyon::GeometryBuilder::build_as(
                &base_shape,
                lyon::DrawMode::Outlined {
                    fill_mode: lyon::FillMode::color(Color::MIDNIGHT_BLUE),
                    outline_mode: lyon::StrokeMode::new(Color::WHITE, 5.0),
                },
                Transform { translation: Vec3::new(0.0, 0.0, -100.0), ..Default::default() }
            ))

 let player = commands.spawn()
            .insert(Player::new())
            .insert_bundle(lyon::GeometryBuilder::build_as(
                &player_shape,
                lyon::DrawMode::Outlined {
                    fill_mode: lyon::FillMode::color(Color::CYAN),
                    outline_mode: lyon::StrokeMode::new(Color::WHITE, 2.0),
                },
                Transform {
                    translation: Vec3::new(0.0, 0.0, 100.0),
                    ..Default::default()
                }
            ))

from bevy_prototype_lyon.

wrnrlr avatar wrnrlr commented on June 19, 2024

Interesting, I remember playing around with the depth/z value and I found/(remember) that negative values don't work.
Could you try with only positive values.

from bevy_prototype_lyon.

andrewexton373 avatar andrewexton373 commented on June 19, 2024

Just tried it with 10.0 for the player and 100.0 for the base. Still have the issue with these z values.

from bevy_prototype_lyon.

andrewexton373 avatar andrewexton373 commented on June 19, 2024

I saw this snippet in the code, so it seems like the z-index should already be taken into account for rendering:

transparent_phase.add(Transparent2d {
                    entity: *visible_entity,
                    draw_function: draw_shape,
                    pipeline: pipeline_id,
                    // The 2d render items are sorted according to their z value before rendering,
                    // in order to get correct transparency
                    sort_key: FloatOrd(mesh_z),
                    // This material is not batched
                    batch_range: None,
                });

I'm not sure if there's a bug here or somewhere related. I'll try and reproduce the issue in a simpler project.

from bevy_prototype_lyon.

andrewexton373 avatar andrewexton373 commented on June 19, 2024

I wasn't able to reproduce the issue by modifying your dynamic shape example to have 2 overlapping shapes, so now I'm beginning to think it might have something to do with my use of rapier2d in conjunction with this project that's introducing the issue?

from bevy_prototype_lyon.

andrewexton373 avatar andrewexton373 commented on June 19, 2024

I'm not entirely sure here, but I was able to solve this in a hacky way by making a system to force set the player Transform's Z to be above the shape I was clipping with. I think rapier2d may have been setting the Transform's Z unknowingly and I discovered that with the bevy_inspector_egui. Here's the system I used:

    // FIXME: is this really the only way? I feel like rapier2d is messing with the z-value...
    fn keep_player_on_top(
        mut player_query: Query<(&mut Player, &mut Transform), (With<Player>, Without<Crosshair>)>
    ) {
        for (player, mut transform) in player_query.iter_mut() {
            transform.translation.z = 100.0;
        }
    }

from bevy_prototype_lyon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.