Sign in to follow this  
Medo Mex

Sparks Effect

Recommended Posts

Medo Mex    891

Great!

 

The transformation issue is now resolved, now I'm trying to draw all the lines with only a single draw call, so I tried changing the following code:

 

 

// The following code draw line per draw call (I don't want that)
TVertex vrts[4];
vrts[0].pos = v0; vrts[0].otherPos = v1;
vrts[1].pos = v1; vrts[1].otherPos = v0;
vrts[2].pos = v0; vrts[2].otherPos = v1;
vrts[3].pos = v1; vrts[3].otherPos = v0;

vrts[0].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[1].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[2].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[3].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );

vrts[0].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.f );
vrts[1].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.f );
vrts[2].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.25f );
vrts[3].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.25f );

d3ddev->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vrts, sizeof( TVertex ) );

 

 

To:

// In this code, I'm trying to draw multiple lines with one single draw call
TVertex vrts[8]; // 8 instead of 4 (8 = 2 lines)

// Line 1
D3DXVECTOR3 v0(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 v1(0.0f, 100.0f, 0.0f);

vrts[0].pos = v0; vrts[0].otherPos = v1;
vrts[1].pos = v1; vrts[1].otherPos = v0;
vrts[2].pos = v0; vrts[2].otherPos = v1;
vrts[3].pos = v1; vrts[3].otherPos = v0;
vrts[0].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[1].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[2].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[3].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[0].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.f );
vrts[1].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.f );
vrts[2].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.25f );
vrts[3].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.25f );

// Line 2
D3DXVECTOR3 pV0(200.0f, 0.0f, 0.0f);
D3DXVECTOR3 pV1(200.0f, 100.0f, 0.0f);

vrts[4].pos = pV0; vrts[4].otherPos = pV1;
vrts[5].pos = pV1; vrts[5].otherPos = pV0;
vrts[6].pos = pV0; vrts[6].otherPos = pV1;
vrts[7].pos = pV1; vrts[7].otherPos = pV0;
vrts[4].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[5].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[6].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[7].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[4].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.f );
vrts[5].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.f );
vrts[6].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.25f );
vrts[7].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.25f );

// Draw all lines
d3ddev->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 4, vrts, sizeof( TVertex ) );

 

Now, the two lines are connected with each others, which of course undesired since I want to draw multiple separate lines with one draw call.

 

Do I have to set index buffer to draw multiple lines with one draw call? If yes, how do I fill the index buffer?

Share this post


Link to post
Share on other sites
Medo Mex    891
 
I tried the following code, but it's not working as expected:
// Create index buffer
DWORD* index = new DWORD[indicesCount];
DWORD j = 0;
indexBuffer->Lock(0, sizeof(index), (void**)&index, 0);
for(USHORT i = 0; i < indicesCount; i += 6)
{
    index[0+i] = 0+j;
    index[1+i] = 2+j;
    index[2+i] = 1+j;
    index[3+i] = 0+j;
    index[4+i] = 3+j;
    index[5+i] = 2+j;
    j += 4;
}
indexBuffer->Unlock();

 

// Draw
device->DrawIndexedPrimitiveUP( D3DPT_TRIANGLELIST, 0, 4, 2, indexBuffer, D3DFMT_INDEX32, vrts, sizeof( TVertex ) );

 

What's wrong?

Edited by Medo3337

Share this post


Link to post
Share on other sites
Ben Bowen    115

it's not working as expected:

 

I'll assume you don't know how to describe the problem. No, errors, it just looks funny, right?


1. The first issue I see is, to account for every line-segment you batch, make sure you do something like this (notice *lineNum):

device->DrawIndexedPrimitiveUP( D3DPT_TRIANGLELIST, 0, 4*lineNum, 2*lineNum, indexBuffer, D3DFMT_INDEX32, vrts, sizeof( TVertex ) );

 

Or you can increment a variable to use for the arguments, just as you probably do with 'vrts'.

 

2. Why are you making an allocation for the buffer? The following code you have written is unnecessary and bad: DWORD* index = new DWORD[indicesCount];

 

The Lock() function will modify your pointer to point somewhere used in the write-combining process. Not only is this memory allocation unnecessary, but you're creating a memory leak.

3. How do you determine "indicesCount" ?
4. My suggestions:

Construct your index layer in explicit terms of line segments. e.g.

 

uint i = 0;
uint vI = 0;
for (uint lineI = 0; lineI != lineQ; ++lineI)
{
	index[i++] = vI;
	index[i++] = vI + 2;
	index[i++] = vI + 1;
	index[i++] = vI + 1;
	index[i++] = vI + 2;
	index[i++] = vI + 3;
	vI += 4;
}

 

indicesCount can be determined just like this: lineQ * 6;

Notation info: I have a personal habit of appending a capital letter i to denote an index and Q to denote a quantity.

Hopefully these tips get you somewhere. biggrin.png

Edited by Reflexus

Share this post


Link to post
Share on other sites
Norman Barrows    7179

if you can't get what you're working on going, check out the point sprite demo mentioned in one of the previous posts. its in the directx 8 sdk (and perhaps later ones). it REALLY looks nice! JUST what you want. <g>

 

not sure how they do it. they may be lines, or thin tri's with gradient texture and lots of emissive on the material. never looked at the code. but the demo is killer.

 

and if dx8 will do, dx9 will do it for sure.

Share this post


Link to post
Share on other sites
Ben Bowen    115

It's not working.

 

How so? Please explain the problem, as I asked before. I just left you with tips and example code to get you pointed in the right direction -- but it was a guess nevertheless -- because you have not explained the debugging results.

Edited by Reflexus

Share this post


Link to post
Share on other sites
Ben Bowen    115

you might want to look at the effect file to see how the indices should be like.


Really... If you're not sure how to get them right yourself, just try different combinations. Really. There aren't too many to try. You could have fixed it by now.

Edit: Oh, sorry. I sound sour. I am not able to help you further. My time!

Edited by Reflexus

Share this post


Link to post
Share on other sites
Medo Mex    891

Yes, I have been trying to use different indices but couldn't get it to work.

 

Anyway, consider the question closed, I'll look for a way to resolve the issue.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this