Skip to content

Commit

Permalink
visual tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
ondras committed Jan 4, 2015
1 parent 993566a commit 96c64ab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
14 changes: 12 additions & 2 deletions js/explosion.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@ var Explosion = function(gl, force) {

var r = Math.random();
switch (true) {
case (r > 0.7):
this._buildSet("sphere", force, 0.5);
this._buildSet("sphere", force, 0.5);
break;

case (r > 0.4):
this._buildSet("sphere", force);
break;

case (r > 0.35):
this._buildSet("circle", force, 0.5);
this._buildSet("circle", force, 0.5);
break;

case (r > 0.3):
this._buildSet("circle", force);
break;
Expand Down Expand Up @@ -82,10 +92,10 @@ Explosion.prototype.render = function(program, now, vMatrix) {
return true;
}

Explosion.prototype._buildSet = function(type, force) {
Explosion.prototype._buildSet = function(type, force, amount) {
var color = vec3.create();
color[0] = 0.4 + 0.6*Math.random();
color[1] = 0.3 + 0.6*Math.random();
color[2] = 0.2 + 0.6*Math.random();
this._particleSets.push(new ParticleSet(this._gl, type, force, color));
this._particleSets.push(new ParticleSet(this._gl, type, force, color, amount));
}
8 changes: 4 additions & 4 deletions js/particleset.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var ParticleSet = function(gl, type, force, color) {
var ParticleSet = function(gl, type, force, color, amount) {
this._gl = gl;
this._buffers = {
velocity: gl.createBuffer()
}

this._color = color;
this._build(type, force);
this._build(type, force, amount);
}

ParticleSet.prototype.destroy = function() {
Expand All @@ -15,10 +15,10 @@ ParticleSet.prototype.destroy = function() {
this._buffers = {};
}

ParticleSet.prototype._build = function(type, force) {
ParticleSet.prototype._build = function(type, force, amount) {
var gl = this._gl;
var buffers = this._buffers;
this._count = (type == "sphere" ? 1000 : 200);
this._count = Math.round((type == "sphere" ? 1000 : 200) * (amount || 1));

var tmp3 = vec3.create();
var tmp2 = vec2.create();
Expand Down
4 changes: 2 additions & 2 deletions shaders/particleset.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ varying float vLifetime;
void main(void) {
float age = float(uCurrentTime - uStartTime);

vec3 position = log(1.0+age * 0.1) * aVelocity
vec3 position = log(1.0+age * 0.02) * aVelocity
+ 0.5 * age * age * uGravity;

vec4 cameraPosition = uModelView * vec4(position, 1.0);
gl_Position = uProjection * cameraPosition;

float distanceSquared = abs(dot(cameraPosition, cameraPosition));
distanceSquared = clamp(distanceSquared, 1.0, 10000.0);
gl_PointSize = 6.0 + 1000.0 / distanceSquared;
gl_PointSize = 7.0 + 1000.0 / distanceSquared;

vLifetime = 1.0 - (age / uLifetime);
vColor = uColor;
Expand Down

0 comments on commit 96c64ab

Please sign in to comment.