Archived

This topic is now archived and is closed to further replies.

Vanz

Space ship trail effects

Recommended Posts

Seen some discussions on this in the search but nothing all that usefull. Was wondering how to accomplish something like: or... I don''t really like the homeworld exhausts (2nd pic) because I think they are too long and too bright and look too cartooney. jmho... I kind of like the first one best. I am currently doing this: 1. Create a polygon mesh aft of the ship, using points of where the ship has been (see pic) 2. Make 2 polygon meshes perpendicular to each other so that it doesn''t look thin from the top (see pic) 3. Then depending on the thrust use points further away or closer to the ship 4. Map an exhaust gradient texture to the polygon stream them alpha blend to get the glow. This method looks good but not nearly as good as the top 2 pics. I also notice that in a big battle seen on Homeworld there are a ton of trails and fps is still high, so I don''t think they are using any kind of particle system. Any suggestions on how to do this better... rhuala

Share this post


Link to post
Share on other sites
"4. Map an exhaust gradient texture to the polygon stream them alpha blend to get the glow."

You will want to use addative blending (istead of alpha blending). Look it up - it is used to simulate glows, engine flares, light flashes, lasers, explosions etc (The pictures you''ve displayed use addative blending).
Also, I think the second picture looks pretty awful because it is too long and bright, but also the trail just stops mid air without fading out properly. So be sure to fade the trail into nothing at the far end.

Share this post


Link to post
Share on other sites
I was planning on implementing this effect with a particle system; but I am not planning to have anywhere near the number of ships as in HomeWorld II.

_______________________________________
Understanding is a three edged sword...

Share this post


Link to post
Share on other sites
Homeworld''s engine trail uses an axis aligned billboarding system. When a trail is made from point a to point b it is just a quad facing the camera, but oriented along the axis of travel. Take a look at the homeworld source code available on the relic developer network.

Share this post


Link to post
Share on other sites
quote:

Homeworld''s engine trail uses an axis aligned billboarding system. When a trail is made from point a to point b it is just a quad facing the camera, but oriented along the axis of travel.



That makes sense; but the trail is not a straight line if memory serves. How are they bending the trail stream?


_______________________________________
Understanding is a three edged sword...

Share this post


Link to post
Share on other sites
"Could you do a pixel shader? "

I really want and think there is a simpler less cpu intensive way...

"Homeworld''s engine trail uses an axis aligned billboarding system. When a trail is made from point a to point b it is just a quad facing the camera, but oriented along the axis of travel. Take a look at the homeworld source code available on the relic developer network. "

Sphet, could you please post the code or tell me the file name it''s in. I have the source but after about an hour of looking through a stack of files I couldn''t find (shader.c seemed closest) ... or better yet how about just elaborate your explanation a bit, like how would one create a billbaord oriented along the axis of travel for a quad that is shaped like a piece of string in 3d space...

"You will want to use addative blending... "
jack_1313, do you have any links or info on this, the gamedev search and google don''t turn up great help. I read a game conferencing article awhile back on how the game Tron was done, is this the same system, I may be able to find that article...''

Thanks for your replies...

rhuala

Share this post


Link to post
Share on other sites
yeah, just set the cull render state to false

and look at the freespace open source I''ve implemented a simpler effect (was shooting for some thing diferent than you) and FS has lots of the beam rendering (as I call it) as well as a working trail system you can probly rip off. also were always looking for good programers

also use tristrips for rendering

Share this post


Link to post
Share on other sites
while I''m here this is how FS generates the two verts for each point on the spline (this is actualy from the beam rendering code but it''s prety much identical)

void beam_calc_facing_pts( vector *top, vector *bot, vector *fvec, vector *pos, float w, float z_add )
{
vector uvec, rvec;
vector temp;

temp = *pos;

vm_vec_sub( &rvec, &Eye_position, &temp );
vm_vec_normalize( &rvec );

vm_vec_crossprod(&uvec,fvec,&rvec);
vm_vec_normalize(&uvec);

vm_vec_scale_add( top, &temp, &uvec, w/2.0f );
vm_vec_scale_add( bot, &temp, &uvec, -w/2.0f );
}


you see you take the cross product between the normalized vector from the point to your eye position and the forward vector of the segment (this can be determined in trails as the relitive position of the next segment from the last, exept for the first and last segment were you can just use the point it''self for one of the two) and then scale the result by the width of the trail at that segment both positivly and negitivly and that will be the two points for youre segment, just pop them into a tristrip vertex buffer then render it.
simple :D

Bobboau, bringing you products that work... in theory

Share this post


Link to post
Share on other sites
and additive alpha

d3d_SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE );
d3d_SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE );
d3d_SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE );

(d3d_SetRenderState is a wraper function, but you should get the idea)

Share this post


Link to post
Share on other sites
To switch to addatvie blending:

g_pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
g_pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);

And to change back to alpha:

g_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
g_pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

Easy. How does addative blending work? Well, instead of ''mixing'' the colors together (alpha blending) the RGB values are simply added on to the existing values. What I mean is this (done for each pixel when rendering):

Alpha blending
Initial color= 100,100,100
New pixel= 150,150,150
Alpha blended at 50 percent, the resulting pixel is:
125,125,125(the colors are mixed) assuming my maths is right

Addative blending:
Initial color= 100,100,100
New pixel= 150,150,150
Addative blended, the resulting pixel is:
250,250,250(color values are added)

Share this post


Link to post
Share on other sites
Hey thanks Bobboau... the culling is working good.

