@awayjs/graphics
Version:
AwayJS graphics classes
147 lines (146 loc) • 8.32 kB
JavaScript
import { __extends } from "tslib";
import { ShaderRegisterElement } from '@awayjs/stage';
import { ParticlePropertiesMode } from '../data/ParticlePropertiesMode';
import { ParticleSegmentedColorState } from '../states/ParticleSegmentedColorState';
import { ParticleAnimationSet } from '../ParticleAnimationSet';
import { ParticleNodeBase } from './ParticleNodeBase';
/**
*
*/
var ParticleSegmentedColorNode = /** @class */ (function (_super) {
__extends(ParticleSegmentedColorNode, _super);
function ParticleSegmentedColorNode(usesMultiplier, usesOffset, numSegmentPoint, startColor, endColor, segmentPoints) {
var _this =
//because of the stage3d register limitation, it only support the global mode
_super.call(this, 'ParticleSegmentedColor', ParticlePropertiesMode.GLOBAL, 0, ParticleAnimationSet.COLOR_PRIORITY) || this;
_this._pStateClass = ParticleSegmentedColorState;
if (numSegmentPoint > 4)
throw (new Error('the numSegmentPoint must be less or equal 4'));
_this._iUsesMultiplier = usesMultiplier;
_this._iUsesOffset = usesOffset;
_this._iNumSegmentPoint = numSegmentPoint;
_this._iStartColor = startColor;
_this._iEndColor = endColor;
_this._iSegmentPoints = segmentPoints;
return _this;
}
/**
* @inheritDoc
*/
ParticleSegmentedColorNode.prototype._iProcessAnimationSetting = function (particleAnimationSet) {
if (this._iUsesMultiplier)
particleAnimationSet.hasColorMulNode = true;
if (this._iUsesOffset)
particleAnimationSet.hasColorAddNode = true;
};
/**
* @inheritDoc
*/
ParticleSegmentedColorNode.prototype.getAGALVertexCode = function (shader, animationSet, registerCache, animationRegisterData) {
var code = '';
if (shader.usesFragmentAnimation) {
var accMultiplierColor = void 0;
//var accOffsetColor:ShaderRegisterElement;
if (this._iUsesMultiplier) {
accMultiplierColor = registerCache.getFreeVertexVectorTemp();
registerCache.addVertexTempUsages(accMultiplierColor, 1);
}
var tempColor = registerCache.getFreeVertexVectorTemp();
registerCache.addVertexTempUsages(tempColor, 1);
var temp = registerCache.getFreeVertexVectorTemp();
var accTime = new ShaderRegisterElement(temp.regName, temp.index, 0);
var tempTime = new ShaderRegisterElement(temp.regName, temp.index, 1);
if (this._iUsesMultiplier)
registerCache.removeVertexTempUsage(accMultiplierColor);
registerCache.removeVertexTempUsage(tempColor);
//for saving all the life values (at most 4)
var lifeTimeRegister = registerCache.getFreeVertexConstant();
animationRegisterData.setRegisterIndex(this, ParticleSegmentedColorState.TIME_DATA_INDEX, lifeTimeRegister.index);
var i = void 0;
var startMulValue = void 0;
var deltaMulValues = void 0;
if (this._iUsesMultiplier) {
startMulValue = registerCache.getFreeVertexConstant();
animationRegisterData.setRegisterIndex(this, ParticleSegmentedColorState.START_MULTIPLIER_INDEX, startMulValue.index);
deltaMulValues = new Array();
for (i = 0; i < this._iNumSegmentPoint + 1; i++)
deltaMulValues.push(registerCache.getFreeVertexConstant());
}
var startOffsetValue = void 0;
var deltaOffsetValues = void 0;
if (this._iUsesOffset) {
startOffsetValue = registerCache.getFreeVertexConstant();
animationRegisterData.setRegisterIndex(this, ParticleSegmentedColorState.START_OFFSET_INDEX, startOffsetValue.index);
deltaOffsetValues = new Array();
for (i = 0; i < this._iNumSegmentPoint + 1; i++)
deltaOffsetValues.push(registerCache.getFreeVertexConstant());
}
if (this._iUsesMultiplier)
code += 'mov ' + accMultiplierColor + ',' + startMulValue + '\n';
if (this._iUsesOffset)
code += 'add ' + animationRegisterData.colorAddTarget + ',' + animationRegisterData.colorAddTarget + ',' + startOffsetValue + '\n';
for (i = 0; i < this._iNumSegmentPoint; i++) {
switch (i) {
case 0:
code += 'min ' + tempTime + ',' + animationRegisterData.vertexLife + ',' + lifeTimeRegister + '.x\n';
break;
case 1:
code += 'sub ' + accTime + ',' + animationRegisterData.vertexLife + ',' + lifeTimeRegister + '.x\n';
code += 'max ' + tempTime + ',' + accTime + ',' + animationRegisterData.vertexZeroConst + '\n';
code += 'min ' + tempTime + ',' + tempTime + ',' + lifeTimeRegister + '.y\n';
break;
case 2:
code += 'sub ' + accTime + ',' + accTime + ',' + lifeTimeRegister + '.y\n';
code += 'max ' + tempTime + ',' + accTime + ',' + animationRegisterData.vertexZeroConst + '\n';
code += 'min ' + tempTime + ',' + tempTime + ',' + lifeTimeRegister + '.z\n';
break;
case 3:
code += 'sub ' + accTime + ',' + accTime + ',' + lifeTimeRegister + '.z\n';
code += 'max ' + tempTime + ',' + accTime + ',' + animationRegisterData.vertexZeroConst + '\n';
code += 'min ' + tempTime + ',' + tempTime + ',' + lifeTimeRegister + '.w\n';
break;
}
if (this._iUsesMultiplier) {
code += 'mul ' + tempColor + ',' + tempTime + ',' + deltaMulValues[i] + '\n';
code += 'add ' + accMultiplierColor + ',' + accMultiplierColor + ',' + tempColor + '\n';
}
if (this._iUsesOffset) {
code += 'mul ' + tempColor + ',' + tempTime + ',' + deltaOffsetValues[i] + '\n';
code += 'add ' + animationRegisterData.colorAddTarget + ',' + animationRegisterData.colorAddTarget + ',' + tempColor + '\n';
}
}
//for the last segment:
if (this._iNumSegmentPoint == 0)
tempTime = animationRegisterData.vertexLife;
else {
switch (this._iNumSegmentPoint) {
case 1:
code += 'sub ' + accTime + ',' + animationRegisterData.vertexLife + ',' + lifeTimeRegister + '.x\n';
break;
case 2:
code += 'sub ' + accTime + ',' + accTime + ',' + lifeTimeRegister + '.y\n';
break;
case 3:
code += 'sub ' + accTime + ',' + accTime + ',' + lifeTimeRegister + '.z\n';
break;
case 4:
code += 'sub ' + accTime + ',' + accTime + ',' + lifeTimeRegister + '.w\n';
break;
}
code += 'max ' + tempTime + ',' + accTime + ',' + animationRegisterData.vertexZeroConst + '\n';
}
if (this._iUsesMultiplier) {
code += 'mul ' + tempColor + ',' + tempTime + ',' + deltaMulValues[this._iNumSegmentPoint] + '\n';
code += 'add ' + accMultiplierColor + ',' + accMultiplierColor + ',' + tempColor + '\n';
code += 'mul ' + animationRegisterData.colorMulTarget + ',' + animationRegisterData.colorMulTarget + ',' + accMultiplierColor + '\n';
}
if (this._iUsesOffset) {
code += 'mul ' + tempColor + ',' + tempTime + ',' + deltaOffsetValues[this._iNumSegmentPoint] + '\n';
code += 'add ' + animationRegisterData.colorAddTarget + ',' + animationRegisterData.colorAddTarget + ',' + tempColor + '\n';
}
}
return code;
};
return ParticleSegmentedColorNode;
}(ParticleNodeBase));
export { ParticleSegmentedColorNode };