Skip to main content
GameDev.net gamedev.net
🔒 Locked

VertexElement without POSITION

Started by PaulSmecker Aug 5, 2006 at 11:37 AM 9 replies 1.1k views
Original Post
PaulSmecker
PaulSmecker
Hello! I have a simple (i hope so) question: Is it possible to render a triangle in Directx without using DrawPrimitive (or a similar function). The problem is: My program creates a large ammount of triangles, but all coordinates can be stored in a byte. In order to push as little data to the GPU as possible i tried to store the position in only the needed 4 byte. So i tried to create a VERTEXELEMENT which looks like

D3DVERTEXELEMENT9 decl[]=
{
	{0,0,D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,0},
	D3DDECL_END()
};
I use UBYTE4 because it look like it could be ideal for my problem. I will store in every UBYTE one coordinate. In a vertexshader they should be transformed into the correct float4 value. But now here comes my problem: if i try to use this declaration the DrawPrimitive function returns D3DERR_INVALIDCALL. It says the problem is that POSITION cant be an other type than float3 in the fixed function pipeline. So i tried to change the usage to D3DDECLUSAGE_BLENDWEIGHTS. Now it says that for the fixed function pipeline there has to be a POSITION value. So finally here comes my question: Is it possible either to render triangles only with a shader (only pass the elements in the right order to the shader and tell it the outcome should be a triangle) or create a declaration without the POSITION which works with the drawprimitives function. Tia PaulSmecker
vNistelrooy
vNistelrooy
Don't use the ffp then. It should work when using shaders.
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
AbandonedAccount
AbandonedAccount
D3DDECLTYPE_FLOAT16_4 may work and save you some space (16b, but not the 8b you're hoping for). Otherwise you may need to quit using the fixed function pipeline.

To use your own custom 8b values for position you will need to write shaders. If you did not write such a shader, the GPU does not know how to convert a UBYTE4 to a position. If you did write a shader to do the conversion, you need to be asking why your shader doesn't work.
Demus79
Demus79

It is possible to use 1 dword containing 4 values (ie. 4 bytes). In the vertex shader the values will be scaled to range on 0..1. I think that you can use FVF to specify this vertex format

VERTEX_FORMAT = ( D3DFVF_DIFFUSE )

or do the vertex declaration.

Cheers
hplus0603
hplus0603
The problem is that the fixed function pipeline only supports certain combinations of data types and usages.

The obvious solution is to start using shaders instead :-) Using ID3DXEffect, it's pretty easy.
enum Bool { True, False, FileNotFound };
treeway
treeway
As far as I know vertices MUST have a position even in the programmable pipeline.
Demus79
Demus79

Quote:


As far as I know vertices MUST have a position even in the programmable pipeline.



Well, it isn't true. You'll need position with ffp but with shaders, you are allowed to have what ever you desire in your vertex structure.

I use 2 dwords to pack a terrain vertex in my engine and neither of them are tagged as position.

Cheers
PaulSmecker
PaulSmecker
sorry, wasn't logged in!
The post above is from me
Namethatnobodyelsetook
Namethatnobodyelsetook
You still use the normal draw calls, but when vertex shader is active it isn't using the fixed pipeline, and the restrictions don't apply.

UBYTE4 will give 4 values from 0 to 255, while D3DCOLOR will give 4 values from 0 to 1. Not all hardware (ie: GeForce3 don't) support UBYTE4, but everything supports D3DCOLOR.

PaulSmecker
PaulSmecker
Finally!!!!!!!!!! :)

i found the HLSLwithoutEffect sample in the sdk and this uses the pipeline the way i want to use it (No FVF, only shaders).

Now i got it.

Thanks for the help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.