Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

How shall I create buffers for several attributes specific for my pass #1313

Closed
stavenko opened this issue Jan 2, 2019 · 3 comments
Closed

Comments

@stavenko
Copy link

stavenko commented Jan 2, 2019

Hello!

I am trying to create my own rendering pass. Main purpose of this pass is to render tile-map, using predefined texture for tiles. This is the main idea, how, i believe, this task shall be accomplished:

    1. Vertex shader shall receive simple point attributes, which shall have following info:
    • center of tile in the world. (vec3)
    • offset of tile piece on the provided texture (uvec2)
    • size of tile on the texture (uvec2)
    1. Geometry shader shall produce desired tile with center from vertex shader and with size, controlled by uniform variable. And pass offset and slice size to fragment shader then. (for example, I create six triangles with shared point in the center of the tile -- hex tile);
    1. Fragment shader shall retreive desired texture piece and put it on the framebuffer.

To accomplish this, somewhere internally in the deep of my code, I prepare three arrays:

  • Vec [x, y, z, x, y z....] with size = amount_of_tiles * 3 * size_of_float
  • Vec [x,y, x, y, ...] with size = amount_of_tiles * 2 * size_of_u32
  • Vec [w, h, w, h, ...] with size = amount_of_tiles * 2 * size_of_u32
    And try to create all three buffers with call
factory
      .create_buffer_immutable(
        &tile_coords_array, // Vec<f32> or Vec<u32>
        buffer::Role::Vertex, 
        Bind::empty()
      )

And then each apply call I do

effect.clear()

and then binding those buffers with:

    effect.data.vertex_bufs.push(vb.raw().clone()); // vec3
    effect.data.vertex_bufs.push(ob.raw().clone()); // uvec2
    effect.data.vertex_bufs.push(sb.raw().clone()); // uvec2

As a result I can see perfecly aligned tiles(so position attribute is passed to shader corretly), but it seems that other attributes are not passed at all.

I build effect with:

    effect 
      .geom(VERT_SHADER, GEOM_SHADER, FRAG_SHADER)
      .with_primitive_type(Primitive::PointList)
      .with_texture("tileSheet")
      .with_raw_constant_buffer(
        "TileMapArguments",
        mem::size_of::<<TileMapArguments as Uniform>::Std140>(),
        1
        )
      .with_raw_vertex_buffer(
        TileMapAttributes::ATTRIBUTES, 
        TileMapAttributes::size() as ElemStride,
        0)
      .with_blended_output("color", ColorMask::all(), blend::ALPHA, None)
      .build()

So I want to clear this out:

  1. Which way shall I create and organise my buffers. Shall I interleave them? Shall I make binding somehow else?
  2. Which way is it better to create effect? Shall I discover what is a Separate trait?
  3. How do I create PosColorTex(or PosColor, or whatever) instances? How to make array of them?
@fhaynes
Copy link
Member

fhaynes commented Mar 22, 2019

My apologies @stavenko. Do you still need assistance with this?

@fhaynes
Copy link
Member

fhaynes commented Mar 23, 2019

@stavenko Feel free to join Discord or post here: https://community.amethyst-engine.org/c/other-help if you still need this answered.

@fhaynes fhaynes closed this as completed Mar 23, 2019
@stavenko
Copy link
Author

@fhaynes, no problem. I figured out how to do that using rendering passes. If anyone needs assistance - feel free to contact me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants