Sign in to follow this  
pseudomarvin

Do I always need two separate sets of shaders when vertex input signatures differ

Recommended Posts

I have a rendering pipeline which includes shadow map pass, geometry pass and the main lighting pass which I use when rendering single models.

The vertex input signature is this: "POSITION", "NORMAL", "MATERIAL".

 

But if I want to render an object multiple times using instancing the input signature looks like this: "POSITION", "NORMAL", "MATERIAL" , "INSTANCE_POS".

 

So I either:

 

1.) Create separate shader programs for instancing and individual rendering which differ almost only in the input signature and a few details.

 

2.) Or render everything using DrawIndexedInstanced() and initialize the models with a dummy instance buffer which is not used(but it's size can't be 0 as I've just verified since that results in 'CreateBuffer returning E_INVALIDARG') and just set the instanceCount to 1 for single objects ?

 

3.) A better alternative I have not thought of

 

What is the most reasonable way to do this? Thanks.

 

Share this post


Link to post
Share on other sites

1) Yup, if the input differs, so must the vertex shader. The only way to keep the same signature is providing input through bound buffers instead of the input assembler. Still needs a different vertex shader though, so...

 

2) Is actually quite sensible. An empty buffer doesn't make sense though, so create a buffer with just one entry for the instance data (matrix or whatever). Note that you can use offsets in both binding vertex buffers or with the draw call, so you can actually just use one buffer for everything (idea is to update/upload as few times as possible) and work with offsets for the instance data.

Share this post


Link to post
Share on other sites

Great. thanks. So theoretically (if the implementation restricton on max buffer size allowed it) you could place all of the game objects together with their instances into just one buffer and remember the particular offsets and use that? And that would be the most effective way to do it? Or did you just mean using one buffer for vertex data, index data and instance data for one object?

Share this post


Link to post
Share on other sites
The API is quite flexible, so yeah you can stuff all into one buffer if you want. Though I wonder what one gains here. Personally I prefer separating geometry (vertices, indices) and instance data. There was a related discussion about this in the graphics subforum

Effective ? There's no best solution for all scenarios. Play around with different approaches and profile. If you want some inspiration have a look at vertex pulling (which goes a step further than normal instancing)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this