|
@@ -8931,6 +8931,14 @@ var BABYLON;
|
|
|
this._gl.disable(this._gl.DITHER);
|
|
|
}
|
|
|
};
|
|
|
+ Engine.prototype.setRasterizerState = function (value) {
|
|
|
+ if (value) {
|
|
|
+ this._gl.disable(this._gl.RASTERIZER_DISCARD);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this._gl.enable(this._gl.RASTERIZER_DISCARD);
|
|
|
+ }
|
|
|
+ };
|
|
|
/**
|
|
|
* stop executing a render loop function and remove it from the execution array
|
|
|
* @param {Function} [renderFunction] the function to be removed. If not provided all functions will be removed.
|
|
@@ -12105,8 +12113,9 @@ var BABYLON;
|
|
|
Engine.prototype.bindTransformFeedback = function (value) {
|
|
|
this._gl.bindTransformFeedback(this._gl.TRANSFORM_FEEDBACK, value);
|
|
|
};
|
|
|
- Engine.prototype.beginTransformFeedback = function () {
|
|
|
- this._gl.beginTransformFeedback(this._gl.TRIANGLES);
|
|
|
+ Engine.prototype.beginTransformFeedback = function (usePoints) {
|
|
|
+ if (usePoints === void 0) { usePoints = true; }
|
|
|
+ this._gl.beginTransformFeedback(usePoints ? this._gl.POINTS : this._gl.TRIANGLES);
|
|
|
};
|
|
|
Engine.prototype.endTransformFeedback = function () {
|
|
|
this._gl.endTransformFeedback();
|
|
@@ -12114,6 +12123,9 @@ var BABYLON;
|
|
|
Engine.prototype.setTranformFeedbackVaryings = function (program, value) {
|
|
|
this._gl.transformFeedbackVaryings(program, value, this._gl.INTERLEAVED_ATTRIBS);
|
|
|
};
|
|
|
+ Engine.prototype.bindTransformFeedbackBuffer = function (value) {
|
|
|
+ this._gl.bindBufferBase(this._gl.TRANSFORM_FEEDBACK_BUFFER, 0, value);
|
|
|
+ };
|
|
|
// Statics
|
|
|
Engine.isSupported = function () {
|
|
|
try {
|
|
@@ -22193,6 +22205,8 @@ var BABYLON;
|
|
|
}
|
|
|
if (!this._cachedTextureMatrix) {
|
|
|
this._cachedTextureMatrix = BABYLON.Matrix.Zero();
|
|
|
+ }
|
|
|
+ if (!this._projectionModeMatrix) {
|
|
|
this._projectionModeMatrix = BABYLON.Matrix.Zero();
|
|
|
}
|
|
|
this._cachedUOffset = this.uOffset;
|
|
@@ -44865,7 +44879,11 @@ var BABYLON;
|
|
|
this.name = name;
|
|
|
this.emitter = null;
|
|
|
this.renderingGroupId = 0;
|
|
|
- this.layerMask = 0x0FFFFFFF;
|
|
|
+ this.layerMask = 0x0FFFFFFF; // TODO
|
|
|
+ this._updateVertexBuffers = {};
|
|
|
+ this._renderVertexBuffers = {};
|
|
|
+ this._currentRenderId = -1;
|
|
|
+ this._started = true;
|
|
|
/**
|
|
|
* An event triggered when the system is disposed.
|
|
|
* @type {BABYLON.Observable}
|
|
@@ -44873,8 +44891,10 @@ var BABYLON;
|
|
|
this.onDisposeObservable = new BABYLON.Observable();
|
|
|
this.id = name;
|
|
|
this._scene = scene || BABYLON.Engine.LastCreatedScene;
|
|
|
+ this._capacity = capacity;
|
|
|
+ this._engine = this._scene.getEngine();
|
|
|
this._scene.particleSystems.push(this);
|
|
|
- this._renderingEffect = new BABYLON.Effect("gpuRenderParticles", ["position", "age", "life", "velocity"], [], [], this._scene.getEngine());
|
|
|
+ this._renderEffect = new BABYLON.Effect("gpuRenderParticles", ["position", "age", "life", "velocity"], [], [], this._scene.getEngine());
|
|
|
var updateEffectOptions = {
|
|
|
attributes: ["position", "age", "life", "velocity"],
|
|
|
uniformsNames: [],
|
|
@@ -44891,11 +44911,94 @@ var BABYLON;
|
|
|
this._updateEffect = new BABYLON.Effect("gpuUpdateParticles", updateEffectOptions, this._scene.getEngine());
|
|
|
}
|
|
|
GPUParticleSystem.prototype.isStarted = function () {
|
|
|
- return false;
|
|
|
+ return this._started;
|
|
|
+ };
|
|
|
+ GPUParticleSystem.prototype.start = function () {
|
|
|
+ this._started = true;
|
|
|
+ };
|
|
|
+ GPUParticleSystem.prototype.stop = function () {
|
|
|
+ this._started = false;
|
|
|
};
|
|
|
GPUParticleSystem.prototype.animate = function () {
|
|
|
+ // Do nothing
|
|
|
+ };
|
|
|
+ GPUParticleSystem.prototype._initialize = function () {
|
|
|
+ if (this._renderVAO) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var data = new Array();
|
|
|
+ for (var particleIndex = 0; particleIndex < this._capacity; particleIndex++) {
|
|
|
+ // position
|
|
|
+ data.push(0.0);
|
|
|
+ data.push(0.0);
|
|
|
+ data.push(0.0);
|
|
|
+ var life = 1 + Math.random() * 10; // TODO: var
|
|
|
+ data.push(life + 1); // create the particle as a dead one to create a new one at start
|
|
|
+ data.push(life);
|
|
|
+ // velocity
|
|
|
+ data.push(0.0);
|
|
|
+ data.push(0.0);
|
|
|
+ data.push(0.0);
|
|
|
+ }
|
|
|
+ // Update VAO
|
|
|
+ this._updateBuffer = new BABYLON.Buffer(this._scene.getEngine(), data, false, 0);
|
|
|
+ this._updateVertexBuffers["position"] = this._updateBuffer.createVertexBuffer("position", 0, 3, 3);
|
|
|
+ this._updateVertexBuffers["age"] = this._updateBuffer.createVertexBuffer("age", 3, 1, 1);
|
|
|
+ this._updateVertexBuffers["life"] = this._updateBuffer.createVertexBuffer("life", 4, 1, 1);
|
|
|
+ this._updateVertexBuffers["velocity"] = this._updateBuffer.createVertexBuffer("velocity", 5, 3, 3);
|
|
|
+ this._updateVAO = this._engine.recordVertexArrayObject(this._updateVertexBuffers, null, this._updateEffect);
|
|
|
+ this._engine.bindArrayBuffer(null);
|
|
|
+ // Render VAO
|
|
|
+ this._renderBuffer = new BABYLON.Buffer(this._scene.getEngine(), data, false, 0);
|
|
|
+ this._renderVertexBuffers["position"] = this._renderBuffer.createVertexBuffer("position", 0, 3, 3);
|
|
|
+ this._renderVertexBuffers["age"] = this._renderBuffer.createVertexBuffer("age", 3, 1, 1);
|
|
|
+ this._renderVertexBuffers["life"] = this._renderBuffer.createVertexBuffer("life", 4, 1, 1);
|
|
|
+ this._renderVertexBuffers["velocity"] = this._renderBuffer.createVertexBuffer("velocity", 5, 3, 3);
|
|
|
+ this._renderVAO = this._engine.recordVertexArrayObject(this._renderVertexBuffers, null, this._renderEffect);
|
|
|
+ this._engine.bindArrayBuffer(null);
|
|
|
+ // Links
|
|
|
+ this._sourceVAO = this._updateVAO;
|
|
|
+ this._targetVAO = this._renderVAO;
|
|
|
+ this._sourceBuffer = this._updateBuffer;
|
|
|
+ this._targetBuffer = this._renderBuffer;
|
|
|
};
|
|
|
GPUParticleSystem.prototype.render = function () {
|
|
|
+ if (!this.emitter || !this._updateEffect.isReady() || !this._renderEffect.isReady()) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ // Get everything ready to render
|
|
|
+ this._initialize();
|
|
|
+ if (this._currentRenderId === this._scene.getRenderId()) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ this._currentRenderId = this._scene.getRenderId();
|
|
|
+ // Enable update effect
|
|
|
+ this._engine.enableEffect(this._updateEffect);
|
|
|
+ this._engine.setState(false);
|
|
|
+ // Bind source VAO
|
|
|
+ this._engine.bindVertexArrayObject(this._sourceVAO, null);
|
|
|
+ // Update
|
|
|
+ this._engine.bindTransformFeedbackBuffer(this._targetBuffer.getBuffer());
|
|
|
+ this._engine.setRasterizerState(false);
|
|
|
+ this._engine.beginTransformFeedback();
|
|
|
+ this._engine.drawPointClouds(0, this._capacity);
|
|
|
+ this._engine.endTransformFeedback();
|
|
|
+ this._engine.setRasterizerState(true);
|
|
|
+ this._engine.bindTransformFeedbackBuffer(null);
|
|
|
+ // Enable render effect
|
|
|
+ this._engine.enableEffect(this._renderEffect);
|
|
|
+ // Bind source VAO
|
|
|
+ this._engine.bindVertexArrayObject(this._targetVAO, null);
|
|
|
+ // Render
|
|
|
+ this._engine.drawPointClouds(0, this._capacity);
|
|
|
+ // Switch VAOs
|
|
|
+ var tmpVAO = this._sourceVAO;
|
|
|
+ this._sourceVAO = this._targetVAO;
|
|
|
+ this._targetVAO = tmpVAO;
|
|
|
+ // Switch buffers
|
|
|
+ var tmpBuffer = this._sourceBuffer;
|
|
|
+ this._sourceBuffer = this._targetBuffer;
|
|
|
+ this._targetBuffer = tmpBuffer;
|
|
|
return 0;
|
|
|
};
|
|
|
GPUParticleSystem.prototype.rebuild = function () {
|
|
@@ -44905,6 +45008,7 @@ var BABYLON;
|
|
|
if (index > -1) {
|
|
|
this._scene.particleSystems.splice(index, 1);
|
|
|
}
|
|
|
+ //TODO: this._dataBuffer.dispose();
|
|
|
// Callback
|
|
|
this.onDisposeObservable.notifyObservers(this);
|
|
|
this.onDisposeObservable.clear();
|