Space ship trail effects

Started by
15 comments, last by Vanz 20 years, 5 months ago
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)
Bobboau, bringing you products that work... in theory
Advertisement
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)
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
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 typesm_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]
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]
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]
the SCP site is here

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
Bobboau, bringing you products that work... in theory

This topic is closed to new replies.

Advertisement