You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Voxels changing position when other entities are present #2
Hello, I'm trying to integrate the voxel plotting into an existing application. I'm seeing the transformation of the voxels change with that of seemingly unrelated cuboid entities and with changing camera position. It's a bit of a long shot but I was wondering if you had any ideas what might cause such behaviour @hacknus ?
e.g. without other cuboid entities:
with an added cuboid entity, with some rotation:
I'm pretty sure that my system that handles the updating of the cuboid transform should not alter the spawned voxel entity. Any insight is hugely appreciated, the integration feels close except for this odd behaviour!
I can do when I have some time tomorrow, for now I am wondering if it is a consequence of the shader using get_world_from_local(0u)? I have no experience with .wgsl files, so just a hunch.
#import bevy_pbr::mesh_functions::{get_world_from_local, mesh_position_local_to_clip}
struct Vertex {
@location(0) position: vec3<f32>,
@location(1) normal: vec3<f32>,
@location(2) uv: vec2<f32>,
@location(3) i_pos_scale: vec4<f32>,
@location(4) i_color: vec4<f32>,
};
struct VertexOutput {
@builtin(position) clip_position: vec4<f32>,
@location(0) color: vec4<f32>,
};
@vertex
fn vertex(vertex: Vertex) -> VertexOutput {
let position = vertex.position * vertex.i_pos_scale.w + vertex.i_pos_scale.xyz;
var out: VertexOutput;
// NOTE: Passing 0 as the instance_index to get_world_from_local() is a hack
// for this example as the instance_index builtin would map to the wrong
// index in the Mesh array. This index could be passed in via another
// uniform instead but it's unnecessary for the example.
out.clip_position = mesh_position_local_to_clip(
get_world_from_local(0u),
vec4<f32>(position, 1.0)
);
out.color = vertex.i_color;
return out;
}
@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
return in.color;
}
Activity
hacknus commentedon Nov 6, 2025
Hello @arodgers-dg
Thanks for bringing this up! This looks odd indeed. Can you share your code?
arodgers-dg commentedon Nov 6, 2025
I can do when I have some time tomorrow, for now I am wondering if it is a consequence of the shader using
get_world_from_local(0u)? I have no experience with.wgslfiles, so just a hunch.hacknus commentedon Nov 7, 2025
Yes, that might indeed be the cause. I'm also not too familiar with wgsl, unfortunately. I based this code on the official example from bevy (it has been moved to here in bevy 0.17: https://github.com/bevyengine/bevy/blob/main/examples/shader_advanced/custom_shader_instancing.rs)
arodgers-dg commentedon Nov 7, 2025
F.Y.I I managed to fix the behaviour with the following:
👍
hacknus commentedon Nov 7, 2025
oh cool! can you create a PR?
arodgers-dg commentedon Dec 1, 2025
Closed by #3