direct 3d design questsions

Started by
21 comments, last by superpig 15 years, 11 months ago
Quote:Original post by Sync Views
So I need my shader to:
-Use the appropiate world transform arcording to the vertexes quad index
-Use the current view transfrom (so camra xyz, angle)
-Use the current projection transfrom (perspective?)
Correct. Given that this is 2D, both the world and view transforms can probably just be 2x3 matrices; if you pack that into two 4-vector constants, that leaves you two components free that you could pack a Z offset and one other piece of information into (alpha value?). Projection would probably want to be an orthographic projection rather than a perspective projection.

Quote:
Also all the 2d D3D stuff Ive seen has drawn struff in the order it's wanted.
Is there a reason people do it that way rather than:
-Setting a projection with no perspective
-Drawing quads using the z axis so the grafics card can decide if things are above or below each other thus allowing me to draw everything with a single texture in one go.
Using the Z buffer means you're allocating a Z buffer (more memory usage) and in theory it'd be possible for a card to render non-Z-tested stuff slightly faster than Z-tested stuff (because it doesn't have to do the Z-test, natch). In practice, though, the extra memory usage isn't an issue and the speed difference is actually probably zero, because non-Z-tested stuff is often treated as a Z-test of 'always pass'. Being able to use a single texture and skipping the sort-by-depth is a bigger win.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Advertisement
ok well ive written this vertex shader, now just to find out how to actualy use it...

struct VS_INPUT{	vector position : POSITION;	vector uv       : TEXCOORD;	vector quad     : TEXCOORD;};struct VS_OUTPUT{	vector position : POSITION;	vector uv       : TEXCOORD;	vector diffuse  : COLOR;};matrix WorldMatrix[100];//max 100 quads per batchmatrix ProjMatrix;matrix ViewMatrix;VS_OUTPUT Main(VS_INPUT input){	VS_OUTPUT output = (VS_OUTPUT)0;		//move the vector to screen space	vector position = input.position;	position = mul(position, WorldMatix[input.quad]);	position = mul(position, ProjMatix);	position = mul(position, ViewMatix);		output.position = position;	output.diffuse = {1.0f, 1.0f, 1.0f, 1.0f};//white	output.uv = input.uv;	return output;}

A is this the right vertex declaration for that?
struct VertexQuad{	float x, y, z;//float3 position0	float u,v;    //float2 texcords0	float quad;   //int    texcords1	VertexQuad(const float x, const float y, const float z, const float u, const float v, const float quad);}...	D3DVERTEXELEMENT9 decl[] =	{		{0, 0 , D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},//x,y,z		{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},//u,v		{0, 24, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},//quad		D3DDECL_END()	};


[Edited by - Sync Views on May 21, 2008 1:14:07 AM]
Not quite. The offset and data type for the third element are wrong. (Failing that, the type of the third component of the structure is wrong).

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement