Jump to content
  • Advertisement
Sign in to follow this  
poigwym

DX11 dx11 draw instance with different material

This topic is 695 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

I have learn how to draw many object in different position but share same mesh, material.

I'm curious about how to draw totally different object by using the instance buffer ? pack all matrix, material/texture to one buffer.

But throw all meshes to gpu seems impossible .

Share this post


Link to post
Share on other sites
Advertisement

In D3D11 you have two basic options.

1.sort by material and mesh - look up render queues in the forum... if you sort your drawcalls such that you minimize state changes between draw calls you get more draw call throughput and you can instance identical calls.

- also you should look up texture atlas's

2. if you set a null vertex buffer you can manually fetch vertices in the VS ( http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Vertex-Shader-Tricks-Bill-Bilodeau.ppsx ) if you combine this with instancing you can render alot of different meshes. ( http://advances.realtimerendering.com/s2015/aaltonenhaar_siggraph2015_combined_final_footer_220dpi.pdf )  This one is pretty complicated.

Share this post


Link to post
Share on other sites

There is a 3rd option:

 

Create an array of materials:

struct Material
{
float4 alpha_test_threshold;
float4 diffuse;


uint4 textureIndices0_3;
};


cbuffer materialArray : register(b1)
{
Material materialArray[1024];
};

And index them via SV_InstanceID:

materialArray[instanceId];

Note that SV_InstanceID always starts from 0 regardless from what baseInstance parameter in DrawPrimitive says. If you want an instance ID that starts from baseInstance, you'll need to setup an instance buffer pre-filled with values from [0; arbitraryLimit) and use that buffer instead.

 

This technique trades a little GPU overhead (an indirection + higher VGPR pressure instead of SGPR pressure) for massive lower CPU overheads.

Share this post


Link to post
Share on other sites

Oh there might be another option for you indirect drawing.  It's pretty robust in dx12 and is available in dx11, but I don't know if its as robust.

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!