Jump to content

  • Log In with Google      Sign In   
  • Create Account

Is it possible that a vertex declaration is optional field?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 13 August 2012 - 01:24 PM

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.

Sponsor:

#2 phil_t   Crossbones+   -  Reputation: 4109

Like
1Likes
Like

Posted 13 August 2012 - 01:43 PM

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.

Edited by phil_t, 13 August 2012 - 01:43 PM.


#3 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 20 August 2012 - 06:35 AM

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.

Edited by ShotoReaper, 20 August 2012 - 09:18 AM.


#4 Seabolt   Members   -  Reputation: 633

Like
0Likes
Like

Posted 20 August 2012 - 11:04 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS