├── README.md ├── LICENSE ├── index.html └── dist └── glsl-component.js /README.md: -------------------------------------------------------------------------------- 1 | # RayCasting3D -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Artem Yashin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Ray casting 3D 5 | 6 | 7 | 15 | 16 | 17 | 18 | precision highp float; 19 | uniform vec2 u_resolution; 20 | uniform vec2 u_mouse; 21 | //uniform vec3 u_pos; 22 | uniform float u_time; 23 | 24 | const float MAX_DIST = 99999.0; 25 | const vec3 light = normalize(vec3(-0.5, 0.75, -1.0)); 26 | 27 | mat2 rot(in float a) { 28 | float s = sin(a); 29 | float c = cos(a); 30 | return mat2(c, -s, s, c); 31 | } 32 | 33 | vec2 sphIntersect(in vec3 ro, in vec3 rd, float ra) { 34 | float b = dot(ro, rd); 35 | float c = dot(ro, ro) - ra * ra; 36 | float h = b * b - c; 37 | if(h < 0.0) return vec2(-1.0); 38 | h = sqrt(h); 39 | return vec2(-b - h, -b + h); 40 | } 41 | 42 | vec2 boxIntersection(in vec3 ro, in vec3 rd, in vec3 rad, out vec3 oN) { 43 | vec3 m = 1.0 / rd; 44 | vec3 n = m * ro; 45 | vec3 k = abs(m) * rad; 46 | vec3 t1 = -n - k; 47 | vec3 t2 = -n + k; 48 | float tN = max(max(t1.x, t1.y), t1.z); 49 | float tF = min(min(t2.x, t2.y), t2.z); 50 | if(tN > tF || tF < 0.0) return vec2(-1.0); 51 | oN = -sign(rd) * step(t1.yzx, t1.xyz) * step(t1.zxy, t1.xyz); 52 | return vec2(tN, tF); 53 | } 54 | 55 | float plaIntersect(in vec3 ro, in vec3 rd, in vec4 p) { 56 | return -(dot(ro, p.xyz) + p.w) / dot(rd, p.xyz); 57 | } 58 | 59 | vec3 getSky(in vec3 rd) { 60 | vec3 col = vec3(0.3, 0.6, 1.0); 61 | vec3 sun = vec3(0.95, 0.9, 1.0); 62 | sun *= pow(max(0.0, dot(rd, light)), 32.0); 63 | return clamp(sun + col, 0.0, 1.0); 64 | } 65 | 66 | vec3 castRay(inout vec3 ro, inout vec3 rd) { 67 | vec3 col; 68 | vec2 minIt = vec2(MAX_DIST); 69 | vec2 it; 70 | vec3 n; 71 | vec3 spherePos = vec3(0.0, -1.0, 0.0); 72 | it = sphIntersect(ro - spherePos, rd, 1.0); 73 | if(it.x > 0.0 && it.x < minIt.x) { 74 | minIt = it; 75 | vec3 itPos = ro + rd * it.x; 76 | n = itPos - spherePos; 77 | col = vec3(1.0, 0.2, 0.1); 78 | } 79 | vec3 boxN; 80 | vec3 boxPos = vec3(0.0, 2.0, 0.0); 81 | it = boxIntersection(ro - boxPos, rd, vec3(1.0), boxN); 82 | if(it.x > 0.0 && it.x < minIt.x) { 83 | minIt = it; 84 | n = boxN; 85 | col = vec3(0.4, 0.6, 0.8); 86 | } 87 | vec3 planeNormal = vec3(0.0, 0.0, -1.0); 88 | it = vec2(plaIntersect(ro, rd, vec4(planeNormal, 1.0))); 89 | if(it.x > 0.0 && it.x < minIt.x) { 90 | minIt = it; 91 | n = planeNormal; 92 | col = vec3(0.5); 93 | } 94 | if(minIt.x == MAX_DIST) return vec3(-1.0); 95 | float diffuse = dot(light, n) * 0.5 + 0.5; 96 | float specular = pow(max(0.0, dot(reflect(rd, n), light)), 32.0) * 2.0; 97 | col *= mix(diffuse, specular, 0.5); 98 | ro += rd * (minIt.x - 0.001); 99 | rd = n; 100 | return col; 101 | } 102 | 103 | vec3 traceRay(in vec3 ro, in vec3 rd) { 104 | vec3 col = castRay(ro, rd); 105 | if(col.x < 0.0) return getSky(rd); 106 | vec3 lightDir = light; 107 | if(dot(rd, light) > 0.0) { 108 | if(castRay(ro, lightDir).x != -1.0) col *= 0.5; 109 | } 110 | return col; 111 | } 112 | 113 | void main() { 114 | vec2 uv = gl_FragCoord.xy / u_resolution.y - vec2(1.0, 0.5); 115 | vec3 rayOrigin = vec3(-5.0, 0.0, 0.0); 116 | vec3 rayDirection = normalize(vec3(1.0, uv)); 117 | vec2 mouse = (-u_mouse / u_resolution - vec2(0.5)) * 3.0; 118 | rayDirection.zx *= rot(mouse.y); 119 | rayDirection.xy *= rot(mouse.x); 120 | vec3 col = traceRay(rayOrigin, rayDirection); 121 | col = pow(col, vec3(0.45)); 122 | gl_FragColor = vec4(col, 1.0); 123 | } 124 | 125 | 126 | -------------------------------------------------------------------------------- /dist/glsl-component.js: -------------------------------------------------------------------------------- 1 | !function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";r(1);var n=r(2),o=function(){};o.prototype=Object.create(HTMLCanvasElement.prototype),o.prototype.createdCallback=function(){var e=this.attachShadow({mode:"closed"}),t=document.createElement("canvas");e.appendChild(t),this.style.width="100%",this.style.height="100%",this.style.display="block",t.style.width="100%",t.style.height="100%",t.style.display="block",t.width=t.offsetWidth,t.height=t.offsetHeight;var r={},o=this.innerHTML.replace(/<br>/g,"");o=o.replace(/
/g,""),o=o.replace(/ /g,""),o=o.replace(/</g,"<"),o=o.replace(/>/g,">"),o=o.replace(/&/g,"&"),r.fragmentString=o||EMPTY_FRAG_SHADER,o&&(this.innerHTML="");for(var i=0;i1)&&$(this)}}}),Ce(i,I,{value:function(e){-1>0),O="addEventListener",D="attached",U="Callback",N="detached",F="extends",I="attributeChanged"+U,X=D+U,G="connected"+U,V="disconnected"+U,q="created"+U,B=N+U,W="ADDITION",Y="MODIFICATION",z="REMOVAL",K="DOMAttrModified",J="DOMContentLoaded",Z="DOMSubtreeModified",Q="<",ee="=",te=/^[A-Z][A-Z0-9]*(?:-[A-Z0-9]+)+$/,re=["ANNOTATION-XML","COLOR-PROFILE","FONT-FACE","FONT-FACE-SRC","FONT-FACE-URI","FONT-FACE-FORMAT","FONT-FACE-NAME","MISSING-GLYPH"],ne=[],oe=[],ie="",ae=x.documentElement,se=ne.indexOf||function(e){for(var t=this.length;t--&&this[t]!==e;);return t},ue=w.prototype,ce=ue.hasOwnProperty,le=ue.isPrototypeOf,fe=w.defineProperty,he=[],de=w.getOwnPropertyDescriptor,pe=w.getOwnPropertyNames,me=w.getPrototypeOf,ge=w.setPrototypeOf,ve=!!w.__proto__,be=!1,ye="__dreCEv1",$e=e.customElements,Ee="force"!==t&&!!($e&&$e.define&&$e.get&&$e.whenDefined),Te=w.create||w,xe=e.Map||function(){var e,t=[],r=[];return{get:function(e){return r[se.call(t,e)]},set:function(n,o){e=se.call(t,n),e<0?r[t.push(n)-1]=o:r[e]=o}}},we=e.Promise||function(e){function t(e){for(n=!0;r.length;)r.shift()(e)}var r=[],n=!1,o={catch:function(){return o},then:function(e){return r.push(e),n&&setTimeout(t,1),o}};return e(t),o},_e=!1,Me=Te(null),Le=Te(null),Ae=new xe,je=String,Re=w.create||function e(t){return t?(e.prototype=t,new e):this},Se=ge||(ve?function(e,t){return e.__proto__=t,e}:pe&&de?function(){function e(e,t){for(var r,n=pe(t),o=0,i=n.length;o1?arguments[1]:void 0,3);t=t?t.n:this._f;)for(r(t.v,t.k,this);t&&t.r;)t=t.p},has:function(e){return!!E(this,e)}}),g&&n.setDesc(l.prototype,"size",{get:function(){return u(this[b])}}),l},def:function(e,t,r){var n,o,i=E(e,t);return i?i.v=r:(e._l=i={i:o=$(t,!0),k:t,v:r,p:n=e._l,n:void 0,r:!1},e._f||(e._f=i),n&&(n.n=i),e[b]++,"F"!==o&&(e._i[o]=i)),e},getEntry:E,setStrong:function(e,t,r){l(e,t,function(e,t){this._t=e,this._k=t,this._l=void 0},function(){for(var e=this,t=e._k,r=e._l;r&&r.r;)r=r.p;return e._t&&(e._l=r=r?r.n:e._t._f)?"keys"==t?f(0,r.k):"values"==t?f(0,r.v):f(0,[r.k,r.v]):(e._t=void 0,f(1))},r?"entries":"values",!r,!0),m(t)}}},{"./$":49,"./$.ctx":28,"./$.defined":29,"./$.descriptors":30,"./$.for-of":34,"./$.has":36,"./$.hide":37,"./$.is-object":42,"./$.iter-define":45,"./$.iter-step":47,"./$.redefine-all":55,"./$.set-species":59,"./$.strict-new":63,"./$.uid":70}],25:[function(e,t,r){var n=e("./$.for-of"),o=e("./$.classof");t.exports=function(e){return function(){if(o(this)!=e)throw TypeError(e+"#toJSON isn't generic");var t=[];return n(this,!1,t.push,t),t}}},{"./$.classof":22,"./$.for-of":34}],26:[function(e,t,r){"use strict";var n=e("./$"),o=e("./$.global"),i=e("./$.export"),a=e("./$.fails"),s=e("./$.hide"),u=e("./$.redefine-all"),c=e("./$.for-of"),l=e("./$.strict-new"),f=e("./$.is-object"),h=e("./$.set-to-string-tag"),d=e("./$.descriptors");t.exports=function(e,t,r,p,m,g){var v=o[e],b=v,y=m?"set":"add",$=b&&b.prototype,E={};return d&&"function"==typeof b&&(g||$.forEach&&!a(function(){(new b).entries().next()}))?(b=t(function(t,r){l(t,b,e),t._c=new v,void 0!=r&&c(r,m,t[y],t)}),n.each.call("add,clear,delete,forEach,get,has,set,keys,values,entries".split(","),function(e){var t="add"==e||"set"==e;e in $&&(!g||"clear"!=e)&&s(b.prototype,e,function(r,n){if(!t&&g&&!f(r))return"get"==e&&void 0;var o=this._c[e](0===r?0:r,n);return t?this:o})}),"size"in $&&n.setDesc(b.prototype,"size",{get:function(){return this._c.size}})):(b=p.getConstructor(t,e,m,y),u(b.prototype,r)),h(b,e),E[e]=b,i(i.G+i.W+i.F,E),g||p.setStrong(b,e,m),b}},{"./$":49,"./$.descriptors":30,"./$.export":32,"./$.fails":33,"./$.for-of":34,"./$.global":35,"./$.hide":37,"./$.is-object":42,"./$.redefine-all":55,"./$.set-to-string-tag":60,"./$.strict-new":63}],27:[function(e,t,r){var n=t.exports={version:"1.2.6"};"number"==typeof __e&&(__e=n)},{}],28:[function(e,t,r){var n=e("./$.a-function");t.exports=function(e,t,r){if(n(e),void 0===t)return e;switch(r){case 1:return function(r){return e.call(t,r)};case 2:return function(r,n){return e.call(t,r,n)};case 3:return function(r,n,o){return e.call(t,r,n,o)}}return function(){return e.apply(t,arguments)}}},{"./$.a-function":19}],29:[function(e,t,r){t.exports=function(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}},{}],30:[function(e,t,r){t.exports=!e("./$.fails")(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},{"./$.fails":33}],31:[function(e,t,r){var n=e("./$.is-object"),o=e("./$.global").document,i=n(o)&&n(o.createElement);t.exports=function(e){return i?o.createElement(e):{}}},{"./$.global":35,"./$.is-object":42}],32:[function(e,t,r){var n=e("./$.global"),o=e("./$.core"),i=e("./$.ctx"),a="prototype",s=function(e,t,r){var u,c,l,f=e&s.F,h=e&s.G,d=e&s.S,p=e&s.P,m=e&s.B,g=e&s.W,v=h?o:o[t]||(o[t]={}),b=h?n:d?n[t]:(n[t]||{})[a];h&&(r=t);for(u in r)c=!f&&b&&u in b,c&&u in v||(l=c?b[u]:r[u],v[u]=h&&"function"!=typeof b[u]?r[u]:m&&c?i(l,n):g&&b[u]==l?function(e){var t=function(t){return this instanceof e?new e(t):e(t)};return t[a]=e[a],t}(l):p&&"function"==typeof l?i(Function.call,l):l,p&&((v[a]||(v[a]={}))[u]=l))};s.F=1,s.G=2,s.S=4,s.P=8,s.B=16,s.W=32,t.exports=s},{"./$.core":27,"./$.ctx":28,"./$.global":35}],33:[function(e,t,r){t.exports=function(e){try{return!!e()}catch(e){return!0}}},{}],34:[function(e,t,r){var n=e("./$.ctx"),o=e("./$.iter-call"),i=e("./$.is-array-iter"),a=e("./$.an-object"),s=e("./$.to-length"),u=e("./core.get-iterator-method");t.exports=function(e,t,r,c){var l,f,h,d=u(e),p=n(r,c,t?2:1),m=0;if("function"!=typeof d)throw TypeError(e+" is not iterable!");if(i(d))for(l=s(e.length);l>m;m++)t?p(a(f=e[m])[0],f[1]):p(e[m]);else for(h=d.call(e);!(f=h.next()).done;)o(h,p,f.value,t)}},{"./$.an-object":21,"./$.ctx":28,"./$.is-array-iter":41,"./$.iter-call":43,"./$.to-length":68,"./core.get-iterator-method":72}],35:[function(e,t,r){var n=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},{}],36:[function(e,t,r){var n={}.hasOwnProperty;t.exports=function(e,t){return n.call(e,t)}},{}],37:[function(e,t,r){var n=e("./$"),o=e("./$.property-desc");t.exports=e("./$.descriptors")?function(e,t,r){return n.setDesc(e,t,o(1,r))}:function(e,t,r){return e[t]=r,e}},{"./$":49,"./$.descriptors":30,"./$.property-desc":54}],38:[function(e,t,r){t.exports=e("./$.global").document&&document.documentElement},{"./$.global":35}],39:[function(e,t,r){t.exports=function(e,t,r){var n=void 0===r;switch(t.length){case 0:return n?e():e.call(r);case 1:return n?e(t[0]):e.call(r,t[0]);case 2:return n?e(t[0],t[1]):e.call(r,t[0],t[1]);case 3:return n?e(t[0],t[1],t[2]):e.call(r,t[0],t[1],t[2]);case 4:return n?e(t[0],t[1],t[2],t[3]):e.call(r,t[0],t[1],t[2],t[3])}return e.apply(r,t)}},{}],40:[function(e,t,r){var n=e("./$.cof");t.exports=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==n(e)?e.split(""):Object(e)}},{"./$.cof":23}],41:[function(e,t,r){var n=e("./$.iterators"),o=e("./$.wks")("iterator"),i=Array.prototype;t.exports=function(e){return void 0!==e&&(n.Array===e||i[o]===e)}},{"./$.iterators":48,"./$.wks":71}],42:[function(e,t,r){t.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},{}],43:[function(e,t,r){var n=e("./$.an-object");t.exports=function(e,t,r,o){try{return o?t(n(r)[0],r[1]):t(r)}catch(t){var i=e.return;throw void 0!==i&&n(i.call(e)),t}}},{"./$.an-object":21}],44:[function(e,t,r){"use strict";var n=e("./$"),o=e("./$.property-desc"),i=e("./$.set-to-string-tag"),a={};e("./$.hide")(a,e("./$.wks")("iterator"),function(){return this}),t.exports=function(e,t,r){e.prototype=n.create(a,{next:o(1,r)}),i(e,t+" Iterator")}},{"./$":49,"./$.hide":37,"./$.property-desc":54,"./$.set-to-string-tag":60,"./$.wks":71}],45:[function(e,t,r){"use strict";var n=e("./$.library"),o=e("./$.export"),i=e("./$.redefine"),a=e("./$.hide"),s=e("./$.has"),u=e("./$.iterators"),c=e("./$.iter-create"),l=e("./$.set-to-string-tag"),f=e("./$").getProto,h=e("./$.wks")("iterator"),d=!([].keys&&"next"in[].keys()),p="@@iterator",m="keys",g="values",v=function(){return this};t.exports=function(e,t,r,b,y,$,E){c(r,t,b);var T,x,w=function(e){if(!d&&e in A)return A[e];switch(e){case m:return function(){return new r(this,e)};case g:return function(){return new r(this,e)}}return function(){return new r(this,e)}},_=t+" Iterator",M=y==g,L=!1,A=e.prototype,j=A[h]||A[p]||y&&A[y],R=j||w(y);if(j){var S=f(R.call(new e));l(S,_,!0),!n&&s(A,p)&&a(S,h,v),M&&j.name!==g&&(L=!0,R=function(){return j.call(this)})}if(n&&!E||!d&&!L&&A[h]||a(A,h,R),u[t]=R,u[_]=v,y)if(T={values:M?R:w(g),keys:$?R:w(m),entries:M?w("entries"):R},E)for(x in T)x in A||i(A,x,T[x]);else o(o.P+o.F*(d||L),t,T);return T}},{"./$":49,"./$.export":32,"./$.has":36,"./$.hide":37,"./$.iter-create":44,"./$.iterators":48,"./$.library":50,"./$.redefine":56,"./$.set-to-string-tag":60,"./$.wks":71}],46:[function(e,t,r){var n=e("./$.wks")("iterator"),o=!1;try{var i=[7][n]();i.return=function(){o=!0},Array.from(i,function(){throw 2})}catch(e){}t.exports=function(e,t){if(!t&&!o)return!1;var r=!1;try{var i=[7],a=i[n]();a.next=function(){r=!0},i[n]=function(){return a},e(i)}catch(e){}return r}},{"./$.wks":71}],47:[function(e,t,r){t.exports=function(e,t){return{value:t,done:!!e}}},{}],48:[function(e,t,r){t.exports={}},{}],49:[function(e,t,r){var n=Object;t.exports={create:n.create,getProto:n.getPrototypeOf,isEnum:{}.propertyIsEnumerable,getDesc:n.getOwnPropertyDescriptor,setDesc:n.defineProperty,setDescs:n.defineProperties,getKeys:n.keys,getNames:n.getOwnPropertyNames,getSymbols:n.getOwnPropertySymbols,each:[].forEach}},{}],50:[function(e,t,r){t.exports=!0},{}],51:[function(e,t,r){var n,o,i,a=e("./$.global"),s=e("./$.task").set,u=a.MutationObserver||a.WebKitMutationObserver,c=a.process,l=a.Promise,f="process"==e("./$.cof")(c),h=function(){var e,t,r;for(f&&(e=c.domain)&&(c.domain=null,e.exit());n;)t=n.domain,r=n.fn,t&&t.enter(),r(),t&&t.exit(),n=n.next;o=void 0,e&&e.enter()};if(f)i=function(){c.nextTick(h)};else if(u){var d=1,p=document.createTextNode("");new u(h).observe(p,{characterData:!0}),i=function(){p.data=d=-d}}else i=l&&l.resolve?function(){l.resolve().then(h)}:function(){s.call(a,h)};t.exports=function(e){var t={fn:e,next:void 0,domain:f&&c.domain};o&&(o.next=t),n||(n=t,i()),o=t}},{"./$.cof":23,"./$.global":35,"./$.task":65}],52:[function(e,t,r){var n=e("./$"),o=e("./$.to-object"),i=e("./$.iobject");t.exports=e("./$.fails")(function(){var e=Object.assign,t={},r={},n=Symbol(),o="abcdefghijklmnopqrst";return t[n]=7,o.split("").forEach(function(e){r[e]=e}),7!=e({},t)[n]||Object.keys(e({},r)).join("")!=o})?function(e,t){for(var r=o(e),a=arguments,s=a.length,u=1,c=n.getKeys,l=n.getSymbols,f=n.isEnum;s>u;)for(var h,d=i(a[u++]),p=l?c(d).concat(l(d)):c(d),m=p.length,g=0;m>g;)f.call(d,h=p[g++])&&(r[h]=d[h]);return r}:Object.assign},{"./$":49,"./$.fails":33,"./$.iobject":40,"./$.to-object":69}],53:[function(e,t,r){var n=e("./$.export"),o=e("./$.core"),i=e("./$.fails");t.exports=function(e,t){var r=(o.Object||{})[e]||Object[e],a={};a[e]=t(r),n(n.S+n.F*i(function(){r(1)}),"Object",a)}},{"./$.core":27,"./$.export":32,"./$.fails":33}],54:[function(e,t,r){t.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},{}],55:[function(e,t,r){var n=e("./$.redefine");t.exports=function(e,t){for(var r in t)n(e,r,t[r]);return e}},{"./$.redefine":56}],56:[function(e,t,r){t.exports=e("./$.hide")},{"./$.hide":37}],57:[function(e,t,r){t.exports=Object.is||function(e,t){return e===t?0!==e||1/e===1/t:e!=e&&t!=t}},{}],58:[function(e,t,r){var n=e("./$").getDesc,o=e("./$.is-object"),i=e("./$.an-object"),a=function(e,t){if(i(e),!o(t)&&null!==t)throw TypeError(t+": can't set as prototype!")};t.exports={set:Object.setPrototypeOf||("__proto__"in{}?function(t,r,o){try{o=e("./$.ctx")(Function.call,n(Object.prototype,"__proto__").set,2),o(t,[]),r=!(t instanceof Array)}catch(e){r=!0}return function(e,t){return a(e,t),r?e.__proto__=t:o(e,t),e}}({},!1):void 0),check:a}},{"./$":49,"./$.an-object":21,"./$.ctx":28,"./$.is-object":42}],59:[function(e,t,r){"use strict";var n=e("./$.core"),o=e("./$"),i=e("./$.descriptors"),a=e("./$.wks")("species");t.exports=function(e){var t=n[e];i&&t&&!t[a]&&o.setDesc(t,a,{configurable:!0,get:function(){return this}})}},{"./$":49,"./$.core":27,"./$.descriptors":30,"./$.wks":71}],60:[function(e,t,r){var n=e("./$").setDesc,o=e("./$.has"),i=e("./$.wks")("toStringTag");t.exports=function(e,t,r){e&&!o(e=r?e:e.prototype,i)&&n(e,i,{configurable:!0,value:t})}},{"./$":49,"./$.has":36,"./$.wks":71}],61:[function(e,t,r){var n=e("./$.global"),o="__core-js_shared__",i=n[o]||(n[o]={});t.exports=function(e){return i[e]||(i[e]={})}},{"./$.global":35}],62:[function(e,t,r){var n=e("./$.an-object"),o=e("./$.a-function"),i=e("./$.wks")("species");t.exports=function(e,t){var r,a=n(e).constructor;return void 0===a||void 0==(r=n(a)[i])?t:o(r)}},{"./$.a-function":19,"./$.an-object":21,"./$.wks":71}],63:[function(e,t,r){t.exports=function(e,t,r){if(!(e instanceof t))throw TypeError(r+": use the 'new' operator!");return e}},{}],64:[function(e,t,r){var n=e("./$.to-integer"),o=e("./$.defined");t.exports=function(e){return function(t,r){var i,a,s=String(o(t)),u=n(r),c=s.length;return u<0||u>=c?e?"":void 0:(i=s.charCodeAt(u),i<55296||i>56319||u+1===c||(a=s.charCodeAt(u+1))<56320||a>57343?e?s.charAt(u):i:e?s.slice(u,u+2):(i-55296<<10)+(a-56320)+65536)}}},{"./$.defined":29,"./$.to-integer":66}],65:[function(e,t,r){var n,o,i,a=e("./$.ctx"),s=e("./$.invoke"),u=e("./$.html"),c=e("./$.dom-create"),l=e("./$.global"),f=l.process,h=l.setImmediate,d=l.clearImmediate,p=l.MessageChannel,m=0,g={},v="onreadystatechange",b=function(){var e=+this;if(g.hasOwnProperty(e)){var t=g[e];delete g[e],t(); 2 | }},y=function(e){b.call(e.data)};h&&d||(h=function(e){for(var t=[],r=1;arguments.length>r;)t.push(arguments[r++]);return g[++m]=function(){s("function"==typeof e?e:Function(e),t)},n(m),m},d=function(e){delete g[e]},"process"==e("./$.cof")(f)?n=function(e){f.nextTick(a(b,e,1))}:p?(o=new p,i=o.port2,o.port1.onmessage=y,n=a(i.postMessage,i,1)):l.addEventListener&&"function"==typeof postMessage&&!l.importScripts?(n=function(e){l.postMessage(e+"","*")},l.addEventListener("message",y,!1)):n=v in c("script")?function(e){u.appendChild(c("script"))[v]=function(){u.removeChild(this),b.call(e)}}:function(e){setTimeout(a(b,e,1),0)}),t.exports={set:h,clear:d}},{"./$.cof":23,"./$.ctx":28,"./$.dom-create":31,"./$.global":35,"./$.html":38,"./$.invoke":39}],66:[function(e,t,r){var n=Math.ceil,o=Math.floor;t.exports=function(e){return isNaN(e=+e)?0:(e>0?o:n)(e)}},{}],67:[function(e,t,r){var n=e("./$.iobject"),o=e("./$.defined");t.exports=function(e){return n(o(e))}},{"./$.defined":29,"./$.iobject":40}],68:[function(e,t,r){var n=e("./$.to-integer"),o=Math.min;t.exports=function(e){return e>0?o(n(e),9007199254740991):0}},{"./$.to-integer":66}],69:[function(e,t,r){var n=e("./$.defined");t.exports=function(e){return Object(n(e))}},{"./$.defined":29}],70:[function(e,t,r){var n=0,o=Math.random();t.exports=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++n+o).toString(36))}},{}],71:[function(e,t,r){var n=e("./$.shared")("wks"),o=e("./$.uid"),i=e("./$.global").Symbol;t.exports=function(e){return n[e]||(n[e]=i&&i[e]||(i||o)("Symbol."+e))}},{"./$.global":35,"./$.shared":61,"./$.uid":70}],72:[function(e,t,r){var n=e("./$.classof"),o=e("./$.wks")("iterator"),i=e("./$.iterators");t.exports=e("./$.core").getIteratorMethod=function(e){if(void 0!=e)return e[o]||e["@@iterator"]||i[n(e)]}},{"./$.classof":22,"./$.core":27,"./$.iterators":48,"./$.wks":71}],73:[function(e,t,r){var n=e("./$.an-object"),o=e("./core.get-iterator-method");t.exports=e("./$.core").getIterator=function(e){var t=o(e);if("function"!=typeof t)throw TypeError(e+" is not iterable!");return n(t.call(e))}},{"./$.an-object":21,"./$.core":27,"./core.get-iterator-method":72}],74:[function(e,t,r){"use strict";var n=e("./$.ctx"),o=e("./$.export"),i=e("./$.to-object"),a=e("./$.iter-call"),s=e("./$.is-array-iter"),u=e("./$.to-length"),c=e("./core.get-iterator-method");o(o.S+o.F*!e("./$.iter-detect")(function(e){Array.from(e)}),"Array",{from:function(e){var t,r,o,l,f=i(e),h="function"==typeof this?this:Array,d=arguments,p=d.length,m=p>1?d[1]:void 0,g=void 0!==m,v=0,b=c(f);if(g&&(m=n(m,p>2?d[2]:void 0,2)),void 0==b||h==Array&&s(b))for(t=u(f.length),r=new h(t);t>v;v++)r[v]=g?m(f[v],v):f[v];else for(l=b.call(f),r=new h;!(o=l.next()).done;v++)r[v]=g?a(l,m,[o.value,v],!0):o.value;return r.length=v,r}})},{"./$.ctx":28,"./$.export":32,"./$.is-array-iter":41,"./$.iter-call":43,"./$.iter-detect":46,"./$.to-length":68,"./$.to-object":69,"./core.get-iterator-method":72}],75:[function(e,t,r){"use strict";var n=e("./$.add-to-unscopables"),o=e("./$.iter-step"),i=e("./$.iterators"),a=e("./$.to-iobject");t.exports=e("./$.iter-define")(Array,"Array",function(e,t){this._t=a(e),this._i=0,this._k=t},function(){var e=this._t,t=this._k,r=this._i++;return!e||r>=e.length?(this._t=void 0,o(1)):"keys"==t?o(0,r):"values"==t?o(0,e[r]):o(0,[r,e[r]])},"values"),i.Arguments=i.Array,n("keys"),n("values"),n("entries")},{"./$.add-to-unscopables":20,"./$.iter-define":45,"./$.iter-step":47,"./$.iterators":48,"./$.to-iobject":67}],76:[function(e,t,r){var n=e("./$.export");n(n.S+n.F,"Object",{assign:e("./$.object-assign")})},{"./$.export":32,"./$.object-assign":52}],77:[function(e,t,r){var n=e("./$.to-object");e("./$.object-sap")("keys",function(e){return function(t){return e(n(t))}})},{"./$.object-sap":53,"./$.to-object":69}],78:[function(e,t,r){},{}],79:[function(e,t,r){"use strict";var n,o=e("./$"),i=e("./$.library"),a=e("./$.global"),s=e("./$.ctx"),u=e("./$.classof"),c=e("./$.export"),l=e("./$.is-object"),f=e("./$.an-object"),h=e("./$.a-function"),d=e("./$.strict-new"),p=e("./$.for-of"),m=e("./$.set-proto").set,g=e("./$.same-value"),v=e("./$.wks")("species"),b=e("./$.species-constructor"),y=e("./$.microtask"),$="Promise",E=a.process,T="process"==u(E),x=a[$],w=function(e){var t=new x(function(){});return e&&(t.constructor=Object),x.resolve(t)===t},_=function(){function t(e){var r=new x(e);return m(r,t.prototype),r}var r=!1;try{if(r=x&&x.resolve&&w(),m(t,x),t.prototype=o.create(x.prototype,{constructor:{value:t}}),t.resolve(5).then(function(){})instanceof t||(r=!1),r&&e("./$.descriptors")){var n=!1;x.resolve(o.setDesc({},"then",{get:function(){n=!0}})),r=n}}catch(e){r=!1}return r}(),M=function(e,t){return!(!i||e!==x||t!==n)||g(e,t)},L=function(e){var t=f(e)[v];return void 0!=t?t:e},A=function(e){var t;return!(!l(e)||"function"!=typeof(t=e.then))&&t},j=function(e){var t,r;this.promise=new e(function(e,n){if(void 0!==t||void 0!==r)throw TypeError("Bad Promise constructor");t=e,r=n}),this.resolve=h(t),this.reject=h(r)},R=function(e){try{e()}catch(e){return{error:e}}},S=function(e,t){if(!e.n){e.n=!0;var r=e.c;y(function(){for(var n=e.v,o=1==e.s,i=0,s=function(t){var r,i,a=o?t.ok:t.fail,s=t.resolve,u=t.reject;try{a?(o||(e.h=!0),r=a===!0?n:a(n),r===t.promise?u(TypeError("Promise-chain cycle")):(i=A(r))?i.call(r,s,u):s(r)):u(n)}catch(e){u(e)}};r.length>i;)s(r[i++]);r.length=0,e.n=!1,t&&setTimeout(function(){var t,r,o=e.p;H(o)&&(T?E.emit("unhandledRejection",n,o):(t=a.onunhandledrejection)?t({promise:o,reason:n}):(r=a.console)&&r.error&&r.error("Unhandled promise rejection",n)),e.a=void 0},1)})}},H=function(e){var t,r=e._d,n=r.a||r.c,o=0;if(r.h)return!1;for(;n.length>o;)if(t=n[o++],t.fail||!H(t.promise))return!1;return!0},P=function(e){var t=this;t.d||(t.d=!0,t=t.r||t,t.v=e,t.s=2,t.a=t.c.slice(),S(t,!0))},k=function(e){var t,r=this;if(!r.d){r.d=!0,r=r.r||r;try{if(r.p===e)throw TypeError("Promise can't be resolved itself");(t=A(e))?y(function(){var n={r:r,d:!1};try{t.call(e,s(k,n,1),s(P,n,1))}catch(e){P.call(n,e)}}):(r.v=e,r.s=1,S(r,!1))}catch(e){P.call({r:r,d:!1},e)}}};_||(x=function(e){h(e);var t=this._d={p:d(this,x,$),c:[],a:void 0,s:0,d:!1,v:void 0,h:!1,n:!1};try{e(s(k,t,1),s(P,t,1))}catch(e){P.call(t,e)}},e("./$.redefine-all")(x.prototype,{then:function(e,t){var r=new j(b(this,x)),n=r.promise,o=this._d;return r.ok="function"!=typeof e||e,r.fail="function"==typeof t&&t,o.c.push(r),o.a&&o.a.push(r),o.s&&S(o,!1),n},catch:function(e){return this.then(void 0,e)}})),c(c.G+c.W+c.F*!_,{Promise:x}),e("./$.set-to-string-tag")(x,$),e("./$.set-species")($),n=e("./$.core")[$],c(c.S+c.F*!_,$,{reject:function(e){var t=new j(this),r=t.reject;return r(e),t.promise}}),c(c.S+c.F*(!_||w(!0)),$,{resolve:function(e){if(e instanceof x&&M(e.constructor,this))return e;var t=new j(this),r=t.resolve;return r(e),t.promise}}),c(c.S+c.F*!(_&&e("./$.iter-detect")(function(e){x.all(e).catch(function(){})})),$,{all:function(e){var t=L(this),r=new j(t),n=r.resolve,i=r.reject,a=[],s=R(function(){p(e,!1,a.push,a);var r=a.length,s=Array(r);r?o.each.call(a,function(e,o){var a=!1;t.resolve(e).then(function(e){a||(a=!0,s[o]=e,--r||n(s))},i)}):n(s)});return s&&i(s.error),r.promise},race:function(e){var t=L(this),r=new j(t),n=r.reject,o=R(function(){p(e,!1,function(e){t.resolve(e).then(r.resolve,n)})});return o&&n(o.error),r.promise}})},{"./$":49,"./$.a-function":19,"./$.an-object":21,"./$.classof":22,"./$.core":27,"./$.ctx":28,"./$.descriptors":30,"./$.export":32,"./$.for-of":34,"./$.global":35,"./$.is-object":42,"./$.iter-detect":46,"./$.library":50,"./$.microtask":51,"./$.redefine-all":55,"./$.same-value":57,"./$.set-proto":58,"./$.set-species":59,"./$.set-to-string-tag":60,"./$.species-constructor":62,"./$.strict-new":63,"./$.wks":71}],80:[function(e,t,r){"use strict";var n=e("./$.collection-strong");e("./$.collection")("Set",function(e){return function(){return e(this,arguments.length>0?arguments[0]:void 0)}},{add:function(e){return n.def(this,e=0===e?0:e,e)}},n)},{"./$.collection":26,"./$.collection-strong":24}],81:[function(e,t,r){"use strict";var n=e("./$.string-at")(!0);e("./$.iter-define")(String,"String",function(e){this._t=String(e),this._i=0},function(){var e,t=this._t,r=this._i;return r>=t.length?{value:void 0,done:!0}:(e=n(t,r),this._i+=e.length,{value:e,done:!1})})},{"./$.iter-define":45,"./$.string-at":64}],82:[function(e,t,r){var n=e("./$.export");n(n.P,"Set",{toJSON:e("./$.collection-to-json")("Set")})},{"./$.collection-to-json":25,"./$.export":32}],83:[function(e,t,r){e("./es6.array.iterator");var n=e("./$.iterators");n.NodeList=n.HTMLCollection=n.Array},{"./$.iterators":48,"./es6.array.iterator":75}],84:[function(e,t,r){function n(e,t,r){if(!s(t))throw new TypeError("iterator must be a function");arguments.length<3&&(r=this),"[object Array]"===u.call(e)?o(e,t,r):"string"==typeof e?i(e,t,r):a(e,t,r)}function o(e,t,r){for(var n=0,o=e.length;n0&&(p=setTimeout(function(){d=!0,c.abort("timeout");var e=new Error("XMLHttpRequest timeout");e.code="ETIMEDOUT",n(e)},e.timeout)),c.setRequestHeader)for(f in b)b.hasOwnProperty(f)&&c.setRequestHeader(f,b[f]);else if(e.headers&&!o(e.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in e&&(c.responseType=e.responseType),"beforeSend"in e&&"function"==typeof e.beforeSend&&e.beforeSend(c),c.send(v),c}function u(){}var c=e("global/window"),l=e("once"),f=e("is-function"),h=e("parse-headers"),d=e("xtend");t.exports=a,a.XMLHttpRequest=c.XMLHttpRequest||u,a.XDomainRequest="withCredentials"in new a.XMLHttpRequest?a.XMLHttpRequest:c.XDomainRequest,n(["get","put","post","patch","head","delete"],function(e){a["delete"===e?"del":e]=function(t,r,n){return r=i(t,r,n),r.method=e.toUpperCase(),s(r)}})},{"global/window":85,"is-function":86,once:90,"parse-headers":87,xtend:91}],90:[function(e,t,r){function n(e){var t=!1;return function(){if(!t)return t=!0,e.apply(this,arguments)}}t.exports=n,n.proto=n(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return n(this)},configurable:!0})})},{}],91:[function(e,t,r){function n(){for(var e={},t=0;t0){window.glslCanvases=[];for(var t=0;t1&&g.setMouse(m),g.render(),g.forceRender=g.resize(),window.requestAnimationFrame(n)}var o=this;i(this,e),(0,d.subscribeMixin)(this),r=r||{},this.width=t.clientWidth,this.height=t.clientHeight,this.canvas=t,this.gl=void 0,this.program=void 0,this.textures={},this.uniforms={},this.vbo={},this.isValid=!1,this.vertexString=r.vertexString||"\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nattribute vec2 a_position;\nattribute vec2 a_texcoord;\n\nvarying vec2 v_texcoord;\n\nvoid main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n v_texcoord = a_texcoord;\n}\n",this.fragmentString=r.fragmentString||"\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nvarying vec2 v_texcoord;\n\nvoid main(){\n gl_FragColor = vec4(0.0);\n}\n";var a=(0,c.setupWebGL)(t,r);if(a){if(this.gl=a,this.timeLoad=this.timePrev=Date.now(),this.forceRender=!0,this.paused=!1,t.style.backgroundColor=r.backgroundColor||"rgba(1,1,1,0)",t.hasAttribute("data-fragment"))this.fragmentString=t.getAttribute("data-fragment");else if(t.hasAttribute("data-fragment-url")){var s=t.getAttribute("data-fragment-url");u.default.get(s,function(e,t,r){o.load(r,o.vertexString)})}if(t.hasAttribute("data-vertex"))this.vertexString=t.getAttribute("data-vertex");else if(t.hasAttribute("data-vertex-url")){var s=t.getAttribute("data-vertex-url");u.default.get(s,function(e,t,r){o.load(o.fragmentString,r)})}if(this.load(),this.program){var l=a.getAttribLocation(this.program,"a_texcoord");this.vbo.texCoords=a.createBuffer(),this.gl.bindBuffer(a.ARRAY_BUFFER,this.vbo.texCoords),this.gl.bufferData(a.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),a.STATIC_DRAW),this.gl.enableVertexAttribArray(l),this.gl.vertexAttribPointer(l,2,a.FLOAT,!1,0,0);var f=a.getAttribLocation(this.program,"a_position");if(this.vbo.vertices=a.createBuffer(),this.gl.bindBuffer(a.ARRAY_BUFFER,this.vbo.vertices),this.gl.bufferData(a.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),a.STATIC_DRAW),this.gl.enableVertexAttribArray(f),this.gl.vertexAttribPointer(f,2,a.FLOAT,!1,0,0),t.hasAttribute("data-textures")){var h=t.getAttribute("data-textures").split(",");for(var p in h)this.setUniform("u_tex"+p,h[p])}var m={x:0,y:0};document.addEventListener("mousemove",function(e){m.x=e.clientX||e.pageX,m.y=e.clientY||e.pageY},!1);var g=this;return this.setMouse({x:0,y:0}),n(),this}}}return o(e,[{key:"destroy",value:function(){this.animated=!1,this.isValid=!1;for(var e in this.textures)this.gl.deleteTexture(e);this.textures={};for(var t in this.attribs)this.gl.deleteBuffer(this.attribs[t]);this.gl.useProgram(null),this.gl.deleteProgram(this.program),this.program=null,this.gl=null}},{key:"load",value:function(e,t){t&&(this.vertexString=t),e&&(this.fragmentString=e),this.animated=!1,this.nDelta=(this.fragmentString.match(/u_delta/g)||[]).length,this.nTime=(this.fragmentString.match(/u_time/g)||[]).length,this.nDate=(this.fragmentString.match(/u_date/g)||[]).length,this.nMouse=(this.fragmentString.match(/u_mouse/g)||[]).length,this.animated=this.nDate>1||this.nTime>1||this.nMouse>1;var r=this.fragmentString.search(/sampler2D/g);if(r)for(var n=this.fragmentString.split("\n"),o=0;o1?r-1:0),o=1;o=t.left&&e.x<=t.right&&e.y&&e.y>=t.top&&e.y<=t.bottom&&this.uniform("2f","vec2","u_mouse",e.x-t.left,this.canvas.height-(e.y-t.top))}},{key:"uniform",value:function e(t,r,n){this.uniforms[n]=this.uniforms[n]||{};for(var e=this.uniforms[n],o=arguments.length,i=Array(o>3?o-3:0),a=3;a1&&(this.uniform("1f","float","u_time",(t-this.timePrev)/1e3),this.timePrev=t),this.nTime>1&&this.uniform("1f","float","u_time",(t-this.timeLoad)/1e3),this.nDate&&this.uniform("4f","float","u_date",e.getFullYear(),e.getMonth(),e.getDate(),3600*e.getHours()+60*e.getMinutes()+e.getSeconds()+.001*e.getMilliseconds()),this.uniform("2f","vec2","u_resolution",this.canvas.width,this.canvas.height),this.texureIndex=0;for(var r in this.textures)this.uniformTexture(r);this.gl.drawArrays(this.gl.TRIANGLES,0,6),this.trigger("render",{}),this.change=!1,this.forceRender=!1}}},{key:"pause",value:function(){this.paused=!0}},{key:"play",value:function(){this.paused=!1}},{key:"version",value:function(){return"0.0.16"}}]),e}();r.default=p,window.GlslCanvas=p,window.addEventListener("load",function(){n()}),t.exports=r.default},{"./gl/Texture":93,"./gl/gl":94,"./tools/common":95,"./tools/mixin":96,"babel-runtime/helpers/class-call-check":8,"babel-runtime/helpers/create-class":9,"babel-runtime/helpers/interop-require-default":10,xhr:89}],93:[function(e,t,r){"use strict";var n=e("babel-runtime/helpers/create-class").default,o=e("babel-runtime/helpers/class-call-check").default,i=e("babel-runtime/core-js/promise").default;Object.defineProperty(r,"__esModule",{value:!0});var a=e("../tools/common"),s=e("../tools/mixin"),u=function(){function e(t,r){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];o(this,e),(0,s.subscribeMixin)(this),this.gl=t,this.texture=t.createTexture(),this.texture&&(this.valid=!0),this.bind(),this.name=r,this.source=null,this.sourceType=null,this.loading=null,this.setData(1,1,new Uint8Array([0,0,0,255]),{filtering:"linear"}),this.setFiltering(n.filtering),this.load(n)}return n(e,[{key:"destroy",value:function(){this.valid&&(this.gl.deleteTexture(this.texture),this.texture=null,delete this.data,this.data=null,this.valid=!1)}},{key:"bind",value:function(t){this.valid&&("number"==typeof t&&e.activeUnit!==t&&(this.gl.activeTexture(this.gl.TEXTURE0+t),e.activeUnit=t),e.activeTexture!==this.texture&&(this.gl.bindTexture(this.gl.TEXTURE_2D,this.texture),e.activeTexture=this.texture))}},{key:"load",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.loading=null,"string"==typeof e.url?void 0!==this.url&&e.url===this.url||this.setUrl(e.url,e):e.element?this.setElement(e.element,e):e.data&&e.width&&e.height&&this.setData(e.width,e.height,e.data,e)}},{key:"setUrl",value:function(e){var t=this,r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(this.valid)return this.url=e,this.source=this.url,this.sourceType="url",this.loading=new i(function(e,n){var o=new Image;o.onload=function(){try{t.setElement(o,r)}catch(e){console.log("Texture '"+t.name+"': failed to load url: '"+t.source+"'",e,r)}e(t)},o.onerror=function(n){console.log("Texture '"+t.name+"': failed to load url: '"+t.source+"'",n,r),e(t)},o.crossOrigin="anonymous",o.src=t.source}),this.loading}},{key:"setData",value:function(e,t,r){var n=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];return this.width=e,this.height=t,this.source=r,this.sourceType="data",this.update(n),this.setFiltering(n),this.loading=i.resolve(this),this.loading}},{key:"setElement",value:function(e,t){var r=e;if("string"==typeof e&&(e=document.querySelector(e)),e instanceof HTMLCanvasElement||e instanceof HTMLImageElement||e instanceof HTMLVideoElement)this.source=e,this.sourceType="element",this.update(t),this.setFiltering(t);else{var n="the 'element' parameter (`element: "+JSON.stringify(r)+"`) must be a CSS ";n+="selector string, or a , or