I've used TRANSPARENT_ADD_COLOR, accessed the color component of each vertex and faded it to black
Code: Select all
void CNebulaSceneNode::calcTexture()
{
if (m_center.X == -9000) return;
ICameraSceneNode* camera = SceneManager->getActiveCamera();
vector3df v0(1,1,0);
vector3df v1(1,0,0);
vector3df v2(0,0,0);
vector3df v3(0,1,0);
if (!m_device) return;
if (m_initTime == 0)
m_initTime = m_device->getTimer()->getTime();
u32 currentTime = m_device->getTimer()->getTime();
// rotate
m_theta = (m_theta + m_direction* (currentTime-m_initTime)/333.0f) ;
if (m_theta > 360.0f)
m_theta = m_theta - 360.0f;
/////////////////////
vector3df pos = getAbsolutePosition() ;//-Box.getExtent()/4;
// vector3df pos = m_center;
vector3df campos = camera->getAbsolutePosition();
vector3df diff = campos - pos;
core::vector3df target = camera->getTarget();
core::vector3df up = camera->getUpVector();
core::vector3df view = target - campos;
vector3df vtest = getAbsolutePosition() - campos;
vtest.normalize();
view.normalize();
float vdot = vtest.dotProduct(view);
// printf("vdot %4.3f\n",vdot);
float dist = (float) diff.getLength();
/*
trapezoid
x0 left start up ramp
x1 left start flat
x2 end flat start right down ramp
x3 end right ramp at 0
*/
float x0 = 2.0f;
float x1 = 140.0f;
float x2 = 160.0f;
float x3 = 300.0f;
float xr = 0.0f;
int r = 0;
//char tt[125];
if (dist > 0.0f && dist <= x0)
{
xr = 0;
// sprintf(tt,"section A %4.3f %4.3f \n",dist,xr);
}
if (dist > x0 && dist < x1)
{
xr = (dist - x0)/(x1 - x0);
// sprintf(tt,"section B %4.3f %4.3f \n",dist,xr);
}
if (dist >= x1 && dist <= x2)
{
xr = 1;
// sprintf(tt,"section C %4.3f %4.3f \n",dist,xr);
}
if (dist > x2 && dist < x3)
{
xr = (x3 - dist)/(x3 - x2);
// sprintf(tt,"section D %4.3f %4.3f \n",dist,xr);
}
if (dist > x3 )
{
xr = 0;
// sprintf(tt,"section e %4.3f %4.3f \n",dist,xr);
}
xr = xr * ((2.0f* vdot) -1.0f); //effect for rotation
if (xr > 1.0f)
xr = 1.0f;
if (xr < 0.0f)
xr = 0.0f;
////////////////////////////////////////////////////////////////////////////////////
r = xr * 255;
//printf("r %d xr %4.3f vdot %4.3f\n",r,xr,vdot);
//printf(" r %d dist %4.3f, pos %4.3f, %4.3f,%4.3f\n",r,dist,pos.X,pos.Y,pos.Z);
//printf(tt);
if (r > 255)
r = 255;
SColor nColor(r,r,r,r);
vertices[0].Color = nColor;
vertices[1].Color = nColor;
vertices[2].Color = nColor;
vertices[3].Color = nColor;
m_initTime = currentTime;
if (r < 20)
{
setVisible(false);
}
else
{
setVisible(true);
}
the code sample is part of a custom bill board that fades out as a function of distance from the viewer. Max visibility is at distance x, and the closer or farther from that distance the visibility of the billboard drops. Also drops if they rotate away from directly facing the billboard.
HTH