maxAge of particle is now halfAge and it lives for 5*halfAge time.
This commit is contained in:
parent
a6b9078c21
commit
3a30a20043
5 changed files with 17 additions and 15 deletions
|
@ -21,14 +21,15 @@ void main()
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
float d = decay/(1.0+max(0.0, 1.0-explCenterDist));
|
float d = decay/(1.0+max(0.0, 1.0-2.0*explCenterDist));
|
||||||
float h = (1.0-d)/6.0;
|
float h = (1.0-d)/6.0;
|
||||||
float v = max(0.0, (1.0-log(d)));
|
float v = max(0.0, (1.0-log(d)));
|
||||||
float s = 1.0;
|
float s = max(0.0, min(30.0 * sqrt(decay) * explCenterDist, 1.0));
|
||||||
|
|
||||||
//v /= decay * 10.0*length(vertex-explCenter);
|
//v /= decay * 10.0*length(vertex-explCenter);
|
||||||
//v /= 1.0+2.0*length(vertex-explCenter);
|
//v /= 1.0+2.0*length(vertex-explCenter);
|
||||||
v /= 1.0 + max(0.0, min(35.0*(decay-0.2), 1.0)) * 15.0 * explCenterDist;
|
//v /= 1.0 + max(0.0, min(35.0*(decay-0.2), 1.0)) + 10.0 * explCenterDist;
|
||||||
|
v /= 1.0 + 10.0 * explCenterDist;
|
||||||
|
|
||||||
gl_FragColor = vec4(hsv2rgb(vec3(h, s, v)), 1.0);
|
gl_FragColor = vec4(hsv2rgb(vec3(h, s, v)), 1.0);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ attribute vec3 in_velocity;
|
||||||
uniform float age;
|
uniform float age;
|
||||||
uniform float size;
|
uniform float size;
|
||||||
uniform float maxVelocity;
|
uniform float maxVelocity;
|
||||||
uniform float maxAge;
|
uniform float halfAge;
|
||||||
uniform vec3 explCenter;
|
uniform vec3 explCenter;
|
||||||
|
|
||||||
varying float decay;
|
varying float decay;
|
||||||
|
@ -17,15 +17,16 @@ varying float explCenterDist;
|
||||||
// TODO: rotate to face the user!
|
// TODO: rotate to face the user!
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
//decay = min(1.0, age+5.0*length(velocity)) / maxAge;
|
//decay = min(1.0, age+5.0*length(velocity)) / halfAge;
|
||||||
//decay = max(decay*decay, sqrt(decay));
|
//decay = max(decay*decay, sqrt(decay));
|
||||||
decay = age / maxAge;
|
decay = age / halfAge;
|
||||||
|
|
||||||
// faster particles are smaller
|
// faster particles are smaller
|
||||||
float s = size * (1.0-length(in_velocity)/maxVelocity);
|
//float s = size * (1.0-length(in_velocity)/maxVelocity);
|
||||||
|
float s = size;
|
||||||
vec2 base = in_vertex;
|
vec2 base = in_vertex;
|
||||||
vec3 p = s*vec3(base, 0.0);
|
vec3 p = s*vec3(base, 0.0);
|
||||||
vec3 offset = log(1.0+age) * in_velocity + in_position;
|
vec3 offset = (0.1*age + log(1.0+age*5.0)) * in_velocity + in_position;
|
||||||
p += offset;
|
p += offset;
|
||||||
|
|
||||||
gl_Position = vec4(p, 1.0);
|
gl_Position = vec4(p, 1.0);
|
||||||
|
|
|
@ -11,11 +11,11 @@ int getDivisorForIndex(int index)
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace endofthejedi {
|
namespace endofthejedi {
|
||||||
ParticleBatch::ParticleBatch(size_t id, size_t numParticles, float particleSize, float maxAge)
|
ParticleBatch::ParticleBatch(size_t id, size_t numParticles, float particleSize, float halfAge)
|
||||||
: m_id(id)
|
: m_id(id)
|
||||||
, m_numParticles(numParticles)
|
, m_numParticles(numParticles)
|
||||||
, m_particleRadius(particleSize)
|
, m_particleRadius(particleSize)
|
||||||
, m_maxAge(maxAge)
|
, m_halfAge(halfAge)
|
||||||
, m_age(0.0)
|
, m_age(0.0)
|
||||||
, m_maxVelocity(1.0)
|
, m_maxVelocity(1.0)
|
||||||
, m_center(glm::vec3(0.0f, 0.0f, 0.0f))
|
, m_center(glm::vec3(0.0f, 0.0f, 0.0f))
|
||||||
|
@ -137,7 +137,7 @@ namespace endofthejedi {
|
||||||
|
|
||||||
glUniform1f(m_shader.location("age"), m_age);
|
glUniform1f(m_shader.location("age"), m_age);
|
||||||
glUniform1f(m_shader.location("maxVelocity"), m_maxVelocity);
|
glUniform1f(m_shader.location("maxVelocity"), m_maxVelocity);
|
||||||
glUniform1f(m_shader.location("maxAge"), m_maxAge);
|
glUniform1f(m_shader.location("halfAge"), m_halfAge);
|
||||||
glUniform1f(m_shader.location("size"), m_particleRadius);
|
glUniform1f(m_shader.location("size"), m_particleRadius);
|
||||||
glUniform3f(m_shader.location("center"), m_center.x, m_center.y, m_center.z);
|
glUniform3f(m_shader.location("center"), m_center.x, m_center.y, m_center.z);
|
||||||
|
|
||||||
|
@ -206,6 +206,6 @@ namespace endofthejedi {
|
||||||
|
|
||||||
bool ParticleBatch::done() const
|
bool ParticleBatch::done() const
|
||||||
{
|
{
|
||||||
return m_age >= m_maxAge;
|
return m_age >= 5.0*m_halfAge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
namespace endofthejedi {
|
namespace endofthejedi {
|
||||||
class ParticleBatch {
|
class ParticleBatch {
|
||||||
public:
|
public:
|
||||||
ParticleBatch(size_t id, size_t numParticles, float particleRadius, float maxAge);
|
ParticleBatch(size_t id, size_t numParticles, float particleRadius, float halfAge);
|
||||||
|
|
||||||
// deallocate opengl stuff on destroy
|
// deallocate opengl stuff on destroy
|
||||||
~ParticleBatch();
|
~ParticleBatch();
|
||||||
|
@ -41,7 +41,7 @@ namespace endofthejedi {
|
||||||
size_t m_id;
|
size_t m_id;
|
||||||
size_t m_numParticles;
|
size_t m_numParticles;
|
||||||
float m_particleRadius;
|
float m_particleRadius;
|
||||||
const float m_maxAge;
|
const float m_halfAge;
|
||||||
float m_age;
|
float m_age;
|
||||||
float m_maxVelocity;
|
float m_maxVelocity;
|
||||||
glm::vec3 m_center;
|
glm::vec3 m_center;
|
||||||
|
|
|
@ -119,7 +119,7 @@ namespace endofthejedi {
|
||||||
//glm::vec3 v = 0.5f*glm::vec3(sin(t), cos(t), util::randf_m1_1());
|
//glm::vec3 v = 0.5f*glm::vec3(sin(t), cos(t), util::randf_m1_1());
|
||||||
|
|
||||||
glm::vec3 v = glm::ballRand(maxVelocity);
|
glm::vec3 v = glm::ballRand(maxVelocity);
|
||||||
v *= util::randf_0_1() + util::randf_0_1();
|
v *= util::randf_0_1() * util::randf_0_1();
|
||||||
|
|
||||||
batch->setParticle(i, glm::vec3(pos, 0.0) + glm::ballRand(explSize), v);
|
batch->setParticle(i, glm::vec3(pos, 0.0) + glm::ballRand(explSize), v);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue