Members - Reputation: 149
Posted 13 August 2012 - 01:24 PM
I want to use the same vertexshader with static models and dynamic models with bones. My problem is that my vertex input need use the fields
:BLENDWEIGHT0 and :BLENDINDICES0, and when the static model is rendered this fields give an error because they don´t have any information, This error is :
"The current vertex declaration does not include all the elements required by the current vertex shader. "
My dude is if it´s possible that this fields will be could be static.
PD I´m working with XNA.
Crossbones+ - Reputation: 4109
Posted 13 August 2012 - 01:43 PM
1) have two different shaders, but they could re-use much of the same code. Your vertex shaders could call a common function that does much of the work. The VS for the static model could pass the "constant" values for BLENDWEIGHT0 and BLENDINDICES0 to this worker function.
2) keep your shader unchanged, and make a vertex buffer that is filled with the "constant" values for BLENDWEIGHT0 and BLENDINDICES0 (as big as necessary to support your biggest static model - or you may be able to mess with the instanceFrequency of the VertexBufferBinding to do something smarter), and supply this as a second vertex stream when drawing.
(1) is theoretically faster.
Edited by phil_t, 13 August 2012 - 01:43 PM.
Members - Reputation: 633
Posted 20 August 2012 - 11:04 AM
What phil_t is saying is write two shaders, one where your input vertex structure (VS_INPUT or the like) does have the BLENDWEIGHT0 and BLENDINDICES0 included and use it with geometry that has Blend Weights and Blend Indices, and for geometry that doesn't have Blend Weights or BlendIndices, write a shader that doesn't have those fields in your input vertex structures and just pass the constant values for Blend Weights and Blend Indices into your pixel shader.