ami-cjs.js
Version:
<p align="center"> <img src="https://cloud.githubusercontent.com/assets/214063/23213764/78ade038-f90c-11e6-8208-4fcade5f3832.png" width="60%"> </p>
67 lines (50 loc) • 4.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _shaders = require('../shaders.base');
var _shaders2 = _interopRequireDefault(_shaders);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Texture3d = function (_ShadersBase) {
_inherits(Texture3d, _ShadersBase);
function Texture3d() {
_classCallCheck(this, Texture3d);
var _this = _possibleConstructorReturn(this, (Texture3d.__proto__ || Object.getPrototypeOf(Texture3d)).call(this));
_this.name = 'texture3d';
// default properties names
_this._dataCoordinates = 'dataCoordinates';
_this._dataValue = 'dataValue';
_this._offset = 'offset';
return _this;
}
_createClass(Texture3d, [{
key: 'api',
value: function api() {
var baseFragment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._base;
var dataCoordinates = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._dataCoordinates;
var dataValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this._dataValue;
var offset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : this._offset;
this._base = baseFragment;
return this.compute(dataCoordinates, dataValue, offset);
}
}, {
key: 'compute',
value: function compute(dataCoordinates, dataValue, offset) {
this.computeDefinition();
this._base._functions[this._name] = this._definition;
return this._name + '(' + dataCoordinates + ', ' + dataValue + ', ' + offset + ');';
}
}, {
key: 'computeDefinition',
value: function computeDefinition() {
this._definition = '\nvoid ' + this._name + '(in ivec3 dataCoordinates, out vec4 dataValue, out int offset){\n \n int index = dataCoordinates.x\n + dataCoordinates.y * uDataDimensions.x\n + dataCoordinates.z * uDataDimensions.y * uDataDimensions.x;\n int indexP = int(index/uPackedPerPixel);\n offset = index - 2*indexP;\n\n // Map data index to right sampler2D texture\n int voxelsPerTexture = uTextureSize*uTextureSize;\n int textureIndex = int(floor(float(indexP) / float(voxelsPerTexture)));\n // modulo seems incorrect sometimes...\n // int inTextureIndex = int(mod(float(index), float(textureSize*textureSize)));\n int inTextureIndex = indexP - voxelsPerTexture*textureIndex;\n\n // Get row and column in the texture\n int colIndex = int(mod(float(inTextureIndex), float(uTextureSize)));\n int rowIndex = int(floor(float(inTextureIndex)/float(uTextureSize)));\n\n // Map row and column to uv\n vec2 uv = vec2(0,0);\n uv.x = (0.5 + float(colIndex)) / float(uTextureSize);\n uv.y = 1. - (0.5 + float(rowIndex)) / float(uTextureSize);\n\n //\n if(textureIndex == 0){ dataValue = texture2D(uTextureContainer[0], uv); }\n else if(textureIndex == 1){dataValue = texture2D(uTextureContainer[1], uv);}\n else if(textureIndex == 2){ dataValue = texture2D(uTextureContainer[2], uv); }\n else if(textureIndex == 3){ dataValue = texture2D(uTextureContainer[3], uv); }\n else if(textureIndex == 4){ dataValue = texture2D(uTextureContainer[4], uv); }\n else if(textureIndex == 5){ dataValue = texture2D(uTextureContainer[5], uv); }\n else if(textureIndex == 6){ dataValue = texture2D(uTextureContainer[6], uv); }\n\n}\n ';
}
}]);
return Texture3d;
}(_shaders2.default);
exports.default = new Texture3d();
module.exports = exports['default'];