Sparks Effect

Started by
36 comments, last by Medo Mex 10 years, 11 months ago

I tried setting mWorldProjection to the camera projection and mWorld to the transformation of the volumetric lines.

worldProjection = world * projection. Got that right?

To be crabby... Those aren't even volumetric lines. They're just fancy linear billboards with UV selection based on orientation... in an outrageously terrible implementation at that! You probably could write up proper volumetric lines if you're competent, which I recommend. When you integrate over the path through an OBB, I don't think you'll want to base it on sqrt() distance, which would be pretty (INSANELY) naive considering performance, but won't provide a fully realistic distribution anyway. I'll reply again if I can think of a good way to do this. Others can throw in their suggestions too if they want. biggrin.png

EDIT:
This might be helpful. I'm reading it myself and I'll try to put it into useful terms (appropriate for your needs). smile.png

http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=5FFDAF33F6C101694D4F9987AFA25C3D?doi=10.1.1.96.5955&rep=rep1&type=pdf

One last additional remark

point sprites = billboards which are oriented about a point.

linear billboards = billboards which are oriented about a line.

Advertisement

worldProjection = world * projection. Got that right?

When I do that, the lines are stuck on the camera all the time, they appear like sprites.

I believe this can accomplish what I need which is (sparks particles).

So, my only problem right now is setting the transformation, I have the problem that I mentioned earlier.


worldProjection = world * projection                  // --> Stuck on the camera all the time
worldProjection = camera->GetProjectionMatrix();      // --> I don't see the lines anymore

Show me the actual code involving ->SetMatrix()

I tried doing the following:


D3DXMATRIX mWorld;
D3DXMatrixIdentity(&mWorld);

mWorldProjection = camera->getProjectionMatrix();

effect->SetMatrix( "mWV", &mWorld );
effect->SetMatrix( "mWVP", &mWorldProjection );

When I do that I don't see the lines.

When I do that I don't see the lines.

Where are their positions defined anyway? If you're just using identity then you should make sure they're in that small limited frustum which is tanget to the XY plane (i.e. screen space), and make sure your Z-clipping fits. lol, otherwise, actually use the right matrices. I'll try to explain below. This is the code you showed me:


D3DXMATRIX mWorld;
D3DXMatrixIdentity(&mWorld);

mWorldProjection = camera->getProjectionMatrix();

effect->SetMatrix( "mWV", &mWorld );
effect->SetMatrix( "mWVP", &mWorldProjection );

mWorld should be world * view, and mWorldProjection should be mWorld * your projection. What is the name of your matrix for viewspace? You don't seem to have any clue of what your own matrices are or what they do anyway. I think you need to go back and properly understand how transformation matrices are used to render 3D scenes.

Do you understand what a world matrix really is, and what a view matrix is?


WVP = world * view * projection. In simpleton terms, world refers to how individual content is transformed. View is how the virtual camera is positioned/oriented. Projection is how things are projected onto the screen plane. D3d9 abstracts these, but eventually it really just concatenates them into a single matrix and multiplies geometry by this to get it into its final position in camera space (pretty much screen space; the difference is somewhat trivial). So here, it asks for two matrices, WV and WVP. WV is world * view, and WVP is just WV * projection. Got it?

By the way, I may have thought of a good and fast way to do real volumetric lines, but I'll need to try it for myself before I start spewing nonsense.

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?

No it's a triangle strip, so even with an index layer you can't specify breaks between the lines. Try to use a triangle list instead. For this I guess you can use http://msdn.microsoft.com/en-us/library/windows/desktop/bb174370%28v=vs.85%29.aspx

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?

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

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.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement