UNPKG

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>

75 lines (60 loc) 3.48 kB
'use strict'; 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; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var ShadersFragment = function () { // pass uniforms object function ShadersFragment(uniforms) { _classCallCheck(this, ShadersFragment); this._uniforms = uniforms; this._functions = {}; this._main = ''; } _createClass(ShadersFragment, [{ key: 'functions', value: function functions() { if (this._main === '') { // if main is empty, functions can not have been computed this.main(); } var content = ''; for (var property in this._functions) { content += this._functions[property] + '\n'; } return content; } }, { key: 'uniforms', value: function uniforms() { var content = ''; for (var property in this._uniforms) { var uniform = this._uniforms[property]; content += 'uniform ' + uniform.typeGLSL + ' ' + property; if (uniform && uniform.length) { content += '[' + uniform.length + ']'; } content += ';\n'; } return content; } }, { key: 'main', value: function main() { // need to pre-call main to fill up the functions list this._main = '\nvoid main(void) {\n\n vec2 texc = vec2(((vProjectedCoords.x / vProjectedCoords.w) + 1.0 ) / 2.0,\n ((vProjectedCoords.y / vProjectedCoords.w) + 1.0 ) / 2.0 );\n\n // just silence warning for\n vec4 dummy = vPos;\n\n //The back position is the world space position stored in the texture.\n vec4 baseColor0 = texture2D(uTextureBackTest0, texc);\n vec4 baseColor1 = texture2D(uTextureBackTest1, texc);\n\n if( uTrackMouse == 1 ){\n\n if( vProjectedCoords.x < uMouse.x ){\n\n gl_FragColor = baseColor0;\n\n }\n else{\n\n gl_FragColor = mix( baseColor0, baseColor1, uOpacity1 );\n\n }\n\n }\n else{\n\n if( uType1 == 0 ){\n\n //merge an image into\n gl_FragColor = mix( baseColor0, baseColor1, uOpacity1 );\n\n }\n else{\n\n float opacity = baseColor1.a;\n gl_FragColor = mix( baseColor0, baseColor1, opacity * uOpacity1 );\n\n }\n\n }\n\n return;\n}\n '; } }, { key: 'compute', value: function compute() { var shaderInterpolation = ''; // shaderInterpolation.inline(args) //true/false // shaderInterpolation.functions(args) return '\n// uniforms\n' + this.uniforms() + '\n\n// varying (should fetch it from vertex directly)\nvarying vec4 vPos;\nvarying vec4 vProjectedCoords;\n\n// tailored functions\n' + this.functions() + '\n\n// main loop\n' + this._main + '\n '; } }]); return ShadersFragment; }(); exports.default = ShadersFragment; module.exports = exports['default'];