Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ All notable changes to the `bevy voxel plot` crate will be documented in this fi

### Added:

* ...
* Assume voxel vertices are real world coordinates in shader.

# 2.0.1

Expand Down
18 changes: 7 additions & 11 deletions assets/shaders/instancing.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import bevy_pbr::mesh_functions::{get_world_from_local, mesh_position_local_to_clip}
#import bevy_pbr::mesh_functions::{mesh_position_local_to_world}
#import bevy_pbr::view_transformations::position_world_to_clip

struct Vertex {
@location(0) position: vec3<f32>,
Expand All @@ -16,21 +17,16 @@ struct VertexOutput {

@vertex
fn vertex(vertex: Vertex) -> VertexOutput {
let position = vertex.position * vertex.i_pos_scale.w + vertex.i_pos_scale.xyz;
// NOTE: Assumes vertex positions are real world positions
let world_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.clip_position = position_world_to_clip(world_position);
out.color = vertex.i_color;
return out;
}

@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
return in.color;
}
}