Jump to content
  • Advertisement
Sign in to follow this  
arkerone

Dynamic array on Shader

This topic is 2386 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,

I would create a dynamic table on a shader that contains a global matrix like this:
CPU:
D3DXMATRIX * mWorld;

GPU:
Matrix *mWorld

How do that?

Thx.

Share this post


Link to post
Share on other sites
Advertisement
I don't believe it is possible to create a dynamic array in the shaders. You will have to specify the number of elements in the array:

GPU:
#define MAX_ELEMENTS 1000
Matrix *mWorld[MAX_ELEMENTS]

Then just never send more than maxElements to the shader. Of course it would be best to know exactly how many elements you will need so you don't waste memory by creating a larger array than you need. I don't know for sure what the max is for matrices, but i think it's around 1000 (I say 1000 from what i've seen. I can have an array of 1000 float4x4's in my shader, but when i tried 2000 it wouldn't work). maybe it depends on the graphics card though. If you have to send more than 1000 (or whatever the max it lets you send to it), you will have to do multiple draw calls

Share this post


Link to post
Share on other sites
You may also use a generic float4 buffer to simulate a buffer with varying amount of elements, although the maximum size is fixed.

Cheers!

Share this post


Link to post
Share on other sites
The guaranteed size per constant buffer with D3D10/11 class hardware is 4096; older hardware will have less. Each float4 needs one slot here so a matrix needs 4 slots.

You could alternatively handle this with a texture lookup. Use vertex texture fetch in you need to access it in your vertex shader.

Share this post


Link to post
Share on other sites
Thx, i solved my problem i used a buffer like a ressource.
And in my shader i used my buffer :

struct cbInstance {
Matrix mWorldInstance;
float4 colorInstance;
};
StructuredBuffer<cbInstance> instanceObject : register(t10);
VSout VSmain( VSin Vin,uint InstId:SV_InstanceID) {
VSout Vout = (VSout)0;
float4 worldPosition;
worldPosition = mul(float4(Vin.pos,1), instanceObject[InstId].mWorldInstance);
Vout.pos = mul(worldPosition, mViewProj);
return Vout;
};

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!