Is it possible that a vertex declaration is optional field?

Started by
2 comments, last by Seabolt 11 years, 8 months ago
Hi!

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.

Greetins!

PD I´m working with XNA.
Advertisement
Well, you would need different shader permutations. You could do this two ways:

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.
If you could write a small sample of your first theory I'd appreciate it. I'm starting with the HLSL and I can not do exactly what you say.
The issue is that since the vertex declarations don't match, the shader doesn't know what fields of the vertex match to what fields in the shader.

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.
Perception is when one imagination clashes with another

This topic is closed to new replies.

Advertisement