Skip to content

Instantly share code, notes, and snippets.

@boyswan
Last active October 24, 2022 19:12
Show Gist options
  • Select an option

  • Save boyswan/d521f3a944e7004d328a22fe811f1bd6 to your computer and use it in GitHub Desktop.

Select an option

Save boyswan/d521f3a944e7004d328a22fe811f1bd6 to your computer and use it in GitHub Desktop.

Revisions

  1. boyswan revised this gist Oct 24, 2022. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions gistfile1.rs
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,24 @@

    // I set up my mesh and insert my custom attribute
    // 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 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())));
    }
    };
    // 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
    //Update my material description and give attribuate a location
    fn specialize(
    descriptor: &mut RenderPipelineDescriptor,
    layout: &MeshVertexBufferLayout,
  2. boyswan revised this gist Oct 24, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rs
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ fn specialize(
    descriptor.vertex.buffers = vec![vertex_layout];
    }


    // try to access as argument
    @fragment
    fn fragment(
    @location(0) pos: vec4<f32>,
  3. boyswan revised this gist Oct 24, 2022. 1 changed file with 15 additions and 3 deletions.
    18 changes: 15 additions & 3 deletions gistfile1.rs
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,16 @@ let empty: Vec<[f32; 2]> = vec![[0.0; 2]; 4];
    mesh.insert_attribute(ATTRIBUTE_FRAME, empty);


    ...inside batch
    mesh.insert_attribute(ATTRIBUTE_FRAME, batch.frames);
    // Add attribute 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
    fn specialize(
    @@ -38,7 +46,10 @@ fn fragment(
    }


    However keep getting

    //However keep getting

    /*
    panicked at 'wgpu error: Validation Error
    Caused by:
    @@ -47,4 +58,5 @@ Caused by:
    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
    */

  4. boyswan renamed this gist Oct 24, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. boyswan created this gist Oct 24, 2022.
    50 changes: 50 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@

    // I set up my mesh and insert my custom attribute
    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);


    ...inside batch
    mesh.insert_attribute(ATTRIBUTE_FRAME, batch.frames);

    //Update my material description
    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];
    }


    @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