Skip to content
Permalink
Browse files

add. 65dcf21

  • Loading branch information...
rt
rt committed Apr 24, 2019
1 parent 90a3a0f commit c616ebef66df81358801d58cf0c8d1295ea30650
Showing with 42 additions and 34 deletions.
  1. +42 −34 rts/Rendering/Env/Particles/Classes/SmokeTrailProjectile.cpp
@@ -79,17 +79,15 @@ void CSmokeTrailProjectile::UpdateEndPos(const float3 pos, const float3 dir)

const float dist = pos1.distance(pos2);

drawSegmented = false;
SetPosition((pos1 + pos2) * 0.5f);
SetRadiusAndHeight(dist, 0.0f);
sortDistOffset = 10.f + dist * 0.5f; // so that missile's engine flame gets rendered above the trail
sortDistOffset = 10.0f + dist * 0.5f; // so that missile's engine flame gets rendered above the trail

if (dir1.dot(dir2) < 0.98f) {
if ((drawSegmented = (dir1.dot(dir2) < 0.98f))) {
dirpos1 = pos1 - dir1 * dist * 0.33f;
dirpos2 = pos2 + dir2 * dist * 0.33f;
midpos = CalcBeizer(0.5f, pos1, dirpos1, dirpos2, pos2);
middir = (dir1 + dir2).ANormalize();
drawSegmented = true;
}
}

@@ -104,46 +102,56 @@ void CSmokeTrailProjectile::Draw(GL::RenderDataBufferTC* va) const
const float3 odir1 = (dif1.cross(dir1)).ANormalize();
const float3 odir2 = (dif2.cross(dir2)).ANormalize();

const SColor colBase(color, color, color, 1.0f);
const float t1 = (age ) * invLifeTime;
const float t3 = (age + 4) * invLifeTime;
const float t2 = (age + 8) * invLifeTime;

const float a1 = ((1.0f - age * invLifeTime) * (0.7f + std::fabs(dif1.dot(dir1)))) * (1 - lastSegment);
const float a2 = ((1.0f - (age + 8) * invLifeTime) * (0.7f + std::fabs(dif2.dot(dir2)))) * (1 - firstSegment);
const float lerp1 = ((1.0f - t1) * (0.7f + std::fabs(dif1.dot(dir1)))) * (1 - lastSegment);
const float lerp2 = ((1.0f - t2) * (0.7f + std::fabs(dif2.dot(dir2)))) * (1 - firstSegment);

const float alpha1 = Clamp(a1, 0.0f, 1.0f);
const SColor col = colBase * alpha1;
const float size1 = 1.0f + t1 * orgSize;
const float size2 = 1.0f + t2 * orgSize;

const float alpha2 = Clamp(a2, 0.0f, 1.0f);
const SColor col2 = colBase * alpha2;

const float size = 1 + ( age * invLifeTime) * orgSize;
const float size2 = 1 + ((age + 8) * invLifeTime) * orgSize;
const SColor colBase = {color, color, color, 1.0f};
const SColor col1 = colBase * Clamp(lerp1, 0.0f, 1.0f);
const SColor col2 = colBase * Clamp(lerp2, 0.0f, 1.0f);

if (drawSegmented) {
const float t = (age + 4) * invLifeTime;
const float3 dif3 = (midpos - camera->GetPos()).ANormalize();
const float3 dif3 = (midpos - camera->GetPos()).ANormalize();
const float3 odir3 = (dif3.cross(middir)).ANormalize();
const float size3 = (0.2f + t) * orgSize;

const float a2 = (1.0f - t) * (0.7f + std::fabs(dif3.dot(middir)));
const float alpha = Clamp(a2, 0.0f, 1.0f);
const SColor col3 = colBase * alpha;

const float lerp3 = (1.0f - t3) * (0.7f + std::fabs(dif3.dot(middir)));
const float size3 = (0.2f + t3) * orgSize;
const float midtexx = mix(texture->xstart, texture->xend, 0.5f);

va->SafeAppend({pos1 - (odir1 * size), texture->xstart, texture->ystart, col });
va->SafeAppend({pos1 + (odir1 * size), texture->xstart, texture->yend, col });
va->SafeAppend({midpos + (odir3 * size3), midtexx, texture->yend, col3});
va->SafeAppend({midpos - (odir3 * size3), midtexx, texture->ystart, col3});

va->SafeAppend({midpos - (odir3 * size3), midtexx, texture->ystart, col3});
va->SafeAppend({midpos + (odir3 * size3), midtexx, texture->yend, col3});
va->SafeAppend({pos2 + (odir2 * size2), texture->xend, texture->yend, col2});
va->SafeAppend({pos2 - (odir2 * size2), texture->xend, texture->ystart, col2});
const SColor col3 = colBase * Clamp(lerp3, 0.0f, 1.0f);

{
va->SafeAppend({pos1 - (odir1 * size1), texture->xstart, texture->ystart, col1});
va->SafeAppend({pos1 + (odir1 * size1), texture->xstart, texture->yend, col1});
va->SafeAppend({midpos + (odir3 * size3), midtexx, texture->yend, col3});

va->SafeAppend({midpos + (odir3 * size3), midtexx, texture->yend, col3});
va->SafeAppend({midpos - (odir3 * size3), midtexx, texture->ystart, col3});
va->SafeAppend({pos1 - (odir1 * size1), texture->xstart, texture->ystart, col1});
}
{
va->SafeAppend({midpos - (odir3 * size3), midtexx, texture->ystart, col3});
va->SafeAppend({midpos + (odir3 * size3), midtexx, texture->yend, col3});
va->SafeAppend({pos2 + (odir2 * size2), texture->xend, texture->yend, col2});

va->SafeAppend({pos2 + (odir2 * size2), texture->xend, texture->yend, col2});
va->SafeAppend({pos2 - (odir2 * size2), texture->xend, texture->ystart, col2});
va->SafeAppend({midpos - (odir3 * size3), midtexx, texture->ystart, col3});
}
} else {
va->SafeAppend({pos1 - (odir1 * size), texture->xstart, texture->ystart, col });
va->SafeAppend({pos1 + (odir1 * size), texture->xstart, texture->yend, col });
va->SafeAppend({pos2 + (odir2 * size2), texture->xend, texture->yend, col2});
va->SafeAppend({pos2 - (odir2 * size2), texture->xend, texture->ystart, col2});
va->SafeAppend({pos1 - (odir1 * size1), texture->xstart, texture->ystart, col1});
va->SafeAppend({pos1 + (odir1 * size1), texture->xstart, texture->yend, col1});
va->SafeAppend({pos2 + (odir2 * size2), texture->xend, texture->yend, col2});

va->SafeAppend({pos2 + (odir2 * size2), texture->xend, texture->yend, col2});
va->SafeAppend({pos2 - (odir2 * size2), texture->xend, texture->ystart, col2});
va->SafeAppend({pos1 - (odir1 * size1), texture->xstart, texture->ystart, col1});
}
}

0 comments on commit c616ebe

Please sign in to comment.
You can’t perform that action at this time.