FVF not necesary in shaders?
I recently saw in a book that once you use shaders / effects, you should set the FVF, and VertexDeclaration to NULL.
Is it right to belive that you only need to declare the vertexbuffer-structure in the shader/effect-code and then make sure you use a vertexbuffer with a somewhat similar structure; not setting any FVF or vertexdeclaration what so ever?
And, if so, can you make a Non-FVF-vertexbuffer and happily send it to a shader without setting any FVF or VertexDeclaration and only use shader to sort the incomming data?
// Happy for any help I can get.
a Vertex Declaration or FVF code is required for any D3D rendering, both fixed and programmable pipeline. You must set one or the other, and setting the data in the shader input is not sufficient. DX uses the Vertex Declaration to compute which part of the vertex structure goes into which shader input register. This also means the order of inputs in the shaders doesn't need to match that in the Vertex Structure.
As for FVF-less buffers, you can freely use them for any rendering. Simply pass 0 as the FVF flag when creating the buffer. The only reason the FVF is needed in relation to the vertex buffer is for Software Vertex Processing (specifically using ProcessVertices). If you're not using that function, you don't need an FVF specified in the buffer creation call.
Hope this helps.
As for FVF-less buffers, you can freely use them for any rendering. Simply pass 0 as the FVF flag when creating the buffer. The only reason the FVF is needed in relation to the vertex buffer is for Software Vertex Processing (specifically using ProcessVertices). If you're not using that function, you don't need an FVF specified in the buffer creation call.
Hope this helps.
You need a vertex declaration so the shader knows what kind of data it has to work with. To my knowledge, you can't declare a vertex buffer in the shader code. I could be wrong, so anyone feel free to correct me if I am. Alternatively, you can declare a FVF and then create a vertex declaration based off the FVF. Use the D3DXDeclaratorFromFVF function to do this. It takes two arguments, the FVF and and an array of D3DVERTEXELEMENT9 structures in which to place the generated info. You then use this array in the CreateVertexDeclaration function. I hope this answered your question and that it helps you out.
-AJ
-AJ
No.
The FVF in the VB can be 0, it's only used for the destination VB when using ProcessVertices so that it knows where to store it's output.
When using a shader, you use an FVF *or* a declaration. Whichever you set last is used, there is no need to set the other to 0. Your vertex input structure in HLSL says which data the shader needs, which might not be all your vertex data (a shader doing a Z pass probably doesn't care about UVs, color, normals, etc.).
Think of a few simple examples. Most shaders declare vertex diffuse as FLOAT4... except that it's a DWORD in your structure. How does D3D know if you're really using 4 floats of a D3DCOLOR? That's what the FVF/Declaration is for.
The FVF in the VB can be 0, it's only used for the destination VB when using ProcessVertices so that it knows where to store it's output.
When using a shader, you use an FVF *or* a declaration. Whichever you set last is used, there is no need to set the other to 0. Your vertex input structure in HLSL says which data the shader needs, which might not be all your vertex data (a shader doing a Z pass probably doesn't care about UVs, color, normals, etc.).
Think of a few simple examples. Most shaders declare vertex diffuse as FLOAT4... except that it's a DWORD in your structure. How does D3D know if you're really using 4 floats of a D3DCOLOR? That's what the FVF/Declaration is for.
If you are using a mesh you don't need to set any vertex declaration explicitly but when you are working with vertex buffers you have, you don't set any FVF flags though.
Thanks all! Most helpful! A last question though...
What does it do if you set the registers manually in your code? Like:
float4 color : DIFFUSE : register(c0); // for example?
Can you, like, "kidnap" the data from the FVF/vertexdeclaration? =)
Quote:Original post by sirob
DX uses the Vertex Declaration to compute which part of the vertex structure goes into which shader input register.
What does it do if you set the registers manually in your code? Like:
float4 color : DIFFUSE : register(c0); // for example?
Can you, like, "kidnap" the data from the FVF/vertexdeclaration? =)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement