float ymax = min(max(0.0, center.y + dy), ymin + 2.0 * dy);
return (ymax – ymin) * 0.1;
}
void main() {
/* get vertex info */
vec4 info = texture2D(texture, coord);
/* add the old volume */
info.r += volumeInSphere(oldCenter);
/* subtract the new volume */
info.r -= volumeInSphere(newCenter);
gl_FragColor = info;
}
‘);
}
Water.prototype.addDrop = function(x, y, radius, strength) {
var this_ = this;
this.textureB.drawTo(function() {
this_.textureA.bind();
this_.dropShader.uniforms({
center: [x, y],
radius: radius,
strength: strength
}).draw(this_.plane);
});
this.textureB.swapWith(this.textureA);
};
Water.prototype.moveSphere = function(oldCenter, newCenter, radius) {
var this_ = this;
this.textureB.drawTo(function() {
this_.textureA.bind();
this_.sphereShader.uniforms({
oldCenter: oldCenter,
newCenter: newCenter,
radius: radius
}).draw(this_.plane);
});
this.textureB.swapWith(this.textureA);
};
Water.prototype.stepSimulation = function() {
var this_ = this;









