bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.3k stars 3.48k forks source link

Instance mesh coordinates are changing #11097

Open wk39 opened 9 months ago

wk39 commented 9 months ago

Bevy version

0.12.1

Relevant system information

cargo 1.74.0 (ecb9851af 2023-10-18) Ubuntu 22.04

`AdapterInfo { name: "NVIDIA GeForce RTX 2080 Ti", vendor: 4318, device: 7684, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "535.129.03", backend: Vulkan }`

What you did

I added some PBR mesh in the examples/shader/shader_instancing.rs.

What went wrong

When I add a PBR Mesh, there is an issue where the coordinates of the instance mesh are changing.

Peek 2023-12-27 15-37

Additional information

After several trial and error attempts, I modified 'instancing.wgsl' as follows:

// original
out.clip_position = mesh_position_local_to_clip(
    get_model_matrix(0u), vec4<f32>(position, 1.0)
);

// changed
out.clip_position = mesh_position_local_to_clip(
        mat4x4<f32>(
            vec4<f32>(1.0, 0.0, 0.0, 0.0),
            vec4<f32>(0.0, 1.0, 0.0, 0.0),
            vec4<f32>(0.0, 0.0, 1.0, 0.0),
            vec4<f32>(0.0, 0.0, 0.0, 1.0)
        ),
        vec4<f32>(position, 1.0)
    );

by forcing model_matrix as identity it resolved.

Modified example to reproduce this issue is here:

https://github.com/wk39/temporary/blob/4acf99b967d3f5ab678177502db71523eb0f2e59/shader_instancing.rs

Be careful. bevy version is v0.12.1 (shader_instancing.rs in latest commit has some change)

SarthakSingh31 commented 8 months ago

I tried to replicate this issue on the current main (07cd955c02e186ee36279e9511ee1dc4eb785960) but couldn't replicate it. It looks like the root cause of this issue was fixed at some point.

wk39 commented 8 months ago

Thanks for your check!

I checked out (https://github.com/bevyengine/bevy/commit/07cd955c02e186ee36279e9511ee1dc4eb785960 ) and tested but this happens still.

What I did:

  1. git checkout 07cd955
  2. merge https://github.com/wk39/temporary/blob/4acf99b967d3f5ab678177502db71523eb0f2e59/shader_instancing.rs into examples/shader/shader_instancing.rs
  3. cargo run --example shader_instancing

Thank you.

czaloj commented 5 months ago

Would you also believe that adding .insert(DepthPrepass) on the camera entity also crashes the example?