Skip to content

Instantly share code, notes, and snippets.

@boyswan
Last active October 24, 2022 19:12
Show Gist options
  • Save boyswan/d521f3a944e7004d328a22fe811f1bd6 to your computer and use it in GitHub Desktop.
Save boyswan/d521f3a944e7004d328a22fe811f1bd6 to your computer and use it in GitHub Desktop.
wgpu
// I set up my mesh and insert my custom attribute with an empty value
pub const ATTRIBUTE_FRAME: MeshVertexAttribute =
MeshVertexAttribute::new("frame", 988540917, VertexFormat::Float32x2);
let mut mesh = Mesh::from(shape::Quad::new(Vec2::splat(48.0)));
let empty: Vec<[f32; 2]> = vec![[0.0; 2]; 4];
mesh.insert_attribute(ATTRIBUTE_FRAME, empty);
// Add attribute with batched values in batch loop
if let Ok(mesh_handle) = mesh_handles.get(batcher) {
if let Some(mesh) = meshes.get_mut(&mesh_handle.0) {
mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, batch.positions.to_owned());
mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, batch.normals.to_owned());
mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, batch.uvs.to_owned());
mesh.insert_attribute(ATTRIBUTE_FRAME, batch.frames.to_owned());
mesh.set_indices(Some(Indices::U16(batch.indices.to_owned())));
}
};
//Update my material description and give attribuate a location
fn specialize(
descriptor: &mut RenderPipelineDescriptor,
layout: &MeshVertexBufferLayout,
_key: Material2dKey<Self>,
) -> Result<(), SpecializedMeshPipelineError> {
...
let vertex_layout = layout.get_layout(&[
Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
Mesh::ATTRIBUTE_NORMAL.at_shader_location(1),
Mesh::ATTRIBUTE_UV_0.at_shader_location(2),
ATTRIBUTE_FRAME.at_shader_location(3),
])?;
descriptor.vertex.buffers = vec![vertex_layout];
}
// try to access as argument
@fragment
fn fragment(
@location(0) pos: vec4<f32>,
@location(1) norm: vec3<f32>,
@location(2) uv: vec2<f32>,
@location(3) frame: vec2<f32>
) -> @location(0) vec4<f32> {
...
}
//However keep getting
/*
panicked at 'wgpu error: Validation Error
Caused by:
In Device::create_render_pipeline
note: label = `transparent_mesh2d_pipeline`
error matching FRAGMENT shader requirements against the pipeline
location[3] Float32x2 interpolated as Some(Perspective) with sampling Some(Center) is not provided by the previous stage outputs
input is not provided by the earlier stage in the pipeline
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment