Skip to content

Commit

Permalink
Traktor: Removed per-particle color value.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Jan 9, 2024
1 parent ad99455 commit 5425d6d
Show file tree
Hide file tree
Showing 52 changed files with 654 additions and 1,155 deletions.
3 changes: 1 addition & 2 deletions code/Spray/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ struct T_MATH_ALIGN16 Point
{
Vector4 position;
Vector4 velocity;
Vector4 color; // 48
float orientation;
float angularVelocity;
float inverseMass;
float age;
float maxAge;
float size;
float random; // 28
float random;
};

/*! Array of particles.
Expand Down
7 changes: 3 additions & 4 deletions code/Spray/PointRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,11 @@ void PointRenderer::render(
// \note We're assuming locked vertex buffer is 16-aligned.
position.storeAligned(m_point->positionAndOrientation);
point.velocity.storeAligned(m_point->velocityAndRandom);
point.color.storeAligned(m_point->colorAndAge);
m_point->positionAndOrientation[3] = point.orientation;
m_point->velocityAndRandom[3] = point.random;
m_point->alphaAndSize[0] = alpha;
m_point->alphaAndSize[1] = point.size;
m_point->colorAndAge[3] = age;
m_point->alphaSizeAge[0] = alpha;
m_point->alphaSizeAge[1] = point.size;
m_point->alphaSizeAge[2] = age;
m_point++;

back.distance = min(back.distance, distance);
Expand Down
12 changes: 4 additions & 8 deletions code/Spray/Sources/BoxSource.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,10 +10,8 @@
#include "Spray/Types.h"
#include "Spray/Sources/BoxSource.h"

namespace traktor
namespace traktor::spray
{
namespace spray
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.spray.BoxSource", BoxSource, Source)

Expand Down Expand Up @@ -49,19 +47,18 @@ void BoxSource::emit(
EmitterInstance& emitterInstance
) const
{
Vector4 position = transform * m_position - m_extent * Scalar(0.5f);
const Vector4 position = transform * m_position - m_extent * 0.5_simd;

Point* point = emitterInstance.addPoints(emitCount);

while (emitCount-- > 0)
{
Vector4 direction = context.random.nextUnit();
const Vector4 direction = context.random.nextUnit();

point->position = position + m_extent * Vector4(context.random.nextFloat(), context.random.nextFloat(), context.random.nextFloat(), 0.0f);
point->velocity = direction * Scalar(m_velocity.random(context.random));
point->orientation = m_orientation.random(context.random);
point->angularVelocity = m_angularVelocity.random(context.random);
point->color = Vector4::one();
point->age = 0.0f;
point->maxAge = m_age.random(context.random);
point->inverseMass = 1.0f / (m_mass.random(context.random));
Expand All @@ -72,5 +69,4 @@ void BoxSource::emit(
}
}

}
}
10 changes: 3 additions & 7 deletions code/Spray/Sources/BoxSource.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -20,10 +20,8 @@
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor
namespace traktor::spray
{
namespace spray
{

/*! Box particle source.
* \ingroup Spray
Expand All @@ -33,7 +31,7 @@ class T_DLLCLASS BoxSource : public Source
T_RTTI_CLASS;

public:
BoxSource(
explicit BoxSource(
float constantRate,
float velocityRate,
const Vector4& position,
Expand Down Expand Up @@ -69,6 +67,4 @@ class T_DLLCLASS BoxSource : public Source
Range< float > m_size;
};

}
}

7 changes: 2 additions & 5 deletions code/Spray/Sources/BoxSourceData.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -14,10 +14,8 @@
#include "Spray/Sources/BoxSource.h"
#include "Spray/Sources/BoxSourceData.h"

namespace traktor
namespace traktor::spray
{
namespace spray
{

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.spray.BoxSourceData", 0, BoxSourceData, SourceData)

Expand Down Expand Up @@ -64,5 +62,4 @@ void BoxSourceData::serialize(ISerializer& s)
s >> MemberComposite< Range< float > >(L"size", m_size);
}

}
}
8 changes: 2 additions & 6 deletions code/Spray/Sources/BoxSourceData.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -20,10 +20,8 @@
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor
namespace traktor::spray
{
namespace spray
{

/*! Box particle source persistent data.
* \ingroup Spray
Expand Down Expand Up @@ -52,6 +50,4 @@ class T_DLLCLASS BoxSourceData : public SourceData
Range< float > m_size;
};

}
}

38 changes: 17 additions & 21 deletions code/Spray/Sources/ConeSource.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,10 +10,8 @@
#include "Spray/Types.h"
#include "Spray/Sources/ConeSource.h"

namespace traktor
namespace traktor::spray
{
namespace spray
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.spray.ConeSource", ConeSource, Source)

Expand Down Expand Up @@ -55,38 +53,37 @@ void ConeSource::emit(
EmitterInstance& emitterInstance
) const
{
Vector4 position = transform * m_position;
Vector4 normal = transform * m_normal;
const Vector4 position = transform * m_position;
const Vector4 normal = transform * m_normal;

Scalar dT(context.deltaTime);
const Scalar dT(context.deltaTime);

Vector4 deltaVelocity = -deltaMotion / dT;
const Vector4 deltaVelocity = -deltaMotion / dT;

Vector4 tx = transform.axisX() * m_angle1s;
Vector4 tz = transform.axisZ() * m_angle2s;
const Vector4 tx = transform.axisX() * m_angle1s;
const Vector4 tz = transform.axisZ() * m_angle2s;

Point* point = emitterInstance.addPoints(emitCount);
while (emitCount-- > 0)
{
float phi = context.random.nextFloat() * 2.0f * PI;
const float phi = context.random.nextFloat() * 2.0f * PI;

Scalar gamma(context.random.nextFloat());
Scalar beta(context.random.nextFloat());
const Scalar gamma(context.random.nextFloat());
const Scalar beta(context.random.nextFloat());

Scalar x(traktor::sinf(phi + HALF_PI));
Scalar z(traktor::sinf(phi));
const Scalar x(traktor::sinf(phi + HALF_PI));
const Scalar z(traktor::sinf(phi));

Vector4 ax = tx * x;
Vector4 az = tz * z;
const Vector4 ax = tx * x;
const Vector4 az = tz * z;

Vector4 extent = ax + az;
Vector4 direction = (normal + extent * gamma).normalized();
const Vector4 extent = ax + az;
const Vector4 direction = (normal + extent * gamma).normalized();

point->velocity = direction * Scalar(m_velocity.random(context.random)) + deltaVelocity * Scalar(m_inheritVelocity.random(context.random));
point->position = position + point->velocity * beta * dT;
point->orientation = m_orientation.random(context.random);
point->angularVelocity = m_angularVelocity.random(context.random);
point->color = Vector4::one();
point->age = beta;
point->maxAge = m_age.random(context.random);
point->inverseMass = 1.0f / m_mass.random(context.random);
Expand All @@ -97,5 +94,4 @@ void ConeSource::emit(
}
}

}
}
10 changes: 3 additions & 7 deletions code/Spray/Sources/ConeSource.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -20,10 +20,8 @@
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor
namespace traktor::spray
{
namespace spray
{

/*! Cone particle source.
* \ingroup Spray
Expand All @@ -33,7 +31,7 @@ class T_DLLCLASS ConeSource : public Source
T_RTTI_CLASS;

public:
ConeSource(
explicit ConeSource(
float constantRate,
float velocityRate,
const Vector4& position,
Expand Down Expand Up @@ -79,6 +77,4 @@ class T_DLLCLASS ConeSource : public Source
Range< float > m_size;
};

}
}

7 changes: 2 additions & 5 deletions code/Spray/Sources/ConeSourceData.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -16,10 +16,8 @@
#include "Spray/Sources/ConeSource.h"
#include "Spray/Sources/ConeSourceData.h"

namespace traktor
namespace traktor::spray
{
namespace spray
{

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.spray.ConeSourceData", 1, ConeSourceData, SourceData)

Expand Down Expand Up @@ -78,5 +76,4 @@ void ConeSourceData::serialize(ISerializer& s)
s >> MemberComposite< Range< float > >(L"size", m_size);
}

}
}
8 changes: 2 additions & 6 deletions code/Spray/Sources/ConeSourceData.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -20,10 +20,8 @@
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor
namespace traktor::spray
{
namespace spray
{

/*! Cone particle source persistent data.
* \ingroup Spray
Expand Down Expand Up @@ -55,6 +53,4 @@ class T_DLLCLASS ConeSourceData : public SourceData
Range< float > m_size;
};

}
}

12 changes: 4 additions & 8 deletions code/Spray/Sources/DirectionalPointSource.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,10 +10,8 @@
#include "Spray/Types.h"
#include "Spray/Sources/DirectionalPointSource.h"

namespace traktor
namespace traktor::spray
{
namespace spray
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.spray.DirectionalPointSource", DirectionalPointSource, Source)

Expand Down Expand Up @@ -49,8 +47,8 @@ void DirectionalPointSource::emit(
EmitterInstance& emitterInstance
) const
{
Vector4 position = transform * m_position;
Vector4 direction = transform * m_direction;
const Vector4 position = transform * m_position;
const Vector4 direction = transform * m_direction;

Point* point = emitterInstance.addPoints(emitCount);

Expand All @@ -60,7 +58,6 @@ void DirectionalPointSource::emit(
point->velocity = direction * Scalar(m_velocity.random(context.random));
point->orientation = m_orientation.random(context.random);
point->angularVelocity = m_angularVelocity.random(context.random);
point->color = Vector4::one();
point->age = 0.0f;
point->maxAge = m_age.random(context.random);
point->inverseMass = 1.0f / (m_mass.random(context.random));
Expand All @@ -71,5 +68,4 @@ void DirectionalPointSource::emit(
}
}

}
}
Loading

0 comments on commit 5425d6d

Please sign in to comment.