12345678910111213141516 |
- !function(r,o){"object"==typeof exports&&"object"==typeof module?module.exports=o(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-procedural-textures",["babylonjs"],o):"object"==typeof exports?exports["babylonjs-procedural-textures"]=o(require("babylonjs")):r.PROCEDURALTEXTURES=o(r.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(function(r){return function(r){var o={};function e(t){if(o[t])return o[t].exports;var n=o[t]={i:t,l:!1,exports:{}};return r[t].call(n.exports,n,n.exports,e),n.l=!0,n.exports}return e.m=r,e.c=o,e.d=function(r,o,t){e.o(r,o)||Object.defineProperty(r,o,{enumerable:!0,get:t})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,o){if(1&o&&(r=e(r)),8&o)return r;if(4&o&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(e.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&o&&"string"!=typeof r)for(var n in r)e.d(t,n,function(o){return r[o]}.bind(null,n));return t},e.n=function(r){var o=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(o,"a",o),o},e.o=function(r,o){return Object.prototype.hasOwnProperty.call(r,o)},e.p="",e(e.s=18)}({0:function(o,e){o.exports=r},1:function(r,o,e){"use strict";e.d(o,"b",(function(){return n})),e.d(o,"a",(function(){return i}));
- /*! *****************************************************************************
- Copyright (c) Microsoft Corporation. All rights reserved.
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
- this file except in compliance with the License. You may obtain a copy of the
- License at http://www.apache.org/licenses/LICENSE-2.0
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
- MERCHANTABLITY OR NON-INFRINGEMENT.
- See the Apache Version 2.0 License for specific language governing permissions
- and limitations under the License.
- ***************************************************************************** */
- var t=function(r,o){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,o){r.__proto__=o}||function(r,o){for(var e in o)o.hasOwnProperty(e)&&(r[e]=o[e])})(r,o)};function n(r,o){function e(){this.constructor=r}t(r,o),r.prototype=null===o?Object.create(o):(e.prototype=o.prototype,new e)}function i(r,o,e,t){var n,i=arguments.length,s=i<3?o:null===t?t=Object.getOwnPropertyDescriptor(o,e):t;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(r,o,e,t);else for(var l=r.length-1;l>=0;l--)(n=r[l])&&(s=(i<3?n(s):i>3?n(o,e,s):n(o,e))||s);return i>3&&s&&Object.defineProperty(o,e,s),s}},18:function(r,o,e){"use strict";e.r(o),function(r){var t=e(8);e.d(o,"GrassProceduralTexture",(function(){return t.GrassProceduralTexture}));var n=void 0!==r?r:"undefined"!=typeof window?window:void 0;if(void 0!==n)for(var i in t)n.BABYLON[i]=t[i]}.call(this,e(2))},2:function(r,o){var e;e=function(){return this}();try{e=e||new Function("return this")()}catch(r){"object"==typeof window&&(e=window)}r.exports=e},8:function(r,o,e){"use strict";e.r(o);var t=e(1),n=e(0),i="precision highp float;\nvarying vec2 vPosition;\nvarying vec2 vUV;\nuniform vec3 herb1Color;\nuniform vec3 herb2Color;\nuniform vec3 herb3Color;\nuniform vec3 groundColor;\nfloat rand(vec2 n) {\nreturn fract(cos(dot(n,vec2(12.9898,4.1414)))*43758.5453);\n}\nfloat noise(vec2 n) {\nconst vec2 d=vec2(0.0,1.0);\nvec2 b=floor(n),f=smoothstep(vec2(0.0),vec2(1.0),fract(n));\nreturn mix(mix(rand(b),rand(b+d.yx),f.x),mix(rand(b+d.xy),rand(b+d.yy),f.x),f.y);\n}\nfloat fbm(vec2 n) {\nfloat total=0.0,amplitude=1.0;\nfor (int i=0; i<4; i++) {\ntotal+=noise(n)*amplitude;\nn+=n;\namplitude*=0.5;\n}\nreturn total;\n}\nvoid main(void) {\nvec3 color=mix(groundColor,herb1Color,rand(gl_FragCoord.xy*4.0));\ncolor=mix(color,herb2Color,rand(gl_FragCoord.xy*8.0));\ncolor=mix(color,herb3Color,rand(gl_FragCoord.xy));\ncolor=mix(color,herb1Color,fbm(gl_FragCoord.xy*16.0));\ngl_FragColor=vec4(color,1.0);\n}";n.Effect.ShadersStore.grassProceduralTexturePixelShader=i;var s=function(r){function o(o,e,t,i,s){var l=r.call(this,o,e,"grassProceduralTexture",t,i,s)||this;return l._groundColor=new n.Color3(1,1,1),l._grassColors=[new n.Color3(.29,.38,.02),new n.Color3(.36,.49,.09),new n.Color3(.51,.6,.28)],l.updateShaderUniforms(),l}return Object(t.b)(o,r),o.prototype.updateShaderUniforms=function(){this.setColor3("herb1Color",this._grassColors[0]),this.setColor3("herb2Color",this._grassColors[1]),this.setColor3("herb3Color",this._grassColors[2]),this.setColor3("groundColor",this._groundColor)},Object.defineProperty(o.prototype,"grassColors",{get:function(){return this._grassColors},set:function(r){this._grassColors=r,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"groundColor",{get:function(){return this._groundColor},set:function(r){this._groundColor=r,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),o.prototype.serialize=function(){var o=n.SerializationHelper.Serialize(this,r.prototype.serialize.call(this));o.customType="BABYLON.GrassProceduralTexture",o.grassColors=[];for(var e=0;e<this._grassColors.length;e++)o.grassColors.push(this._grassColors[e].asArray());return o},o.Parse=function(r,e,t){for(var i=n.SerializationHelper.Parse((function(){return new o(r.name,r._size,e,void 0,r._generateMipMaps)}),r,e,t),s=[],l=0;l<r.grassColors.length;l++)s.push(n.Color3.FromArray(r.grassColors[l]));return i.grassColors=s,i},Object(t.a)([Object(n.serializeAsColor3)()],o.prototype,"groundColor",null),o}(n.ProceduralTexture);n._TypeStore.RegisteredTypes["BABYLON.GrassProceduralTexture"]=s,e.d(o,"GrassProceduralTexture",(function(){return s}))}})}));
|