I don''t quite understand everything you are saying yet I will research more... are you rendering your beams, exhaust... etc to 2d screen space? Also, are you adding a texture to a spline (composed of line segments) to achieve this additive blending ... or how are you giving your beams depth

btw does anyone have link to freespace 2 souce code the one I have doesn''t work anymore...

FreeSpace Source

or could you please email to rhuala@shaw.ca...

Thanks.

rhuala

Share this post


Link to post
Share on other sites
Sorry jack_1313 , I posted above post, before I read your post. Here's how my blending looks on a plain 4 vertex poly with the texture above mentioned added for exhaust. There must be something wrong with my source, since the effects are not as expected, looks blah to me...


typedef struct sPoly3dVertex {
float x, y, z;
D3DCOLOR Diffuse; // Diffuse color component

float u, v;
} sPoly3dVertex;
#define Poly3dFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1)


D3DCOLOR Poly3dColor = D3DCOLOR_RGBA(0,0,255,50);

sPoly3dVertex Verts[4] = {
{ dx, dy+Hi, dz, Poly3dColor, 0.0f, 0.0f },
{ dx+Wide, dy+Hi, dz, Poly3dColor, 1.0f, 0.0f },
{ dx, dy-Hi, dz, Poly3dColor, 0.0f, 1.0f },
{ dx+Wide, dy-Hi, dz, Poly3dColor, 1.0f, 1.0f },
};


m_Poly3d.LoadTexture(0, "exhaust1.bmp"); // load function shown below...


BOOL cTexture::Load(cGraphics *Graphics, char *Filename, DWORD Transparent, D3DFORMAT Format)
{
Free();
if(FAILED(D3DXCreateTextureFromFileEx(Graphics->GetDeviceCOM(),
Filename, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
0, Format, D3DPOOL_MANAGED,
D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE,
Transparent, NULL, NULL, &m_Texture)))
}


//if(Alpha == TRUE) m_Graphics->EnableAlphaBlending(TRUE, D3DBLEND_SRCCOLOR, D3DBLEND_INVSRCCOLOR); //TEST 1

// if(Alpha == TRUE) m_Graphics->EnableAlphaBlending(TRUE, D3DBLEND_ONE, D3DBLEND_ONE); /TEST 2

if(Alpha == TRUE) m_Graphics->EnableAlphaBlending(TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);//TEST 3

else m_Graphics->EnableAlphaBlending(FALSE);

// Draw each layer

if(m_Texture.IsLoaded() == TRUE) {
m_Graphics->SetTexture(0, &m_Texture);
m_VB[0].Render(0,2,D3DPT_TRIANGLESTRIP);
m_VB[1].Render(0,2,D3DPT_TRIANGLESTRIP);
}

// Disable alpha testing and alpha blending

m_Graphics->EnableAlphaTesting(FALSE);
if(Alpha == TRUE) m_Graphics->EnableAlphaBlending(FALSE);
return TRUE;

//---- which are using this alphablending function function of course -------


BOOL cGraphics::EnableAlphaBlending(BOOL Enable, DWORD Src, DWORD Dest)
{
if(m_pD3DDevice == NULL)
return FALSE;

// Enable or disable

if(FAILED(m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, Enable)))
return FALSE;

// Set blend type

if(Enable == TRUE) {
m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, Src);
m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, Dest);
}

return TRUE;
}


if (FAILED(m_pD3D->CreateDevice D3DADAPTER_DEFAULT,
(m_HAL == TRUE) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF,
hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &m_pD3DDevice)))

// Enable texture rendering stages and filter types

m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );


... hope I included everything and that makes sense...

The other thing is that if I change the alpha value on my vertex color {Poly3dColor = D3DCOLOR_RGBA(0,0,255,50);} change 50 to anyrhing it has no effect...

How is the sparkley effect on the outskirts of the exhaust accomplished are they animating exhaust textures??

rhuala

[edited by - rhuala on November 18, 2003 7:29:42 AM]

Share this post


Link to post
Share on other sites
But why with additive blendin' my outcome is white square? I
have per-pixel alpha so the result should be smooth edge.


// Blendin' parameters.

m_lpD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_lpD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
m_lpD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

// Primitive color/alpha operations.

m_lpD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
m_lpD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_lpD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
m_lpD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_lpD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);



TFACTOR is currently set to 0xFFFFFFFF so the resultin' values
for alpha will be the alpha values taken from the texture (ARGB
texture). Note that my TFactor has a usage, so I'm leavin' it there.

But why is it so bright and I see whole texture to be nearly
white color? Thanks for any help.








[edited by - HaywireGuy on November 18, 2003 3:32:07 AM]

Share this post


Link to post
Share on other sites
HaywireGuy, I get that if my lights aren't setup right make sure your ambient light is set right...
m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, Enable)

if I have a point or directional I have to turn off ambient or it comes out pure white...

or change the texture color...

also fyi from the dx9 sdk
"Some hardware does not support simultaneous use of D3DTA_TFACTOR and D3DTA_DIFFUSE"



[edited by - rhuala on November 18, 2003 7:36:57 AM]

Share this post


Link to post
Share on other sites
the SCP site is [url=http://freespace.volitionwatch.com/fsscp/]here[/url]

the objects that get rendered with this are being generated in local 3d space, and beams are givven deapth by moving the rotated poly closer to the eye position, there is a Zadd vallue for each section of a beam (beams have a bunch of ''sections'' it''s basicly just the same poly drawen with diferent textures)

Bobboau, bringing you products that work... in theory

Share this post


Link to post
Share on other sites