Babylon.ShaderBuilder.ts 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  1. module BABYLON {
  2. export interface ShaderStruct {
  3. Pixel: string,
  4. Vertex: string
  5. }
  6. export interface IColor {
  7. r: any;
  8. g: any;
  9. b: any;
  10. a: any;
  11. }
  12. export interface IVector3 {
  13. x: any;
  14. y: any;
  15. z: any;
  16. }
  17. export interface ILight {
  18. direction: string;
  19. rotation: IVector3;
  20. color: IColor;
  21. darkColorMode: boolean;
  22. specular: any,
  23. specularPower: number,
  24. specularLevel: number,
  25. phonge: any,
  26. phongePower: number,
  27. phongeLevel: number,
  28. normal: string,
  29. reducer: string,
  30. supplement: boolean,
  31. parallel: boolean
  32. }
  33. export interface ITexture {
  34. key: string,
  35. inVertex: boolean,
  36. inFragment: boolean,
  37. indexedDB: number
  38. }
  39. export interface IEffect {
  40. px: any,
  41. py: any,
  42. pz: any,
  43. pr: any,
  44. }
  45. export interface IMap {
  46. path: string,
  47. x: any,
  48. y: any,
  49. scaleX: any,
  50. scaleY: any,
  51. rotation: IVector3;
  52. useInVertex: boolean;
  53. uv: string,
  54. normal: string,
  55. normalLevel: string,
  56. bias: string,
  57. alpha: boolean,
  58. rowIndex: number,
  59. columnIndex: number,
  60. indexCount: number,
  61. tiled: boolean,
  62. animation: boolean,
  63. animationSpeed: number,
  64. animationFrameEnd: number,
  65. animationFrameStart: number,
  66. }
  67. export interface IReflectMap {
  68. path: string,
  69. x: any,
  70. y: any,
  71. scaleX: any,
  72. scaleY: any,
  73. equirectangular: boolean,
  74. rotation: IVector3;
  75. useInVertex: boolean;
  76. uv: string,
  77. normal: string,
  78. normalLevel: string,
  79. bias: string,
  80. alpha: boolean,
  81. revers: boolean,
  82. reflectMap: string,
  83. refract: boolean,
  84. refractMap: string,
  85. }
  86. export interface IReplaceColor {
  87. colorIndex: number,
  88. colorStep: number,
  89. indexToEnd: boolean,
  90. rangeStep: any,
  91. rangePower: any
  92. }
  93. export interface IRange {
  94. start: any;
  95. end: any;
  96. direction: any;
  97. }
  98. export class ShaderMaterialHelperStatics {
  99. static Dark = false;
  100. static Light = true;
  101. static PrecisionHighMode = 'highp';
  102. static PrecisionMediumMode = 'mediump';
  103. static face_back = "!gl_FrontFacing";
  104. static face_front = "gl_FrontFacing";
  105. static AttrPosition = 'position';
  106. static AttrNormal = 'normal';
  107. static AttrUv = 'uv';
  108. static AttrUv2 = 'uv2';
  109. static AttrTypeForPosition = 'vec3';
  110. static AttrTypeForNormal = 'vec3';
  111. static AttrTypeForUv = 'vec2';
  112. static AttrTypeForUv2 = 'vec2';
  113. static uniformView = "view";
  114. static uniformWorld = "world";
  115. static uniformWorldView = "worldView";
  116. static uniformViewProjection = "viewProjection";
  117. static uniformWorldViewProjection = "worldViewProjection";
  118. static uniformStandardType = "mat4";
  119. static uniformFlags = "flags";
  120. static Mouse = "mouse";
  121. static Screen = "screen";
  122. static Camera = "camera";
  123. static Look = "look";
  124. static Time = "time";
  125. static GlobalTime = "gtime";
  126. static Position = "pos";
  127. static WorldPosition = "wpos";
  128. static Normal = "nrm";
  129. static WorldNormal = "wnrm";
  130. static Uv = "vuv";
  131. static Uv2 = "vuv2";
  132. static Center = 'center';
  133. static ReflectMatrix = "refMat";
  134. static Texture2D = "txtRef_";
  135. static TextureCube = "cubeRef_";
  136. static IdentityHelper: number;
  137. constructor() {
  138. }
  139. }
  140. export class Normals {
  141. static Default = ShaderMaterialHelperStatics.Normal;
  142. static Inverse = '-1.*' + ShaderMaterialHelperStatics.Normal;
  143. static Pointed = 'normalize(' + ShaderMaterialHelperStatics.Position + '-' + ShaderMaterialHelperStatics.Center + ')';
  144. static Flat = 'normalize(cross(dFdx(' + ShaderMaterialHelperStatics.Position + ' * -1.), dFdy(' + ShaderMaterialHelperStatics.Position + ')))';
  145. static Map = 'normalMap()';
  146. }
  147. class Speculars {
  148. static Map = 'specularMap()';
  149. }
  150. interface ShaderHelper {
  151. uniforms: string[],
  152. attributes: string[]
  153. }
  154. export class ShaderMaterialHelper<Scene>{
  155. ShaderMaterial(name: string, scene: Scene, shader: ShaderStruct, helpers: ShaderHelper) {
  156. return this.MakeShaderMaterialForEngine(name, scene, shader, helpers);
  157. }
  158. MakeShaderMaterialForEngine(name: string, scene: Scene, shader: ShaderStruct, helpers: ShaderHelper) { return {}; }
  159. DefineTexture(txt: ITexture, scene: Scene) {
  160. return null;
  161. }
  162. DefineCubeTexture(txt: ITexture, scene: Scene) {
  163. return null;
  164. }
  165. SetUniforms(meshes: any, cameraPos: any, cameraTarget: any, mouse: any, screen: any, time: any) {
  166. }
  167. }
  168. export class Shader {
  169. static _null = 'set null anyway';
  170. static Indexer: number;
  171. static ShaderIdentity: number;
  172. static Me: ShaderBuilder;
  173. static Replace(s: string, t: string, d: string) {
  174. var ignore = null;
  175. return s.replace(new RegExp(t.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g, "\\$&"), (ignore ? "gi" : "g")), (typeof (d) == "string") ? d.replace(/\$/g, "$$$$") : d);
  176. }
  177. static Def(a: any, d: any) {
  178. if (a != undefined && a != null) return (d != undefined && d != null ? a : true);
  179. else
  180. if (d != Shader._null)
  181. return (d != undefined && d != null ? d : false);
  182. return null;
  183. }
  184. static Join(s: string[]) {
  185. return s.join("\n\
  186. ");
  187. }
  188. static Print(n: any) {
  189. if (n == undefined) return "0.";
  190. var sn = Shader.Replace(n.toString(), '-', '0');
  191. var reg = new RegExp('^\\d+$');
  192. if (reg.test(sn) && n.toString().indexOf('.') == -1) return n + ".";
  193. return n.toString();
  194. }
  195. static Custom() {
  196. return "custom_" + this.Print(++this.Me.CustomIndexer) + "_";
  197. }
  198. static Index() {
  199. return "_" + Shader.Indexer + "_";
  200. }
  201. static DefCustom(t: string, c: string) {
  202. this.Me.Body += t + " custom_" + this.Print(++this.Me.CustomIndexer) + "_ = " + c + ";";
  203. }
  204. }
  205. export class Helper {
  206. static Red = 0;
  207. static Yellow = 1;
  208. static White = 2;
  209. static Cyan = 4;
  210. static Blue = 5;
  211. static Pink = 6;
  212. static Black = 7;
  213. static Green = 8;
  214. constructor() {
  215. var setting = Shader.Me.Setting;
  216. var instance = new ShaderBuilder();
  217. instance.Parent = Shader.Me;
  218. instance.Setting = setting;
  219. return instance;
  220. }
  221. }
  222. export class ShaderSetting {
  223. Texture2Ds: any[];
  224. TextureCubes: any[];
  225. PrecisionMode: string;
  226. Transparency: boolean;
  227. Back: boolean;
  228. Front: boolean;
  229. Wire: boolean;
  230. Uv: boolean;
  231. Uv2: boolean;
  232. Center: boolean;
  233. Flags: boolean;
  234. FragmentView: boolean;
  235. FragmentWorld: boolean;
  236. FragmentWorldView: boolean;
  237. FragmentViewProjection: boolean;
  238. SpecularMap: string;
  239. NormalMap: string;
  240. Normal: string;
  241. NormalOpacity: string;
  242. WorldPosition: boolean;
  243. Vertex: boolean;
  244. VertexView: boolean;
  245. VertexWorld: boolean;
  246. VertexWorldView: boolean;
  247. VertexViewProjection: boolean;
  248. Mouse: boolean;
  249. Screen: boolean;
  250. Camera: boolean;
  251. Look: boolean;
  252. Time: boolean;
  253. GlobalTime: boolean;
  254. ReflectMatrix: boolean;
  255. Helpers: Boolean;
  256. constructor() {
  257. this.PrecisionMode = ShaderMaterialHelperStatics.PrecisionHighMode;
  258. }
  259. }
  260. export class ShaderBuilder {
  261. Parent: ShaderBuilder;
  262. Setting: ShaderSetting;
  263. CustomIndexer: number;
  264. Fragment: string[];
  265. Vertex: string[];
  266. static InitializeEngine() {
  267. eval(BABYLON.Shader.Replace(BABYLON.Shader.Replace("BABYLON.ShaderMaterialHelper.prototype.MakeShaderMaterialForEngine=function(name,scene,shader,helpers){BABYLON.Effect.ShadersStore[name+#[QT]VertexShader#[QT]]=shader.Vertex;BABYLON.Effect.ShadersStore[name+#[QT]PixelShader#[QT]]=shader.Pixel;return new BABYLON.ShaderMaterial(name,scene,{vertex:name,fragment:name},helpers);}", "#[QT]", '"'), '#[T]', "'"));
  268. eval(BABYLON.Shader.Replace(BABYLON.Shader.Replace("BABYLON.ShaderMaterialHelper.prototype.DefineTexture = function (option, sc) { var tx = new BABYLON.Texture(option, sc); return tx; } ", "#[QT]", '"'), '#[T]', "'"));
  269. eval(BABYLON.Shader.Replace(BABYLON.Shader.Replace("BABYLON.ShaderMaterialHelper.prototype.DefineCubeTexture = function (option, sc) { var tx = new BABYLON.CubeTexture(option, sc); tx.coordinatesMode = BABYLON.Texture.PLANAR_MODE; return tx; } ", "#[QT]", '"'), '#[T]', "'"));
  270. eval(BABYLON.Shader.Replace(BABYLON.Shader.Replace("BABYLON.ShaderMaterialHelper.prototype.SetUniforms = function (meshes, cameraPos, cameraTarget, mouse, screen, time) { for (var ms in meshes) { ms = meshes[ms]; if (ms.material && (ms.material.ShaderSetting != null || ms.material.ShaderSetting != undefined)) { if (ms.material.ShaderSetting.Camera) ms.material.setVector3(BABYLON.ShaderMaterialHelperStatics.Camera, cameraPos); if (ms.material.ShaderSetting.Center) ms.material.setVector3(BABYLON.ShaderMaterialHelperStatics.Center, { x: 0., y: 0., z: 0. }); if (ms.material.ShaderSetting.Mouse) ms.material.setVector2(BABYLON.ShaderMaterialHelperStatics.Mouse, mouse); if (ms.material.ShaderSetting.Screen) ms.material.setVector2(BABYLON.ShaderMaterialHelperStatics.Screen, screen); if (ms.material.ShaderSetting.GlobalTime) ms.material.setVector4(BABYLON.ShaderMaterialHelperStatics.GlobalTime, { x: 0., y: 0., z: 0., w: 0. }); if (ms.material.ShaderSetting.Look) ms.material.setVector3(BABYLON.ShaderMaterialHelperStatics.Look, cameraTarget); if (ms.material.ShaderSetting.Time) ms.material.setFloat(BABYLON.ShaderMaterialHelperStatics.Time, time); } } }", "#[QT]", '"'), '#[T]', "'"));
  271. }
  272. FragmentBeforeMain: string;
  273. VertexBeforeMain: string;
  274. Varings: string[];
  275. Attributes: string[];
  276. Uniforms: string[];
  277. Extentions: string[];
  278. References: string;
  279. Helpers: string[];
  280. Body: string;
  281. VertexBody: string;
  282. AfterVertex: string;
  283. PrepareBeforeMaterialBuild(scene: any) {
  284. this.Setting = Shader.Me.Setting;
  285. this.Attributes.push(ShaderMaterialHelperStatics.AttrPosition);
  286. this.Attributes.push(ShaderMaterialHelperStatics.AttrNormal);
  287. if (this.Setting.Uv) {
  288. this.Attributes.push(ShaderMaterialHelperStatics.AttrUv);
  289. }
  290. if (this.Setting.Uv2) {
  291. this.Attributes.push(ShaderMaterialHelperStatics.AttrUv2);
  292. }
  293. this.Uniforms.push(ShaderMaterialHelperStatics.uniformView,
  294. ShaderMaterialHelperStatics.uniformWorld,
  295. ShaderMaterialHelperStatics.uniformWorldView,
  296. ShaderMaterialHelperStatics.uniformViewProjection,
  297. ShaderMaterialHelperStatics.uniformWorldViewProjection);
  298. // start Build Vertex Frame
  299. this.Vertex.push("precision " + this.Setting.PrecisionMode + " float;");
  300. this.Vertex.push("attribute " + ShaderMaterialHelperStatics.AttrTypeForPosition + " " + ShaderMaterialHelperStatics.AttrPosition + ";");
  301. this.Vertex.push("attribute " + ShaderMaterialHelperStatics.AttrTypeForNormal + " " + ShaderMaterialHelperStatics.AttrNormal + ";");
  302. if (this.Setting.Uv) {
  303. this.Vertex.push("attribute " + ShaderMaterialHelperStatics.AttrTypeForUv + " " + ShaderMaterialHelperStatics.AttrUv + ";");
  304. this.Vertex.push("varying vec2 " + ShaderMaterialHelperStatics.Uv + ";");
  305. }
  306. if (this.Setting.Uv2) {
  307. this.Vertex.push("attribute " + ShaderMaterialHelperStatics.AttrTypeForUv2 + " " + ShaderMaterialHelperStatics.AttrUv2 + ";");
  308. this.Vertex.push("varying vec2 " + ShaderMaterialHelperStatics.Uv2 + ";");
  309. }
  310. this.Vertex.push("varying vec3 " + ShaderMaterialHelperStatics.Position + ";");
  311. this.Vertex.push("varying vec3 " + ShaderMaterialHelperStatics.Normal + ";");
  312. this.Vertex.push("uniform " + ShaderMaterialHelperStatics.uniformStandardType + ' ' + ShaderMaterialHelperStatics.uniformWorldViewProjection + ";");
  313. if (this.Setting.VertexView) {
  314. this.Vertex.push("uniform " + ShaderMaterialHelperStatics.uniformStandardType + ' ' + ShaderMaterialHelperStatics.uniformView + ";");
  315. }
  316. if (this.Setting.VertexWorld) {
  317. this.Vertex.push("uniform " + ShaderMaterialHelperStatics.uniformStandardType + ' ' + ShaderMaterialHelperStatics.uniformWorld + ";");
  318. }
  319. if (this.Setting.VertexViewProjection) {
  320. this.Vertex.push("uniform " + ShaderMaterialHelperStatics.uniformStandardType + ' ' + ShaderMaterialHelperStatics.uniformViewProjection + ";");
  321. }
  322. if (this.Setting.Flags) {
  323. this.Uniforms.push(ShaderMaterialHelperStatics.uniformFlags);
  324. this.Vertex.push("uniform float " + ShaderMaterialHelperStatics.uniformFlags + ";");
  325. }
  326. if (this.Setting.VertexWorldView) {
  327. this.Vertex.push("uniform " + ShaderMaterialHelperStatics.uniformStandardType + ' ' + ShaderMaterialHelperStatics.uniformWorldView + ";");
  328. }
  329. /*#extension GL_OES_standard_derivatives : enable*/
  330. this.Fragment.push("precision " + this.Setting.PrecisionMode + " float;\n\
  331. #extension GL_OES_standard_derivatives : enable\n\
  332. \n\
  333. \n\
  334. ");
  335. if (this.Setting.Uv) {
  336. this.Fragment.push("varying vec2 " + ShaderMaterialHelperStatics.Uv + ";");
  337. }
  338. if (this.Setting.Uv2) {
  339. this.Fragment.push("varying vec2 " + ShaderMaterialHelperStatics.Uv2 + ";");
  340. }
  341. if (this.Setting.FragmentView) {
  342. this.Fragment.push("uniform " + ShaderMaterialHelperStatics.uniformStandardType + ' ' + ShaderMaterialHelperStatics.uniformView + ";");
  343. }
  344. if (this.Setting.FragmentWorld) {
  345. this.Fragment.push("uniform " + ShaderMaterialHelperStatics.uniformStandardType + ' ' + ShaderMaterialHelperStatics.uniformWorld + ";");
  346. }
  347. if (this.Setting.FragmentViewProjection) {
  348. this.Fragment.push("uniform " + ShaderMaterialHelperStatics.uniformStandardType + ' ' + ShaderMaterialHelperStatics.uniformViewProjection + ";");
  349. }
  350. if (this.Setting.FragmentWorldView) {
  351. this.Fragment.push("uniform " + ShaderMaterialHelperStatics.uniformStandardType + ' ' + ShaderMaterialHelperStatics.uniformWorldView + ";");
  352. }
  353. if (this.Setting.Flags) {
  354. this.Fragment.push("uniform float " + ShaderMaterialHelperStatics.uniformFlags + ";");
  355. }
  356. this.Fragment.push("varying vec3 " + ShaderMaterialHelperStatics.Position + ";");
  357. this.Fragment.push("varying vec3 " + ShaderMaterialHelperStatics.Normal + ";");
  358. if (this.Setting.WorldPosition) {
  359. this.Vertex.push("varying vec3 " + ShaderMaterialHelperStatics.WorldPosition + ";");
  360. this.Vertex.push("varying vec3 " + ShaderMaterialHelperStatics.WorldNormal + ";");
  361. this.Fragment.push("varying vec3 " + ShaderMaterialHelperStatics.WorldPosition + ";");
  362. this.Fragment.push("varying vec3 " + ShaderMaterialHelperStatics.WorldNormal + ";");
  363. }
  364. if (this.Setting.Texture2Ds != null) {
  365. for (var s in this.Setting.Texture2Ds) {
  366. if (this.Setting.Texture2Ds[s].inVertex) {
  367. this.Vertex.push("uniform sampler2D " + ShaderMaterialHelperStatics.Texture2D + s + ";");
  368. }
  369. if (this.Setting.Texture2Ds[s].inFragment) {
  370. this.Fragment.push("uniform sampler2D " + ShaderMaterialHelperStatics.Texture2D + s + ";");
  371. }
  372. }
  373. }
  374. if (this.Setting.TextureCubes != null) {
  375. for (var s in this.Setting.TextureCubes) {
  376. if (this.Setting.TextureCubes[s].inVertex) {
  377. this.Vertex.push("uniform samplerCube " + ShaderMaterialHelperStatics.TextureCube + s + ";");
  378. }
  379. if (this.Setting.TextureCubes[s].inFragment) {
  380. this.Fragment.push("uniform samplerCube " + ShaderMaterialHelperStatics.TextureCube + s + ";");
  381. }
  382. }
  383. }
  384. if (this.Setting.Center) {
  385. this.Vertex.push("uniform vec3 " + ShaderMaterialHelperStatics.Center + ";");
  386. this.Fragment.push("uniform vec3 " + ShaderMaterialHelperStatics.Center + ";");
  387. }
  388. if (this.Setting.Mouse) {
  389. this.Vertex.push("uniform vec2 " + ShaderMaterialHelperStatics.Mouse + ";");
  390. this.Fragment.push("uniform vec2 " + ShaderMaterialHelperStatics.Mouse + ";");
  391. }
  392. if (this.Setting.Screen) {
  393. this.Vertex.push("uniform vec2 " + ShaderMaterialHelperStatics.Screen + ";");
  394. this.Fragment.push("uniform vec2 " + ShaderMaterialHelperStatics.Screen + ";");
  395. }
  396. if (this.Setting.Camera) {
  397. this.Vertex.push("uniform vec3 " + ShaderMaterialHelperStatics.Camera + ";");
  398. this.Fragment.push("uniform vec3 " + ShaderMaterialHelperStatics.Camera + ";");
  399. }
  400. if (this.Setting.Look) {
  401. this.Vertex.push("uniform vec3 " + ShaderMaterialHelperStatics.Look + ";");
  402. this.Fragment.push("uniform vec3 " + ShaderMaterialHelperStatics.Look + ";");
  403. }
  404. if (this.Setting.Time) {
  405. this.Vertex.push("uniform float " + ShaderMaterialHelperStatics.Time + ";");
  406. this.Fragment.push("uniform float " + ShaderMaterialHelperStatics.Time + ";");
  407. }
  408. if (this.Setting.GlobalTime) {
  409. this.Vertex.push("uniform vec4 " + ShaderMaterialHelperStatics.GlobalTime + ";");
  410. this.Fragment.push("uniform vec4 " + ShaderMaterialHelperStatics.GlobalTime + ";");
  411. }
  412. if (this.Setting.ReflectMatrix) {
  413. this.Vertex.push("uniform mat4 " + ShaderMaterialHelperStatics.ReflectMatrix + ";");
  414. this.Fragment.push("uniform mat4 " + ShaderMaterialHelperStatics.ReflectMatrix + ";");
  415. }
  416. if (this.Setting.Helpers) {
  417. var sresult = Shader.Join([
  418. "vec3 random3(vec3 c) { float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0))); vec3 r; r.z = fract(512.0*j); j *= .125; r.x = fract(512.0*j); j *= .125; r.y = fract(512.0*j); return r-0.5; } ",
  419. "float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } ",
  420. "const float F3 = 0.3333333;const float G3 = 0.1666667;",
  421. "float simplex3d(vec3 p) { vec3 s = floor(p + dot(p, vec3(F3))); vec3 x = p - s + dot(s, vec3(G3)); vec3 e = step(vec3(0.0), x - x.yzx); vec3 i1 = e*(1.0 - e.zxy); vec3 i2 = 1.0 - e.zxy*(1.0 - e); vec3 x1 = x - i1 + G3; vec3 x2 = x - i2 + 2.0*G3; vec3 x3 = x - 1.0 + 3.0*G3; vec4 w, d; w.x = dot(x, x); w.y = dot(x1, x1); w.z = dot(x2, x2); w.w = dot(x3, x3); w = max(0.6 - w, 0.0); d.x = dot(random3(s), x); d.y = dot(random3(s + i1), x1); d.z = dot(random3(s + i2), x2); d.w = dot(random3(s + 1.0), x3); w *= w; w *= w; d *= w; return dot(d, vec4(52.0)); } ",
  422. "float noise(vec3 m) { return 0.5333333*simplex3d(m) +0.2666667*simplex3d(2.0*m) +0.1333333*simplex3d(4.0*m) +0.0666667*simplex3d(8.0*m); } ",
  423. "float dim(vec3 p1 , vec3 p2){ return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)+(p2.z-p1.z)*(p2.z-p1.z)); }",
  424. "vec2 rotate_xy(vec2 pr1,vec2 pr2,float alpha) {vec2 pp2 = vec2( pr2.x - pr1.x, pr2.y - pr1.y );return vec2( pr1.x + pp2.x * cos(alpha*3.14159265/180.) - pp2.y * sin(alpha*3.14159265/180.),pr1.y + pp2.x * sin(alpha*3.14159265/180.) + pp2.y * cos(alpha*3.14159265/180.));} \n vec3 r_y(vec3 n, float a,vec3 c) {vec3 c1 = vec3( c.x, c.y, c.z );c1.x = c1.x;c1.y = c1.z;vec2 p = rotate_xy(vec2(c1.x,c1.y), vec2( n.x, n.z ), a);n.x = p.x;n.z = p.y;return n; } \n vec3 r_x(vec3 n, float a,vec3 c) {vec3 c1 = vec3( c.x, c.y, c.z );c1.x = c1.y;c1.y = c1.z;vec2 p = rotate_xy(vec2(c1.x,c1.y), vec2( n.y, n.z ), a);n.y = p.x;n.z = p.y;return n; } \n vec3 r_z(vec3 n, float a,vec3 c) { vec3 c1 = vec3( c.x, c.y, c.z );vec2 p = rotate_xy(vec2(c1.x,c1.y), vec2( n.x, n.y ), a);n.x = p.x;n.y = p.y;return n; }",
  425. //"vec3 sundir(float da,float db,vec3 ps){ float h = floor(floor(" + ShaderMaterialHelperStatics.GlobalTime + ".y/100.)/100.);float m = floor(" + ShaderMaterialHelperStatics.GlobalTime + ".y/100.) - h*100.;float s = " + ShaderMaterialHelperStatics.GlobalTime + ".y - h*10000. -m*100.;float si = s *100./60.;float mi = m*100./60.;float hi = h+mi/100.+si/10000.;float dm = 180./(db-da); vec3 gp = vec3(ps.x,ps.y,ps.z);gp = r_z(gp, dm* hi -da*dm -90. ,vec3(0.));gp = r_x(gp,40. ,vec3(0.)); gp.x = gp.x*-1.; gp.z = gp.z*-1.; return gp; }",
  426. ])
  427. this.Vertex.push(sresult);
  428. this.Fragment.push(sresult);
  429. }
  430. this.Vertex.push("void main(void) { \n\
  431. "+ ShaderMaterialHelperStatics.Position + " = " + ShaderMaterialHelperStatics.AttrPosition + "; \n\
  432. " + ShaderMaterialHelperStatics.Normal + " = " + ShaderMaterialHelperStatics.AttrNormal + "; \n\
  433. vec4 result = vec4(" + ShaderMaterialHelperStatics.Position + ",1.); \n\
  434. #[Source] \n\
  435. gl_Position = worldViewProjection * result;\n\
  436. vuv = uv;\n\
  437. #[AfterFinishVertex] \n\
  438. }");
  439. // start Build Fragment Frame
  440. if (this.Setting.NormalMap != null) {
  441. this.Fragment.push("vec3 normalMap() { vec4 result = vec4(0.); " + this.Setting.NormalMap + "; \n\
  442. result = vec4( normalize( "+ this.Setting.Normal + " -(normalize(result.xyz)*2.0-vec3(1.))*(max(-0.5,min(0.5," + Shader.Print(this.Setting.NormalOpacity) + ")) )),1.0); return result.xyz;}");
  443. }
  444. if (this.Setting.SpecularMap != null) {
  445. this.Fragment.push("float specularMap() { vec4 result = vec4(0.);float float_result = 0.; " + this.Setting.SpecularMap + "; return float_result ;}");
  446. }
  447. this.Fragment.push(this.FragmentBeforeMain);
  448. this.Fragment.push(" \n\
  449. void main(void) { \n\
  450. int discardState = 0;\n\
  451. vec4 result = vec4(0.);\n\
  452. #[Source] \n\
  453. if(discardState == 0)gl_FragColor = result; \n\
  454. }");
  455. }
  456. PrepareMaterial(material: any, scene: any) {
  457. material.ShaderSetting =
  458. this.Setting;
  459. if (!this.Setting.Transparency) {
  460. material.needAlphaBlending = function () { return false; };
  461. }
  462. else {
  463. material.needAlphaBlending = function () { return true; };
  464. };
  465. if (!this.Setting.Back) this.Setting.Back = false;
  466. material.needAlphaTesting = function () { return true; };
  467. material.setVector3("camera", { x: 18., y: 18., z: 18. });
  468. material.backFaceCulling = !this.Setting.Back;
  469. material.wireframe = this.Setting.Wire;
  470. material.setFlags = function (flags: string) {
  471. if (this.ShaderSetting.Flags) {
  472. var s = 0.;
  473. for (var i = 0; i < 20; i++) {
  474. if (flags.length > i && flags[i] == '1')
  475. s += Math.pow(2., i);
  476. }
  477. this.flagNumber = s;
  478. this.setFloat(ShaderMaterialHelperStatics.uniformFlags, s);
  479. }
  480. }
  481. material.flagNumber = 0.;
  482. material.flagUp = function (flag: number) {
  483. if (this.ShaderSetting.Flags) {
  484. if (Math.floor((this.flagNumber / Math.pow(2., flag) % 2.)) != 1.)
  485. this.flagNumber += Math.pow(2., flag);
  486. this.setFloat(ShaderMaterialHelperStatics.uniformFlags, this.flagNumber);
  487. }
  488. }
  489. material.flagDown = function (flag: number) {
  490. if (this.ShaderSetting.Flags) {
  491. if (Math.floor((this.flagNumber / Math.pow(2., flag) % 2.)) == 1.)
  492. this.flagNumber -= Math.pow(2., flag);
  493. this.setFloat(ShaderMaterialHelperStatics.uniformFlags, this.flagNumber);
  494. }
  495. }
  496. material.onCompiled = function () {
  497. }
  498. if (this.Setting.Texture2Ds != null) {
  499. for (var s in this.Setting.Texture2Ds) {
  500. // setTexture2D
  501. var texture = new ShaderMaterialHelper().DefineTexture(this.Setting.Texture2Ds[s].key, scene);
  502. material.setTexture(ShaderMaterialHelperStatics.Texture2D + s, texture);
  503. }
  504. }
  505. if (this.Setting.TextureCubes != null) {
  506. for (var s in this.Setting.TextureCubes) {
  507. // setTexture2D
  508. var texture = new ShaderMaterialHelper().DefineCubeTexture(this.Setting.TextureCubes[s].key, scene);
  509. material.setTexture(ShaderMaterialHelperStatics.TextureCube + s, texture);
  510. material.setMatrix(ShaderMaterialHelperStatics.ReflectMatrix, texture.getReflectionTextureMatrix());
  511. }
  512. }
  513. Shader.Me = null;
  514. return material;
  515. }
  516. Build() {
  517. Shader.Me.Parent.Setting = Shader.Me.Setting;
  518. Shader.Me = Shader.Me.Parent;
  519. return this.Body;
  520. }
  521. BuildMaterial(scene) {
  522. this.PrepareBeforeMaterialBuild(scene);
  523. if (Shader.ShaderIdentity == null) Shader.ShaderIdentity = 0;
  524. Shader.ShaderIdentity++;
  525. var shaderMaterial = new ShaderMaterialHelper().ShaderMaterial("ShaderBuilder_" + Shader.ShaderIdentity, scene, {
  526. Pixel: Shader.Join(this.Fragment)
  527. .replace("#[Source]", this.Body),
  528. Vertex: Shader.Join(this.Vertex)
  529. .replace("#[Source]", Shader.Def(this.VertexBody, ""))
  530. .replace("#[AfterFinishVertex]", Shader.Def(this.AfterVertex, ""))
  531. }, {
  532. uniforms: this.Uniforms,
  533. attributes: this.Attributes
  534. });
  535. Shader.Indexer = 1;
  536. return this.PrepareMaterial(shaderMaterial, scene);
  537. }
  538. Event(index: number, mat: string) {
  539. Shader.Me.Setting.Flags = true;
  540. Shader.Indexer++;
  541. this.Body = Shader.Def(this.Body, "");
  542. this.Body += " if ( floor(mod( " + ShaderMaterialHelperStatics.uniformFlags + "/pow(2.," + Shader.Print(index) + "),2.)) == 1.) { " + mat + " } ";
  543. return this;
  544. }
  545. EventVertex(index: number, mat: string) {
  546. Shader.Me.Setting.Flags = true;
  547. Shader.Me.Setting.Vertex = true;
  548. Shader.Indexer++;
  549. this.VertexBody = Shader.Def(this.VertexBody, "");
  550. this.VertexBody += " if( floor(mod( " + ShaderMaterialHelperStatics.uniformFlags + "/pow(2.," + Shader.Print(index) + "),2.)) == 1. ){ " + mat + "}";
  551. return this;
  552. }
  553. Transparency() {
  554. Shader.Me.Setting.Transparency = true;
  555. return this;
  556. }
  557. Wired() {
  558. Shader.Me.Setting.Wire = true;
  559. return this;
  560. }
  561. VertexShader(mat) {
  562. this.VertexBody = Shader.Def(this.VertexBody, "");
  563. this.VertexBody += mat;
  564. return this;
  565. }
  566. Solid(color: IColor) {
  567. color = Shader.Def(color, { r: 0., g: 0., b: 0., a: 1. });
  568. color.a = Shader.Def(color.a, 1.);
  569. color.r = Shader.Def(color.r, 0.);
  570. color.g = Shader.Def(color.g, 0.);
  571. color.b = Shader.Def(color.b, 0.);
  572. this.Body = Shader.Def(this.Body, "");
  573. this.Body += " result = vec4(" + Shader.Print(color.r) + "," + Shader.Print(color.g) + "," + Shader.Print(color.b) + "," + Shader.Print(color.a) + ");";
  574. return this;
  575. }
  576. GetMapIndex(key: string): number {
  577. if (Shader.Me.Setting.Texture2Ds != null) {
  578. for (var it in Shader.Me.Setting.Texture2Ds) {
  579. if (this.Setting.Texture2Ds[it].key == key) {
  580. return it;
  581. }
  582. }
  583. }
  584. else
  585. Shader.Me.Setting.Texture2Ds = [];
  586. return -1;
  587. }
  588. GetCubeMapIndex(key: string): number {
  589. if (Shader.Me.Setting.TextureCubes != null) {
  590. for (var it in Shader.Me.Setting.TextureCubes) {
  591. if (this.Setting.TextureCubes[it].key == key) {
  592. return it;
  593. }
  594. }
  595. }
  596. else
  597. Shader.Me.Setting.TextureCubes = [];
  598. return -1;
  599. }
  600. Map(option: IMap) {
  601. Shader.Indexer++;
  602. option = Shader.Def(option, { path: '/images/color.png' });
  603. var s = Shader.Me.GetMapIndex(option.path);
  604. if (s == -1) {
  605. Shader.Me.Setting.Texture2Ds.push({ key: option.path, inVertex: option.useInVertex, inFragment: true });
  606. } else {
  607. Shader.Me.Setting.Texture2Ds[s].inVertex = true;
  608. }
  609. s = Shader.Me.GetMapIndex(option.path);
  610. Shader.Me.Setting.Center = true;
  611. Shader.Me.Setting.Helpers = true;
  612. Shader.Me.Setting.Uv = true;
  613. option.normal = Shader.Def(option.normal, Normals.Map);
  614. option.alpha = Shader.Def(option.alpha, false);
  615. option.bias = Shader.Def(option.bias, "0.");
  616. option.normalLevel = Shader.Def(option.normalLevel, 1.0);
  617. option.path = Shader.Def(option.path, "qa.jpg");
  618. option.rotation = Shader.Def(option.rotation, { x: 0, y: 0, z: 0 });
  619. option.scaleX = Shader.Def(option.scaleX, 1.);
  620. option.scaleY = Shader.Def(option.scaleY, 1.);
  621. option.useInVertex = Shader.Def(option.useInVertex, false);
  622. option.x = Shader.Def(option.x, 0.0);
  623. option.y = Shader.Def(option.y, 0.0);
  624. option.uv = Shader.Def(option.uv, ShaderMaterialHelperStatics.Uv);
  625. option.animation = Shader.Def(option.animation, false);
  626. option.tiled = Shader.Def(option.tiled, false);
  627. option.columnIndex = Shader.Def(option.columnIndex, 1);
  628. option.rowIndex = Shader.Def(option.rowIndex, 1);
  629. option.animationSpeed = Shader.Def(option.animationSpeed, 2000);
  630. option.animationFrameEnd = Shader.Def(option.animationFrameEnd, 100) + option.indexCount;
  631. option.animationFrameStart = Shader.Def(option.animationFrameStart, 0) + option.indexCount;
  632. option.indexCount = Shader.Def(option.indexCount, 1);
  633. var frameLength = Math.min(option.animationFrameEnd - option.animationFrameStart, option.indexCount * option.indexCount);
  634. var uv = Shader.Def(option.uv, ShaderMaterialHelperStatics.Uv);
  635. if (option.uv == "planar") {
  636. uv = ShaderMaterialHelperStatics.Position;
  637. }
  638. else {
  639. uv = 'vec3(' + option.uv + '.x,' + option.uv + '.y,0.)';
  640. }
  641. option.scaleX /= option.indexCount;
  642. option.scaleY /= option.indexCount;
  643. var rotate = ["vec3 centeri#[Ind] = " + ShaderMaterialHelperStatics.Center + ";",
  644. "vec3 ppo#[Ind] = r_z( " + uv + "," + Shader.Print(option.rotation.x) + ",centeri#[Ind]); ",
  645. " ppo#[Ind] = r_y( ppo#[Ind]," + Shader.Print(option.rotation.y) + ",centeri#[Ind]); ",
  646. " ppo#[Ind] = r_x( ppo#[Ind]," + Shader.Print(option.rotation.x) + ",centeri#[Ind]); ",
  647. "vec3 nrm#[Ind] = r_z( " + option.normal + "," + Shader.Print(option.rotation.x) + ",centeri#[Ind]); ",
  648. " nrm#[Ind] = r_y( nrm#[Ind]," + Shader.Print(option.rotation.y) + ",centeri#[Ind]); ",
  649. " nrm#[Ind] = r_x( nrm#[Ind]," + Shader.Print(option.rotation.z) + ",centeri#[Ind]); "].join("\n\
  650. ");
  651. var sresult = Shader.Join([rotate,
  652. " vec4 color#[Ind] = texture2D(" +
  653. ShaderMaterialHelperStatics.Texture2D + s + " ,ppo#[Ind].xy*vec2(" +
  654. Shader.Print(option.scaleX) + "," + Shader.Print(option.scaleY) + ")+vec2(" +
  655. Shader.Print(option.x) + "," + Shader.Print(option.y) + ")" +
  656. (option.bias != null ? "," + Shader.Print(option.bias) : "") + ");",
  657. " if(nrm#[Ind].z < " + Shader.Print(option.normalLevel) + "){ ",
  658. (option.alpha ? " result = color#[Ind];" : "result = vec4(color#[Ind].rgb , 1.); "),
  659. "}"]);
  660. if (option.indexCount > 1 || option.tiled) {
  661. option.columnIndex = option.indexCount - option.columnIndex + 1.0;
  662. sresult = [
  663. " vec3 uvt#[Ind] = vec3(" + uv + ".x*" + Shader.Print(option.scaleX) + "+" + Shader.Print(option.x) + "," + uv + ".y*" + Shader.Print(option.scaleY) + "+" + Shader.Print(option.y) + ",0.0); ",
  664. " ",
  665. " float xst#[Ind] = 1./(" + Shader.Print(option.indexCount) + "*2.); ",
  666. " float yst#[Ind] =1./(" + Shader.Print(option.indexCount) + "*2.); ",
  667. " float xs#[Ind] = 1./" + Shader.Print(option.indexCount) + "; ",
  668. " float ys#[Ind] = 1./" + Shader.Print(option.indexCount) + "; ",
  669. " float yid#[Ind] = " + Shader.Print(option.columnIndex - 1.0) + " ; ",
  670. " float xid#[Ind] = " + Shader.Print(option.rowIndex - 1.0) + "; ",
  671. option.animation ? " float ind_a#[Ind] = floor(mod(time*0.001*" + Shader.Print(option.animationSpeed) + ", " + Shader.Print(frameLength) + " )+" + Shader.Print(option.animationFrameStart) + ");" +
  672. " yid#[Ind] = " + Shader.Print(option.indexCount) + "- floor(ind_a#[Ind] / " + Shader.Print(option.indexCount) + ");" +
  673. " xid#[Ind] = floor(mod(ind_a#[Ind] , " + Shader.Print(option.indexCount) + ")); "
  674. : "",
  675. " float xi#[Ind] = mod(uvt#[Ind].x ,xs#[Ind])+xs#[Ind]*xid#[Ind] ; ",
  676. " float yi#[Ind] = mod(uvt#[Ind].y ,ys#[Ind])+ys#[Ind]*yid#[Ind] ; ",
  677. " ",
  678. " float xi2#[Ind] = mod(uvt#[Ind].x -xs#[Ind]*0.5 ,xs#[Ind])+xs#[Ind]*xid#[Ind] ; ",
  679. " float yi2#[Ind] = mod(uvt#[Ind].y -ys#[Ind]*0.5,ys#[Ind])+ys#[Ind]*yid#[Ind] ; ",
  680. " ",
  681. " ",
  682. " vec4 f#[Ind] = texture2D(" + ShaderMaterialHelperStatics.Texture2D + s + ",vec2(xi#[Ind],yi#[Ind])) ; ",
  683. " result = f#[Ind] ; ",
  684. (option.tiled ? [" vec4 f2#[Ind] = texture2D(" + ShaderMaterialHelperStatics.Texture2D + s + ",vec2(xi2#[Ind]+xid#[Ind] ,yi#[Ind])) ; ",
  685. " vec4 f3#[Ind] = texture2D(" + ShaderMaterialHelperStatics.Texture2D + s + ",vec2(xi#[Ind],yi2#[Ind]+yid#[Ind])) ; ",
  686. " vec4 f4#[Ind] = texture2D(" + ShaderMaterialHelperStatics.Texture2D + s + ",vec2(xi2#[Ind]+xid#[Ind],yi2#[Ind]+yid#[Ind])) ; ",
  687. " ",
  688. " ",
  689. " float ir#[Ind] = 0.,ir2#[Ind] = 0.; ",
  690. " ",
  691. " if( yi2#[Ind] >= yid#[Ind] *ys#[Ind] ){ ",
  692. " ir2#[Ind] = min(2.,max(0.,( yi2#[Ind]-yid#[Ind] *ys#[Ind])*2.0/ys#[Ind] )) ; ",
  693. " if(ir2#[Ind] > 1.0) ir2#[Ind] =1.0-(ir2#[Ind]-1.0); ",
  694. " ir2#[Ind] = min(1.0,max(0.0,pow(ir2#[Ind]," + Shader.Print(15.) + " )*" + Shader.Print(3.) + ")); ",
  695. " result = result *(1.0-ir2#[Ind]) +f3#[Ind]*ir2#[Ind] ; ",
  696. " } ",
  697. " if( xi2#[Ind] >= xid#[Ind] *xs#[Ind] ){ ",
  698. " ir2#[Ind] = min(2.,max(0.,( xi2#[Ind]-xid#[Ind] *xs#[Ind])*2.0/xs#[Ind] )) ; ",
  699. " if(ir2#[Ind] > 1.0) ir2#[Ind] =1.0-(ir2#[Ind]-1.0); ",
  700. " ir2#[Ind] = min(1.0,max(0.0,pow(ir2#[Ind]," + Shader.Print(15.) + " )*" + Shader.Print(3.) + ")); ",
  701. " result = result *(1.0-ir2#[Ind]) +f2#[Ind]*ir2#[Ind] ; ",
  702. " } ",
  703. " if( xi2#[Ind] >= xid#[Ind] *xs#[Ind] && xi2#[Ind] >= xid#[Ind] *xs#[Ind] ){ ",
  704. " ir2#[Ind] = min(2.,max(0.,( xi2#[Ind]-xid#[Ind] *xs#[Ind])*2.0/xs#[Ind] )) ; ",
  705. " float ir3#[Ind] = min(2.,max(0.,( yi2#[Ind]-yid#[Ind] *ys#[Ind])*2.0/ys#[Ind] )) ; ",
  706. " if(ir2#[Ind] > 1.0) ir2#[Ind] =1.0-(ir2#[Ind]-1.0); ",
  707. " if(ir3#[Ind] > 1.0) ir3#[Ind] =1.0-(ir3#[Ind]-1.0); ",
  708. " ir2#[Ind] = min(1.0,max(0.0,pow(ir2#[Ind]," + Shader.Print(15.) + " )*" + Shader.Print(3.) + ")); ",
  709. " ir3#[Ind] = min(1.0,max(0.0,pow(ir3#[Ind]," + Shader.Print(15.) + " )*" + Shader.Print(3.) + ")); ",
  710. " ir2#[Ind] = min(1.0,max(0.0, ir2#[Ind]* ir3#[Ind] )); ",
  711. " if(nrm#[Ind].z < " + Shader.Print(option.normalLevel) + "){ ",
  712. (option.alpha ? " result = result *(1.0-ir2#[Ind]) +f4#[Ind]* ir2#[Ind] ;" : " result = vec4(result.xyz*(1.0-ir2#[Ind]) +f4#[Ind].xyz* ir2#[Ind] ,1.0); "),
  713. "}",
  714. " } "
  715. ].join("\n") : "")].join("\n");
  716. }
  717. sresult = Shader.Replace(sresult, '#[Ind]', "_" + Shader.Indexer + "_");
  718. this.Body = Shader.Def(this.Body, "");
  719. this.Body += sresult;
  720. return this;
  721. }
  722. Multi(mats: any[], combine: boolean) {
  723. combine = Shader.Def(combine, true);
  724. Shader.Indexer++;
  725. var pre = "", ps = ["", "", "", ""], psh = "0.0";
  726. for (var i = 0; i < mats.length; i++) {
  727. if (mats[i].result == undefined || mats[i].result == null) mats[i] = { result: mats[i], opacity: 1.0 };
  728. pre += " vec4 result#[Ind]" + i + ";result#[Ind]" + i + " = vec4(0.,0.,0.,0.); float rp#[Ind]" + i + " = " + Shader.Print(mats[i].opacity) + "; \n\
  729. ";
  730. pre += mats[i].result + "\n\
  731. ";
  732. pre += " result#[Ind]" + i + " = result; \n\
  733. ";
  734. ps[0] += (i == 0 ? "" : " + ") + "result#[Ind]" + i + ".x*rp#[Ind]" + i;
  735. ps[1] += (i == 0 ? "" : " + ") + "result#[Ind]" + i + ".y*rp#[Ind]" + i;
  736. ps[2] += (i == 0 ? "" : " + ") + "result#[Ind]" + i + ".z*rp#[Ind]" + i;
  737. ps[3] += (i == 0 ? "" : " + ") + "result#[Ind]" + i + ".w*rp#[Ind]" + i;
  738. psh += "+" + Shader.Print(mats[i].opacity);
  739. }
  740. if (combine) {
  741. ps[0] = "(" + ps[0] + ")/(" + Shader.Print(psh) + ")";
  742. ps[1] = "(" + ps[1] + ")/(" + Shader.Print(psh) + ")";
  743. ps[2] = "(" + ps[2] + ")/(" + Shader.Print(psh) + ")";
  744. ps[3] = "(" + ps[3] + ")/(" + Shader.Print(psh) + ")";
  745. }
  746. pre += "result = vec4(" + ps[0] + "," + ps[1] + "," + ps[2] + "," + ps[3] + ");";
  747. this.Body = Shader.Def(this.Body, "");
  748. this.Body += Shader.Replace(pre, "#[Ind]", "_" + Shader.Indexer + "_");
  749. return this;
  750. }
  751. Back(mat: string) {
  752. Shader.Me.Setting.Back = true;
  753. mat = Shader.Def(mat, '');
  754. this.Body = Shader.Def(this.Body, "");
  755. this.Body += 'if(' + ShaderMaterialHelperStatics.face_back + '){' + mat + ';}';
  756. return this;
  757. }
  758. InLine(mat: string) {
  759. mat = Shader.Def(mat, '');
  760. this.Body = Shader.Def(this.Body, "");
  761. this.Body += mat;
  762. return this;
  763. }
  764. Front(mat: string) {
  765. mat = Shader.Def(mat, '');
  766. this.Body = Shader.Def(this.Body, "");
  767. this.Body += 'if(' + ShaderMaterialHelperStatics.face_front + '){' + mat + ';}';
  768. return this;
  769. }
  770. Range(mat1: string, mat2: string, option: IRange) {
  771. Shader.Indexer++;
  772. var k = Shader.Indexer;
  773. option.start = Shader.Def(option.start, 0.);
  774. option.end = Shader.Def(option.end, 1.);
  775. option.direction = Shader.Def(option.direction, ShaderMaterialHelperStatics.Position + '.y');
  776. var sresult = [
  777. "float s_r_dim#[Ind] = " + option.direction + ";",
  778. "if(s_r_dim#[Ind] > " + Shader.Print(option.end) + "){",
  779. mat2,
  780. "}",
  781. "else { ",
  782. mat1,
  783. " vec4 mat1#[Ind]; mat1#[Ind] = result;",
  784. " if(s_r_dim#[Ind] > " + Shader.Print(option.start) + "){ ",
  785. mat2,
  786. " vec4 mati2#[Ind];mati2#[Ind] = result;",
  787. " float s_r_cp#[Ind] = (s_r_dim#[Ind] - (" + Shader.Print(option.start) + "))/(" + Shader.Print(option.end) + "-(" + Shader.Print(option.start) + "));",
  788. " float s_r_c#[Ind] = 1.0 - s_r_cp#[Ind];",
  789. " result = vec4(mat1#[Ind].x*s_r_c#[Ind]+mati2#[Ind].x*s_r_cp#[Ind],mat1#[Ind].y*s_r_c#[Ind]+mati2#[Ind].y*s_r_cp#[Ind],mat1#[Ind].z*s_r_c#[Ind]+mati2#[Ind].z*s_r_cp#[Ind],mat1#[Ind].w*s_r_c#[Ind]+mati2#[Ind].w*s_r_cp#[Ind]);",
  790. " }",
  791. " else { result = mat1#[Ind]; }",
  792. "}"
  793. ].join('\n\
  794. ');
  795. sresult = Shader.Replace(sresult, '#[Ind]', "_" + Shader.Indexer + "_");
  796. this.Body = Shader.Def(this.Body, "");
  797. this.Body += sresult;
  798. return this;
  799. }
  800. Reference(index: number, mat: any) {
  801. if (Shader.Me.References == null) Shader.Me.References = "";
  802. var sresult = "vec4 resHelp#[Ind] = result;";
  803. if (Shader.Me.References.indexOf("," + index + ",") == -1) {
  804. Shader.Me.References += "," + index + ",";
  805. sresult += " vec4 result_" + index + " = vec4(0.);\n\
  806. ";
  807. }
  808. if (mat == null) {
  809. sresult += " result_" + index + " = result;";
  810. }
  811. else {
  812. sresult += mat + "\n\
  813. result_" + index + " = result;";
  814. }
  815. sresult += "result = resHelp#[Ind] ;";
  816. sresult = Shader.Replace(sresult, '#[Ind]', "_" + Shader.Indexer + "_");
  817. this.Body = Shader.Def(this.Body, "");
  818. this.Body += sresult;
  819. return this;
  820. }
  821. ReplaceColor(index: number, color: number, mat: string, option: IReplaceColor) {
  822. Shader.Indexer++;
  823. option = Shader.Def(option, {});
  824. var d = Shader.Def(option.rangeStep, -0.280);
  825. var d2 = Shader.Def(option.rangePower, 0.0);
  826. var d3 = Shader.Def(option.colorIndex, 0.0);
  827. var d4 = Shader.Def(option.colorStep, 1.0);
  828. var ilg = Shader.Def(option.indexToEnd, false);
  829. var lg = " > 0.5 + " + Shader.Print(d) + " ";
  830. var lw = " < 0.5 - " + Shader.Print(d) + " ";
  831. var rr = "((result_" + index + ".x*" + Shader.Print(d4) + "-" + Shader.Print(d3) + ")>1.0 ? 0. : max(0.,(result_" + index + ".x*" + Shader.Print(d4) + "-" + Shader.Print(d3) + ")))";
  832. var rg = "((result_" + index + ".y*" + Shader.Print(d4) + "-" + Shader.Print(d3) + ")>1.0 ? 0. : max(0.,(result_" + index + ".y*" + Shader.Print(d4) + "-" + Shader.Print(d3) + ")))";
  833. var rb = "((result_" + index + ".z*" + Shader.Print(d4) + "-" + Shader.Print(d3) + ")>1.0 ? 0. : max(0.,(result_" + index + ".z*" + Shader.Print(d4) + "-" + Shader.Print(d3) + ")))";
  834. if (ilg) {
  835. rr = "min(1.0, max(0.,(result_" + index + ".x*" + Shader.Print(d4) + "-" + Shader.Print(d3) + ")))";
  836. rg = "min(1.0, max(0.,(result_" + index + ".y*" + Shader.Print(d4) + "-" + Shader.Print(d3) + ")))";
  837. rb = "min(1.0, max(0.,(result_" + index + ".z*" + Shader.Print(d4) + "-" + Shader.Print(d3) + ")))";
  838. }
  839. var a = " && ";
  840. var p = " + ";
  841. var r = "";
  842. var cond = "";
  843. switch (color) {
  844. case Helper.White: cond = rr + lg + a + rg + lg + a + rb + lg; r = "(" + rr + p + rg + p + rb + ")/3.0"; break;
  845. case Helper.Cyan: cond = rr + lw + a + rg + lg + a + rb + lg; r = "(" + rg + p + rb + ")/2.0 - (" + rr + ")/1.0"; break;
  846. case Helper.Pink: cond = rr + lg + a + rg + lw + a + rb + lg; r = "(" + rr + p + rb + ")/2.0 - (" + rg + ")/1.0"; break;
  847. case Helper.Yellow: cond = rr + lg + a + rg + lg + a + rb + lw; r = "(" + rr + p + rg + ")/2.0 - (" + rb + ")/1.0"; break;
  848. case Helper.Blue: cond = rr + lw + a + rg + lw + a + rb + lg; r = "(" + rb + ")/1.0 - (" + rr + p + rg + ")/2.0"; break;
  849. case Helper.Red: cond = rr + lg + a + rg + lw + a + rb + lw; r = "(" + rr + ")/1.0 - (" + rg + p + rb + ")/2.0"; break;
  850. case Helper.Green: cond = rr + lw + a + rg + lg + a + rb + lw; r = "(" + rg + ")/1.0 - (" + rr + p + rb + ")/2.0"; break;
  851. case Helper.Black: cond = rr + lw + a + rg + lw + a + rb + lw; r = "1.0-(" + rr + p + rg + p + rb + ")/3.0"; break;
  852. }
  853. var sresult = " if( " + cond + " ) { vec4 oldrs#[Ind] = vec4(result);float al#[Ind] = max(0.0,min(1.0," + r + "+(" + Shader.Print(d2) + "))); float l#[Ind] = 1.0-al#[Ind]; " + mat + " result = result*al#[Ind] + oldrs#[Ind] * l#[Ind]; }";
  854. sresult = Shader.Replace(sresult, '#[Ind]', "_" + Shader.Indexer + "_");
  855. this.Body = Shader.Def(this.Body, "");
  856. this.Body += sresult;
  857. return this;
  858. }
  859. Blue(index: number, mat: string, option: IReplaceColor) {
  860. return this.ReplaceColor(index, Helper.Blue, mat, option);
  861. }
  862. Cyan(index: number, mat: string, option: IReplaceColor) {
  863. return this.ReplaceColor(index, Helper.Cyan, mat, option);
  864. }
  865. Red(index: number, mat: string, option: IReplaceColor) {
  866. return this.ReplaceColor(index, Helper.Red, mat, option);
  867. }
  868. Yellow(index: number, mat: string, option: IReplaceColor) {
  869. return this.ReplaceColor(index, Helper.Yellow, mat, option);
  870. }
  871. Green(index: number, mat: string, option: IReplaceColor) {
  872. return this.ReplaceColor(index, Helper.Green, mat, option);
  873. }
  874. Pink(index: number, mat: string, option: IReplaceColor) {
  875. return this.ReplaceColor(index, Helper.Pink, mat, option);
  876. }
  877. White(index: number, mat: string, option: IReplaceColor) {
  878. return this.ReplaceColor(index, Helper.White, mat, option);
  879. }
  880. Black(index: number, mat: string, option: IReplaceColor) {
  881. return this.ReplaceColor(index, Helper.Black, mat, option);
  882. }
  883. ReflectCube(option: IReflectMap) {
  884. Shader.Indexer++;
  885. option = Shader.Def(option, { path: '/images/cube/a' });
  886. var s = Shader.Me.GetCubeMapIndex(option.path);
  887. if (s == -1) {
  888. Shader.Me.Setting.TextureCubes.push({ key: option.path, inVertex: option.useInVertex, inFragment: true });
  889. } else {
  890. Shader.Me.Setting.TextureCubes[s].inVertex = true;
  891. }
  892. s = Shader.Me.GetCubeMapIndex(option.path);
  893. option.normal = Shader.Def(option.normal, Normals.Map);
  894. option.alpha = Shader.Def(option.alpha, false);
  895. option.bias = Shader.Def(option.bias, "0.");
  896. option.normalLevel = Shader.Def(option.normalLevel, 1.0);
  897. option.rotation = Shader.Def(option.rotation, { x: 0, y: 0, z: 0 });
  898. option.scaleX = Shader.Def(option.scaleX, 1.);
  899. option.scaleY = Shader.Def(option.scaleY, 1.);
  900. option.useInVertex = Shader.Def(option.useInVertex, false);
  901. option.x = Shader.Def(option.x, 0.0);
  902. option.y = Shader.Def(option.y, 0.0);
  903. option.uv = Shader.Def(option.uv, ShaderMaterialHelperStatics.Uv);
  904. option.reflectMap = Shader.Def(option.reflectMap, "1.");
  905. Shader.Me.Setting.Center = true;
  906. Shader.Me.Setting.Camera = true;
  907. Shader.Me.Setting.ReflectMatrix = true;
  908. var sresult = "";
  909. if (option.equirectangular) {
  910. option.path = Shader.Def(option.path, '/images/cube/roofl1.jpg');
  911. var s = Shader.Me.GetMapIndex(option.path);
  912. if (s == -1) {
  913. Shader.Me.Setting.Texture2Ds.push({ key: option.path, inVertex: option.useInVertex, inFragment: true });
  914. } else {
  915. Shader.Me.Setting.Texture2Ds[s].inVertex = true;
  916. }
  917. s = Shader.Me.GetMapIndex(option.path);
  918. Shader.Me.Setting.VertexWorld = true;
  919. Shader.Me.Setting.FragmentWorld = true;
  920. sresult = ' vec3 nWorld#[Ind] = normalize( mat3( world[0].xyz, world[1].xyz, world[2].xyz ) * ' + option.normal + '); ' +
  921. ' vec3 vReflect#[Ind] = normalize( reflect( normalize( ' + ShaderMaterialHelperStatics.Camera + '- vec3(world * vec4(' + ShaderMaterialHelperStatics.Position + ', 1.0))), nWorld#[Ind] ) ); ' +
  922. 'float yaw#[Ind] = .5 - atan( vReflect#[Ind].z, -1.* vReflect#[Ind].x ) / ( 2.0 * 3.14159265358979323846264); ' +
  923. ' float pitch#[Ind] = .5 - atan( vReflect#[Ind].y, length( vReflect#[Ind].xz ) ) / ( 3.14159265358979323846264); ' +
  924. ' vec3 color#[Ind] = texture2D( ' + ShaderMaterialHelperStatics.Texture2D + s + ', vec2( yaw#[Ind], pitch#[Ind]),' + Shader.Print(option.bias) + ' ).rgb; result = vec4(color#[Ind] ,1.);';
  925. }
  926. else {
  927. option.path = Shader.Def(option.path, "/images/cube/a");
  928. sresult = [
  929. "vec3 viewDir#[Ind] = " + ShaderMaterialHelperStatics.Position + " - " + ShaderMaterialHelperStatics.Camera + " ;",
  930. " viewDir#[Ind] =r_x(viewDir#[Ind] ," + Shader.Print(option.rotation.x) + ", " + ShaderMaterialHelperStatics.Center + ");",
  931. " viewDir#[Ind] =r_y(viewDir#[Ind] ," + Shader.Print(option.rotation.y) + "," + ShaderMaterialHelperStatics.Center + ");",
  932. " viewDir#[Ind] =r_z(viewDir#[Ind] ," + Shader.Print(option.rotation.z) + "," + ShaderMaterialHelperStatics.Center + ");",
  933. "vec3 coords#[Ind] = " + (option.refract ? "refract" : "reflect") + "(viewDir#[Ind]" + (option.revers ? "*vec3(1.0)" : "*vec3(-1.0)") + ", " + option.normal + " " + (option.refract ? ",(" + Shader.Print(option.refractMap) + ")" : "") + " )+" + ShaderMaterialHelperStatics.Position + "; ",
  934. "vec3 vReflectionUVW#[Ind] = vec3( " + ShaderMaterialHelperStatics.ReflectMatrix + " * vec4(coords#[Ind], 0)); ",
  935. "vec3 rc#[Ind]= textureCube(" +
  936. ShaderMaterialHelperStatics.TextureCube + s + ", vReflectionUVW#[Ind]," + Shader.Print(option.bias) + ").rgb;",
  937. "result =result + vec4(rc#[Ind].x ,rc#[Ind].y,rc#[Ind].z, " + (!option.alpha ? "1." : "(rc#[Ind].x+rc#[Ind].y+rc#[Ind].z)/3.0 ") + ")*(min(1.,max(0.," + Shader.Print(option.reflectMap) + "))); "
  938. ].join('\n\
  939. ');
  940. }
  941. sresult = Shader.Replace(sresult, '#[Ind]', "_" + Shader.Indexer + "_");
  942. this.Body = Shader.Def(this.Body, "");
  943. this.Body += sresult;
  944. return this;
  945. }
  946. NormalMap(val: string, mat: string) {
  947. Shader.Me.Setting.NormalOpacity = val;
  948. Shader.Me.Setting.NormalMap = mat;
  949. return this;
  950. }
  951. SpecularMap(mat: string) {
  952. Shader.Me.Setting.SpecularMap = mat;
  953. return this;
  954. }
  955. Instance() {
  956. var setting = Shader.Me.Setting;
  957. var instance = new ShaderBuilder();
  958. instance.Parent = Shader.Me;
  959. instance.Setting = setting;
  960. return instance;
  961. }
  962. Reflect(option: IReflectMap, opacity: number) {
  963. opacity = Shader.Def(opacity, 1.);
  964. return this.Multi(["result = result;", { result: this.Instance().ReflectCube(option).Build(), opacity: opacity }], true);
  965. }
  966. Light(option: ILight) {
  967. option = Shader.Def(option, {});
  968. option.color = Shader.Def(option.color, { r: 1., g: 1., b: 1., a: 1. });
  969. option.darkColorMode = Shader.Def(option.darkColorMode, false);
  970. option.direction = Shader.Def(option.direction, "vec3(sin(time*0.02)*28.,sin(time*0.02)*8.+10.,cos(time*0.02)*28.)");
  971. option.normal = Shader.Def(option.normal, Normals.Map);
  972. option.rotation = Shader.Def(option.rotation, { x: 0., y: 0., z: 0. });
  973. option.specular = Shader.Def(option.specular, Speculars.Map);
  974. option.specularLevel = Shader.Def(option.specularLevel, 1.);
  975. option.specularPower = Shader.Def(option.specularPower, 1.);
  976. option.phonge = Shader.Def(option.phonge, 0.);
  977. option.phongePower = Shader.Def(option.phongePower, 1.);
  978. option.phongeLevel = Shader.Def(option.phongeLevel, 1.);
  979. option.supplement = Shader.Def(option.supplement, false);
  980. option.reducer = Shader.Def(option.reducer, '1.');
  981. var c_c = option.color;
  982. if (option.darkColorMode) {
  983. c_c.a = 1.0 - c_c.a;
  984. c_c.r = 1.0 - c_c.r;
  985. c_c.g = 1.0 - c_c.g;
  986. c_c.b = 1.0 - c_c.b;
  987. c_c.a = c_c.a - 1.0;
  988. }
  989. Shader.Indexer++;
  990. Shader.Me.Setting.Camera = true;
  991. Shader.Me.Setting.FragmentWorld = true;
  992. Shader.Me.Setting.VertexWorld = true;
  993. Shader.Me.Setting.Helpers = true;
  994. Shader.Me.Setting.Center = true;
  995. var sresult = Shader.Join([
  996. " vec3 dir#[Ind] = normalize( vec3(world * vec4(" + ShaderMaterialHelperStatics.Position + ",1.)) - " + ShaderMaterialHelperStatics.Camera + ");",
  997. " dir#[Ind] =r_x(dir#[Ind] ," + Shader.Print(option.rotation.x) + ",vec3(" + ShaderMaterialHelperStatics.Center + "));",
  998. " dir#[Ind] =r_y(dir#[Ind] ," + Shader.Print(option.rotation.y) + ",vec3(" + ShaderMaterialHelperStatics.Center + "));",
  999. " dir#[Ind] =r_z(dir#[Ind] ," + Shader.Print(option.rotation.z) + ",vec3(" + ShaderMaterialHelperStatics.Center + "));",
  1000. " vec4 p1#[Ind] = vec4(" + option.direction + ",.0); ",
  1001. " vec4 c1#[Ind] = vec4(" + Shader.Print(c_c.r) + "," + Shader.Print(c_c.g) + "," + Shader.Print(c_c.b) + ",0.0); ",
  1002. " vec3 vnrm#[Ind] = normalize(vec3(world * vec4(" + option.normal + ", 0.0))); ",
  1003. " vec3 l#[Ind]= normalize(p1#[Ind].xyz " +
  1004. (!option.parallel ? "- vec3(world * vec4(" + ShaderMaterialHelperStatics.Position + ",1.)) " : "")
  1005. + "); ",
  1006. " vec3 vw#[Ind]= normalize(camera - vec3(world * vec4(" + ShaderMaterialHelperStatics.Position + ",1.))); ",
  1007. " vec3 aw#[Ind]= normalize(vw#[Ind]+ l#[Ind]); ",
  1008. " float sc#[Ind]= max(0.,min(1., dot(vnrm#[Ind], aw#[Ind]))); ",
  1009. " sc#[Ind]= pow(sc#[Ind]*min(1.,max(0.," + Shader.Print(option.specular) + ")), (" + Shader.Print(option.specularPower * 1000.) + "))/" + Shader.Print(option.specularLevel) + " ; ",
  1010. " float ph#[Ind]= pow(" + Shader.Print(option.phonge) + "*2., (" + Shader.Print(option.phongePower) + "*0.3333))/(" + Shader.Print(option.phongeLevel) + "*3.) ; ",
  1011. " float ndl#[Ind] = max(0., dot(vnrm#[Ind], l#[Ind])); ",
  1012. " float ls#[Ind] = " + (option.supplement ? "1.0 -" : "") + "max(0.,min(1.,ndl#[Ind]*ph#[Ind]*(" + Shader.Print(option.reducer) + "))) ; ",
  1013. " result += vec4( c1#[Ind].xyz*( ls#[Ind])*" + Shader.Print(c_c.a) + " , ls#[Ind]); ",
  1014. " float ls2#[Ind] = " + (option.supplement ? "1.0 -" : "") + "max(0.,min(1., sc#[Ind]*(" + Shader.Print(option.reducer) + "))) ; ",
  1015. " result += vec4( c1#[Ind].xyz*( ls2#[Ind])*" + Shader.Print(c_c.a) + " , ls2#[Ind]); ",
  1016. ]);
  1017. sresult = Shader.Replace(sresult, '#[Ind]', "_" + Shader.Indexer + "_");
  1018. this.Body = Shader.Def(this.Body, "");
  1019. this.Body += sresult;
  1020. return this;
  1021. }
  1022. Effect(option: IEffect) {
  1023. var op = Shader.Def(option, {});
  1024. Shader.Indexer++;
  1025. var sresult = [
  1026. 'vec4 res#[Ind] = vec4(0.);',
  1027. 'res#[Ind].x = ' + (op.px ? Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(op.px, 'px', 'result.x'), 'py', 'result.y'), 'pz', 'result.z'), 'pw', 'result.w') + ';' : ' result.x;'),
  1028. 'res#[Ind].y = ' + (op.py ? Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(op.py, 'px', 'result.x'), 'py', 'result.y'), 'pz', 'result.z'), 'pw', 'result.w') + ';' : ' result.y;'),
  1029. 'res#[Ind].z = ' + (op.pz ? Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(op.pz, 'px', 'result.x'), 'py', 'result.y'), 'pz', 'result.z'), 'pw', 'result.w') + ';' : ' result.z;'),
  1030. 'res#[Ind].w = ' + (op.pw ? Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(op.pw, 'px', 'result.x'), 'py', 'result.y'), 'pz', 'result.z'), 'pw', 'result.w') + ';' : ' result.w;'),
  1031. 'res#[Ind] = ' + (op.pr ? ' vec4(' + Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(op.pr, 'pr', 'res#[Ind].x'), 'px', 'result.x'), 'py', 'result.y'), 'pz', 'result.z'), 'pw', 'result.w') + ','
  1032. + Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(op.pr, 'pr', 'res#[Ind].y'), 'px', 'result.x'), 'py', 'result.y'), 'pz', 'result.z'), 'pw', 'result.w') + ',' +
  1033. Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(op.pr, 'pr', 'res#[Ind].z'), 'px', 'result.x'), 'py', 'result.y'), 'pz', 'result.z'), 'pw', 'result.w')
  1034. + ',' +
  1035. Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(Shader.Replace(op.pr, 'pr', 'res#[Ind].w'), 'px', 'result.x'), 'py', 'result.y'), 'pz', 'result.z'), 'pw', 'result.w')
  1036. + ');' : ' res#[Ind]*1.0;'),
  1037. 'result = res#[Ind] ;'
  1038. ].join('\n\
  1039. ');
  1040. sresult = Shader.Replace(sresult, '#[Ind]', "_" + Shader.Indexer + "_");
  1041. this.Body = Shader.Def(this.Body, "");
  1042. this.Body += sresult;
  1043. return this;
  1044. }
  1045. constructor() {
  1046. this.Setting = new ShaderSetting();
  1047. this.Extentions = [];
  1048. this.Attributes = [];
  1049. this.Fragment = [];
  1050. this.Helpers = [];
  1051. this.Uniforms = [];
  1052. this.Varings = [];
  1053. this.Vertex = [];
  1054. this.Setting.Uv = true;
  1055. this.Setting.Time = true;
  1056. this.Setting.Camera = true;
  1057. this.Setting.Helpers = true;
  1058. this.Setting.NormalMap = "result = vec4(0.5);";
  1059. this.Setting.SpecularMap = "float_result = 1.0;";
  1060. this.Setting.NormalOpacity = "0.5";
  1061. this.Setting.Normal = ShaderMaterialHelperStatics.Normal;
  1062. if (Shader.Indexer == null) Shader.Indexer = 1;
  1063. this.CustomIndexer = 1;
  1064. Shader.Me = this;
  1065. }
  1066. }
  1067. }