Skip to content

Commit 559efc1

Browse files
authored
Merge pull request #3 from arodgers-dg/shader-fix
Shader change to assume real world positions
2 parents 832727c + 65cab1c commit 559efc1

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

CHANGELOG.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ All notable changes to the `bevy voxel plot` crate will be documented in this fi
66

77
### Added:
88

9-
* ...
9+
* Assume voxel vertices are real world coordinates in shader.
1010

1111
# 2.0.1
1212

assets/shaders/instancing.wgsl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#import bevy_pbr::mesh_functions::{get_world_from_local, mesh_position_local_to_clip}
1+
#import bevy_pbr::mesh_functions::{mesh_position_local_to_world}
2+
#import bevy_pbr::view_transformations::position_world_to_clip
23

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

1718
@vertex
1819
fn vertex(vertex: Vertex) -> VertexOutput {
19-
let position = vertex.position * vertex.i_pos_scale.w + vertex.i_pos_scale.xyz;
20+
// NOTE: Assumes vertex positions are real world positions
21+
let world_position = vertex.position * vertex.i_pos_scale.w + vertex.i_pos_scale.xyz;
22+
2023
var out: VertexOutput;
21-
// NOTE: Passing 0 as the instance_index to get_world_from_local() is a hack
22-
// for this example as the instance_index builtin would map to the wrong
23-
// index in the Mesh array. This index could be passed in via another
24-
// uniform instead but it's unnecessary for the example.
25-
out.clip_position = mesh_position_local_to_clip(
26-
get_world_from_local(0u),
27-
vec4<f32>(position, 1.0)
28-
);
24+
out.clip_position = position_world_to_clip(world_position);
2925
out.color = vertex.i_color;
3026
return out;
3127
}
3228

3329
@fragment
3430
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
3531
return in.color;
36-
}
32+
}

0 commit comments

Comments
 (0)