bevy icon indicating copy to clipboard operation
bevy copied to clipboard

ensure all Material2d rendering happen in order

Open mockersf opened this issue 1 year ago • 1 comments

Objective

  • Material2d rendering order is random
  • This can be seen in example wireframe_2d, wireframe is randomly visible 50% of the time

Solution

  • Add a temp resource counting the materials added
  • Add sets to materials with a unique value
  • Order each material to be after those added before
  • This means rendering order is dependent on plugin addition order

Testing

steps=10; git restore .;
echo "wireframe_2d" > test
cargo run -p example-showcase -- run --stop-frame 250 --screenshot-frame 100 --fixed-frame-time 0.05 --example-list test --in-ci;
mv screenshots base;
for prefix in `seq 0 $steps`;
do
  echo step $prefix;
  cargo run -p example-showcase -- run --stop-frame 250 --screenshot-frame 100 --fixed-frame-time 0.05 --example-list test;
  mv screenshots $prefix-screenshots;
done;
mv base screenshots
for prefix in `seq 0 $steps`;
do
  echo check $prefix
  for file in screenshots/*/*;
  do
    echo $file;
    diff $file $prefix-$file;
  done;
done;

mockersf avatar Nov 25 '24 21:11 mockersf

I'm not sure how I feel about this. I think the issue is wireframes being wrong. It doesn't feel like that's the rigth fix for the issue. I need to think about this more.

IceSentry avatar Dec 01 '24 19:12 IceSentry

I'm not happy about making it dependent on plugin order, but the fact that Material2d order is random is wrong

mockersf avatar Dec 10 '24 11:12 mockersf

The problem with wireframes is that they break the 1:1 mapping between entities and meshes/materials, which breaks things in lots of ways that can't be fully covered up by forcing the rendering order. One way to fix wireframes properly would be to add a WireframePass and treat wireframes as a sort of prepass-like thing.

pcwalton avatar Jan 22 '25 18:01 pcwalton

Yeah, at the time I ported the wireframe from their own pass to the current wireframe material thing because it simplified a lot of the code, but in hindsight that isn't as ideal of a solution. It's nice that the code is a bit simpler but it's probably less efficient than it could be.

IceSentry avatar Jan 22 '25 20:01 IceSentry