Jump to content
  • Advertisement
Sign in to follow this  

pass an array of some elements to a shader for every instance

This topic is 2019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there.


I have a scene with some thouthan instances, and i have a texture array;

I need to pass to every instance its own array of elements (of that texture array)

For example:


  1. 1) Texture array has 50 elements
  2. 2) Every instance can get his own set of elements, and count of elements can vary for every instance, for example:
    • a) instance 0 get set [1, 20, 40, 38, 16]
    • ?) instance 1 get set [14, 16]
    • ?) instance 2 get set [23, 34, 23]
    • etc

A question: how to organize array of D3D11_INPUT_ELEMENT_DESC for passing this stuff into the shader ?


It's clear, that's possible to create a lot of elements in input buffer for maximum number of my elements, but this solution looks very bad ...


to be clear: of course I don't need an input buffer to pass texture array - I've done it through Texture2DArray, but I don't know how to pass an unique set of elements for every instance ...

Edited by fdialke

Share this post

Link to post
Share on other sites

A vertex buffer filled with instance data is probably not the best option, unless you can cap the amount of indices per instance at some fixed number. Texture buffers are more flexible.


- store all indices together in a Texture buffer:


[1, 20, 40, 38, 16, 14, 16, 23, 34, 23]


- write per-instance offset and length values into a second buffer (or store them both in a single buffer).


[0, 5][5, 2][7, 3]


- In a shader use the Instance_ID system generated value to index the buffers.

Share this post

Link to post
Share on other sites

I woundn't use vertex buffer. I would rather use a StructuredBuffer(or a Tbuffer) with SV_InstanceID to pick the data set.

Edited by imoogiBG

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!