@babylonjs/materials 5.0.0-rc.5 → 5.0.0-rc.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/cell/cell.fragment.d.ts +17 -17
  2. package/cell/cell.fragment.js +20 -20
  3. package/cell/cell.vertex.d.ts +18 -18
  4. package/cell/cell.vertex.js +21 -21
  5. package/cell/cellMaterial.d.ts +37 -37
  6. package/cell/cellMaterial.js +304 -304
  7. package/cell/index.d.ts +1 -1
  8. package/cell/index.js +1 -1
  9. package/custom/customMaterial.d.ts +69 -69
  10. package/custom/customMaterial.js +216 -216
  11. package/custom/index.d.ts +2 -2
  12. package/custom/index.js +2 -2
  13. package/custom/pbrCustomMaterial.d.ts +71 -71
  14. package/custom/pbrCustomMaterial.js +241 -241
  15. package/fire/fire.fragment.d.ts +11 -11
  16. package/fire/fire.fragment.js +14 -14
  17. package/fire/fire.vertex.d.ts +15 -15
  18. package/fire/fire.vertex.js +18 -18
  19. package/fire/fireMaterial.d.ts +38 -38
  20. package/fire/fireMaterial.js +342 -342
  21. package/fire/index.d.ts +1 -1
  22. package/fire/index.js +1 -1
  23. package/fur/fur.fragment.d.ts +17 -17
  24. package/fur/fur.fragment.js +20 -20
  25. package/fur/fur.vertex.d.ts +18 -18
  26. package/fur/fur.vertex.js +21 -21
  27. package/fur/furMaterial.d.ts +56 -56
  28. package/fur/furMaterial.js +500 -500
  29. package/fur/index.d.ts +1 -1
  30. package/fur/index.js +1 -1
  31. package/gradient/gradient.fragment.d.ts +17 -17
  32. package/gradient/gradient.fragment.js +20 -20
  33. package/gradient/gradient.vertex.d.ts +18 -18
  34. package/gradient/gradient.vertex.js +21 -21
  35. package/gradient/gradientMaterial.d.ts +37 -37
  36. package/gradient/gradientMaterial.js +275 -275
  37. package/gradient/index.d.ts +1 -1
  38. package/gradient/index.js +1 -1
  39. package/grid/grid.fragment.d.ts +8 -8
  40. package/grid/grid.fragment.js +11 -11
  41. package/grid/grid.vertex.d.ts +9 -9
  42. package/grid/grid.vertex.js +12 -12
  43. package/grid/gridMaterial.d.ts +77 -77
  44. package/grid/gridMaterial.js +276 -276
  45. package/grid/index.d.ts +1 -1
  46. package/grid/index.js +1 -1
  47. package/index.d.ts +15 -15
  48. package/index.js +15 -15
  49. package/lava/index.d.ts +1 -1
  50. package/lava/index.js +1 -1
  51. package/lava/lava.fragment.d.ts +17 -17
  52. package/lava/lava.fragment.js +20 -20
  53. package/lava/lava.vertex.d.ts +18 -18
  54. package/lava/lava.vertex.js +21 -21
  55. package/lava/lavaMaterial.d.ts +45 -45
  56. package/lava/lavaMaterial.js +394 -394
  57. package/legacy/legacy-cell.d.ts +1 -1
  58. package/legacy/legacy-cell.js +12 -12
  59. package/legacy/legacy-custom.d.ts +1 -1
  60. package/legacy/legacy-custom.js +12 -12
  61. package/legacy/legacy-fire.d.ts +1 -1
  62. package/legacy/legacy-fire.js +12 -12
  63. package/legacy/legacy-fur.d.ts +1 -1
  64. package/legacy/legacy-fur.js +12 -12
  65. package/legacy/legacy-gradient.d.ts +1 -1
  66. package/legacy/legacy-gradient.js +12 -12
  67. package/legacy/legacy-grid.d.ts +1 -1
  68. package/legacy/legacy-grid.js +12 -12
  69. package/legacy/legacy-lava.d.ts +1 -1
  70. package/legacy/legacy-lava.js +12 -12
  71. package/legacy/legacy-mix.d.ts +1 -1
  72. package/legacy/legacy-mix.js +12 -12
  73. package/legacy/legacy-normal.d.ts +1 -1
  74. package/legacy/legacy-normal.js +12 -12
  75. package/legacy/legacy-shadowOnly.d.ts +1 -1
  76. package/legacy/legacy-shadowOnly.js +12 -12
  77. package/legacy/legacy-simple.d.ts +1 -1
  78. package/legacy/legacy-simple.js +12 -12
  79. package/legacy/legacy-sky.d.ts +1 -1
  80. package/legacy/legacy-sky.js +12 -12
  81. package/legacy/legacy-terrain.d.ts +1 -1
  82. package/legacy/legacy-terrain.js +12 -12
  83. package/legacy/legacy-triPlanar.d.ts +1 -1
  84. package/legacy/legacy-triPlanar.js +12 -12
  85. package/legacy/legacy-water.d.ts +1 -1
  86. package/legacy/legacy-water.js +12 -12
  87. package/legacy/legacy.d.ts +1 -1
  88. package/legacy/legacy.js +15 -15
  89. package/mix/index.d.ts +1 -1
  90. package/mix/index.js +1 -1
  91. package/mix/mix.fragment.d.ts +17 -17
  92. package/mix/mix.fragment.js +20 -20
  93. package/mix/mix.vertex.d.ts +18 -18
  94. package/mix/mix.vertex.js +21 -21
  95. package/mix/mixMaterial.d.ts +65 -65
  96. package/mix/mixMaterial.js +510 -510
  97. package/normal/index.d.ts +1 -1
  98. package/normal/index.js +1 -1
  99. package/normal/normal.fragment.d.ts +17 -17
  100. package/normal/normal.fragment.js +20 -20
  101. package/normal/normal.vertex.d.ts +18 -18
  102. package/normal/normal.vertex.js +21 -21
  103. package/normal/normalMaterial.d.ts +36 -36
  104. package/normal/normalMaterial.js +336 -336
  105. package/package.json +2 -2
  106. package/shadowOnly/index.d.ts +1 -1
  107. package/shadowOnly/index.js +1 -1
  108. package/shadowOnly/shadowOnly.fragment.d.ts +16 -16
  109. package/shadowOnly/shadowOnly.fragment.js +19 -19
  110. package/shadowOnly/shadowOnly.vertex.d.ts +18 -18
  111. package/shadowOnly/shadowOnly.vertex.js +21 -21
  112. package/shadowOnly/shadowOnlyMaterial.d.ts +30 -30
  113. package/shadowOnly/shadowOnlyMaterial.js +254 -254
  114. package/simple/index.d.ts +1 -1
  115. package/simple/index.js +1 -1
  116. package/simple/simple.fragment.d.ts +17 -17
  117. package/simple/simple.fragment.js +20 -20
  118. package/simple/simple.vertex.d.ts +18 -18
  119. package/simple/simple.vertex.js +21 -21
  120. package/simple/simpleMaterial.d.ts +35 -35
  121. package/simple/simpleMaterial.js +295 -295
  122. package/sky/index.d.ts +1 -1
  123. package/sky/index.js +1 -1
  124. package/sky/sky.fragment.d.ts +10 -10
  125. package/sky/sky.fragment.js +13 -13
  126. package/sky/sky.vertex.d.ts +9 -9
  127. package/sky/sky.vertex.js +12 -12
  128. package/sky/skyMaterial.d.ts +146 -146
  129. package/sky/skyMaterial.js +359 -359
  130. package/terrain/index.d.ts +1 -1
  131. package/terrain/index.js +1 -1
  132. package/terrain/terrain.fragment.d.ts +17 -17
  133. package/terrain/terrain.fragment.js +20 -20
  134. package/terrain/terrain.vertex.d.ts +18 -18
  135. package/terrain/terrain.vertex.js +21 -21
  136. package/terrain/terrainMaterial.d.ts +50 -50
  137. package/terrain/terrainMaterial.js +426 -426
  138. package/triPlanar/index.d.ts +1 -1
  139. package/triPlanar/index.js +1 -1
  140. package/triPlanar/triPlanarMaterial.d.ts +49 -49
  141. package/triPlanar/triPlanarMaterial.js +403 -403
  142. package/triPlanar/triplanar.fragment.d.ts +17 -17
  143. package/triPlanar/triplanar.fragment.js +20 -20
  144. package/triPlanar/triplanar.vertex.d.ts +18 -18
  145. package/triPlanar/triplanar.vertex.js +21 -21
  146. package/water/index.d.ts +1 -1
  147. package/water/index.js +1 -1
  148. package/water/water.fragment.d.ts +19 -19
  149. package/water/water.fragment.js +22 -22
  150. package/water/water.vertex.d.ts +20 -20
  151. package/water/water.vertex.js +23 -23
  152. package/water/waterMaterial.d.ts +135 -135
  153. package/water/waterMaterial.js +736 -736
@@ -1,69 +1,69 @@
1
- import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
2
- import { Effect } from "@babylonjs/core/Materials/effect.js";
3
- import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
4
- import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
5
- import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
6
- import { Scene } from "@babylonjs/core/scene.js";
7
- export declare class CustomShaderStructure {
8
- FragmentStore: string;
9
- VertexStore: string;
10
- constructor();
11
- }
12
- export declare class ShaderSpecialParts {
13
- constructor();
14
- Fragment_Begin: string;
15
- Fragment_Definitions: string;
16
- Fragment_MainBegin: string;
17
- Fragment_MainEnd: string;
18
- Fragment_Custom_Diffuse: string;
19
- Fragment_Before_Lights: string;
20
- Fragment_Before_Fog: string;
21
- Fragment_Custom_Alpha: string;
22
- Fragment_Before_FragColor: string;
23
- Vertex_Begin: string;
24
- Vertex_Definitions: string;
25
- Vertex_MainBegin: string;
26
- Vertex_Before_PositionUpdated: string;
27
- Vertex_Before_NormalUpdated: string;
28
- Vertex_After_WorldPosComputed: string;
29
- Vertex_MainEnd: string;
30
- }
31
- export declare class CustomMaterial extends StandardMaterial {
32
- static ShaderIndexer: number;
33
- CustomParts: ShaderSpecialParts;
34
- _isCreatedShader: boolean;
35
- _createdShaderName: string;
36
- _customUniform: string[];
37
- _newUniforms: string[];
38
- _newUniformInstances: {
39
- [name: string]: any;
40
- };
41
- _newSamplerInstances: {
42
- [name: string]: Texture;
43
- };
44
- _customAttributes: string[];
45
- FragmentShader: string;
46
- VertexShader: string;
47
- AttachAfterBind(mesh: Mesh | undefined, effect: Effect): void;
48
- ReviewUniform(name: string, arr: string[]): string[];
49
- Builder(shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: MaterialDefines | string[], attributes?: string[]): string;
50
- constructor(name: string, scene?: Scene);
51
- AddUniform(name: string, kind: string, param: any): CustomMaterial;
52
- AddAttribute(name: string): CustomMaterial;
53
- Fragment_Begin(shaderPart: string): CustomMaterial;
54
- Fragment_Definitions(shaderPart: string): CustomMaterial;
55
- Fragment_MainBegin(shaderPart: string): CustomMaterial;
56
- Fragment_MainEnd(shaderPart: string): CustomMaterial;
57
- Fragment_Custom_Diffuse(shaderPart: string): CustomMaterial;
58
- Fragment_Custom_Alpha(shaderPart: string): CustomMaterial;
59
- Fragment_Before_Lights(shaderPart: string): CustomMaterial;
60
- Fragment_Before_Fog(shaderPart: string): CustomMaterial;
61
- Fragment_Before_FragColor(shaderPart: string): CustomMaterial;
62
- Vertex_Begin(shaderPart: string): CustomMaterial;
63
- Vertex_Definitions(shaderPart: string): CustomMaterial;
64
- Vertex_MainBegin(shaderPart: string): CustomMaterial;
65
- Vertex_Before_PositionUpdated(shaderPart: string): CustomMaterial;
66
- Vertex_Before_NormalUpdated(shaderPart: string): CustomMaterial;
67
- Vertex_After_WorldPosComputed(shaderPart: string): CustomMaterial;
68
- Vertex_MainEnd(shaderPart: string): CustomMaterial;
69
- }
1
+ import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
2
+ import { Effect } from "@babylonjs/core/Materials/effect.js";
3
+ import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
4
+ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
5
+ import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
6
+ import { Scene } from "@babylonjs/core/scene.js";
7
+ export declare class CustomShaderStructure {
8
+ FragmentStore: string;
9
+ VertexStore: string;
10
+ constructor();
11
+ }
12
+ export declare class ShaderSpecialParts {
13
+ constructor();
14
+ Fragment_Begin: string;
15
+ Fragment_Definitions: string;
16
+ Fragment_MainBegin: string;
17
+ Fragment_MainEnd: string;
18
+ Fragment_Custom_Diffuse: string;
19
+ Fragment_Before_Lights: string;
20
+ Fragment_Before_Fog: string;
21
+ Fragment_Custom_Alpha: string;
22
+ Fragment_Before_FragColor: string;
23
+ Vertex_Begin: string;
24
+ Vertex_Definitions: string;
25
+ Vertex_MainBegin: string;
26
+ Vertex_Before_PositionUpdated: string;
27
+ Vertex_Before_NormalUpdated: string;
28
+ Vertex_After_WorldPosComputed: string;
29
+ Vertex_MainEnd: string;
30
+ }
31
+ export declare class CustomMaterial extends StandardMaterial {
32
+ static ShaderIndexer: number;
33
+ CustomParts: ShaderSpecialParts;
34
+ _isCreatedShader: boolean;
35
+ _createdShaderName: string;
36
+ _customUniform: string[];
37
+ _newUniforms: string[];
38
+ _newUniformInstances: {
39
+ [name: string]: any;
40
+ };
41
+ _newSamplerInstances: {
42
+ [name: string]: Texture;
43
+ };
44
+ _customAttributes: string[];
45
+ FragmentShader: string;
46
+ VertexShader: string;
47
+ AttachAfterBind(mesh: Mesh | undefined, effect: Effect): void;
48
+ ReviewUniform(name: string, arr: string[]): string[];
49
+ Builder(shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: MaterialDefines | string[], attributes?: string[]): string;
50
+ constructor(name: string, scene?: Scene);
51
+ AddUniform(name: string, kind: string, param: any): CustomMaterial;
52
+ AddAttribute(name: string): CustomMaterial;
53
+ Fragment_Begin(shaderPart: string): CustomMaterial;
54
+ Fragment_Definitions(shaderPart: string): CustomMaterial;
55
+ Fragment_MainBegin(shaderPart: string): CustomMaterial;
56
+ Fragment_MainEnd(shaderPart: string): CustomMaterial;
57
+ Fragment_Custom_Diffuse(shaderPart: string): CustomMaterial;
58
+ Fragment_Custom_Alpha(shaderPart: string): CustomMaterial;
59
+ Fragment_Before_Lights(shaderPart: string): CustomMaterial;
60
+ Fragment_Before_Fog(shaderPart: string): CustomMaterial;
61
+ Fragment_Before_FragColor(shaderPart: string): CustomMaterial;
62
+ Vertex_Begin(shaderPart: string): CustomMaterial;
63
+ Vertex_Definitions(shaderPart: string): CustomMaterial;
64
+ Vertex_MainBegin(shaderPart: string): CustomMaterial;
65
+ Vertex_Before_PositionUpdated(shaderPart: string): CustomMaterial;
66
+ Vertex_Before_NormalUpdated(shaderPart: string): CustomMaterial;
67
+ Vertex_After_WorldPosComputed(shaderPart: string): CustomMaterial;
68
+ Vertex_MainEnd(shaderPart: string): CustomMaterial;
69
+ }
@@ -1,217 +1,217 @@
1
- import { __extends } from "tslib";
2
- import { Effect } from "@babylonjs/core/Materials/effect.js";
3
- import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
4
- import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
5
- var CustomShaderStructure = /** @class */ (function () {
6
- function CustomShaderStructure() {
7
- }
8
- return CustomShaderStructure;
9
- }());
10
- export { CustomShaderStructure };
11
- var ShaderSpecialParts = /** @class */ (function () {
12
- function ShaderSpecialParts() {
13
- }
14
- return ShaderSpecialParts;
15
- }());
16
- export { ShaderSpecialParts };
17
- var CustomMaterial = /** @class */ (function (_super) {
18
- __extends(CustomMaterial, _super);
19
- function CustomMaterial(name, scene) {
20
- var _this = _super.call(this, name, scene) || this;
21
- _this.CustomParts = new ShaderSpecialParts();
22
- _this.customShaderNameResolve = _this.Builder;
23
- _this.FragmentShader = Effect.ShadersStore["defaultPixelShader"];
24
- _this.VertexShader = Effect.ShadersStore["defaultVertexShader"];
25
- return _this;
26
- }
27
- CustomMaterial.prototype.AttachAfterBind = function (mesh, effect) {
28
- if (this._newUniformInstances) {
29
- for (var el in this._newUniformInstances) {
30
- var ea = el.toString().split("-");
31
- if (ea[0] == "vec2") {
32
- effect.setVector2(ea[1], this._newUniformInstances[el]);
33
- }
34
- else if (ea[0] == "vec3") {
35
- effect.setVector3(ea[1], this._newUniformInstances[el]);
36
- }
37
- else if (ea[0] == "vec4") {
38
- effect.setVector4(ea[1], this._newUniformInstances[el]);
39
- }
40
- else if (ea[0] == "mat4") {
41
- effect.setMatrix(ea[1], this._newUniformInstances[el]);
42
- }
43
- else if (ea[0] == "float") {
44
- effect.setFloat(ea[1], this._newUniformInstances[el]);
45
- }
46
- }
47
- }
48
- if (this._newSamplerInstances) {
49
- for (var el in this._newSamplerInstances) {
50
- var ea = el.toString().split("-");
51
- if (ea[0] == "sampler2D" && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {
52
- effect.setTexture(ea[1], this._newSamplerInstances[el]);
53
- }
54
- }
55
- }
56
- };
57
- CustomMaterial.prototype.ReviewUniform = function (name, arr) {
58
- if (name == "uniform" && this._newUniforms) {
59
- for (var ind = 0; ind < this._newUniforms.length; ind++) {
60
- if (this._customUniform[ind].indexOf("sampler") == -1) {
61
- arr.push(this._newUniforms[ind]);
62
- }
63
- }
64
- }
65
- if (name == "sampler" && this._newUniforms) {
66
- for (var ind = 0; ind < this._newUniforms.length; ind++) {
67
- if (this._customUniform[ind].indexOf("sampler") != -1) {
68
- arr.push(this._newUniforms[ind]);
69
- }
70
- }
71
- }
72
- return arr;
73
- };
74
- CustomMaterial.prototype.Builder = function (shaderName, uniforms, uniformBuffers, samplers, defines, attributes) {
75
- var _this = this;
76
- if (attributes && this._customAttributes && this._customAttributes.length > 0) {
77
- attributes.push.apply(attributes, this._customAttributes);
78
- }
79
- this.ReviewUniform("uniform", uniforms);
80
- this.ReviewUniform("sampler", samplers);
81
- if (this._isCreatedShader) {
82
- return this._createdShaderName;
83
- }
84
- this._isCreatedShader = false;
85
- CustomMaterial.ShaderIndexer++;
86
- var name = "custom_" + CustomMaterial.ShaderIndexer;
87
- var fn_afterBind = this._afterBind.bind(this);
88
- this._afterBind = function (m, e) {
89
- if (!e) {
90
- return;
91
- }
92
- _this.AttachAfterBind(m, e);
93
- try {
94
- fn_afterBind(m, e);
95
- }
96
- catch (e) { }
97
- };
98
- Effect.ShadersStore[name + "VertexShader"] = this.VertexShader.replace("#define CUSTOM_VERTEX_BEGIN", this.CustomParts.Vertex_Begin ? this.CustomParts.Vertex_Begin : "")
99
- .replace("#define CUSTOM_VERTEX_DEFINITIONS", (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
100
- .replace("#define CUSTOM_VERTEX_MAIN_BEGIN", this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : "")
101
- .replace("#define CUSTOM_VERTEX_UPDATE_POSITION", this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : "")
102
- .replace("#define CUSTOM_VERTEX_UPDATE_NORMAL", this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : "")
103
- .replace("#define CUSTOM_VERTEX_MAIN_END", this.CustomParts.Vertex_MainEnd ? this.CustomParts.Vertex_MainEnd : "");
104
- if (this.CustomParts.Vertex_After_WorldPosComputed) {
105
- Effect.ShadersStore[name + "VertexShader"] = Effect.ShadersStore[name + "VertexShader"].replace("#define CUSTOM_VERTEX_UPDATE_WORLDPOS", this.CustomParts.Vertex_After_WorldPosComputed);
106
- }
107
- Effect.ShadersStore[name + "PixelShader"] = this.FragmentShader.replace("#define CUSTOM_FRAGMENT_BEGIN", this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : "")
108
- .replace("#define CUSTOM_FRAGMENT_MAIN_BEGIN", this.CustomParts.Fragment_MainBegin ? this.CustomParts.Fragment_MainBegin : "")
109
- .replace("#define CUSTOM_FRAGMENT_DEFINITIONS", (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
110
- .replace("#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE", this.CustomParts.Fragment_Custom_Diffuse ? this.CustomParts.Fragment_Custom_Diffuse : "")
111
- .replace("#define CUSTOM_FRAGMENT_UPDATE_ALPHA", this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : "")
112
- .replace("#define CUSTOM_FRAGMENT_BEFORE_LIGHTS", this.CustomParts.Fragment_Before_Lights ? this.CustomParts.Fragment_Before_Lights : "")
113
- .replace("#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR", this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : "")
114
- .replace("#define CUSTOM_FRAGMENT_MAIN_END", this.CustomParts.Fragment_MainEnd ? this.CustomParts.Fragment_MainEnd : "");
115
- if (this.CustomParts.Fragment_Before_Fog) {
116
- Effect.ShadersStore[name + "PixelShader"] = Effect.ShadersStore[name + "PixelShader"].replace("#define CUSTOM_FRAGMENT_BEFORE_FOG", this.CustomParts.Fragment_Before_Fog);
117
- }
118
- this._isCreatedShader = true;
119
- this._createdShaderName = name;
120
- return name;
121
- };
122
- CustomMaterial.prototype.AddUniform = function (name, kind, param) {
123
- if (!this._customUniform) {
124
- this._customUniform = new Array();
125
- this._newUniforms = new Array();
126
- this._newSamplerInstances = {};
127
- this._newUniformInstances = {};
128
- }
129
- if (param) {
130
- if (kind.indexOf("sampler") != -1) {
131
- this._newSamplerInstances[kind + "-" + name] = param;
132
- }
133
- else {
134
- this._newUniformInstances[kind + "-" + name] = param;
135
- }
136
- }
137
- this._customUniform.push("uniform " + kind + " " + name + ";");
138
- this._newUniforms.push(name);
139
- return this;
140
- };
141
- CustomMaterial.prototype.AddAttribute = function (name) {
142
- if (!this._customAttributes) {
143
- this._customAttributes = [];
144
- }
145
- this._customAttributes.push(name);
146
- return this;
147
- };
148
- CustomMaterial.prototype.Fragment_Begin = function (shaderPart) {
149
- this.CustomParts.Fragment_Begin = shaderPart;
150
- return this;
151
- };
152
- CustomMaterial.prototype.Fragment_Definitions = function (shaderPart) {
153
- this.CustomParts.Fragment_Definitions = shaderPart;
154
- return this;
155
- };
156
- CustomMaterial.prototype.Fragment_MainBegin = function (shaderPart) {
157
- this.CustomParts.Fragment_MainBegin = shaderPart;
158
- return this;
159
- };
160
- CustomMaterial.prototype.Fragment_MainEnd = function (shaderPart) {
161
- this.CustomParts.Fragment_MainEnd = shaderPart;
162
- return this;
163
- };
164
- CustomMaterial.prototype.Fragment_Custom_Diffuse = function (shaderPart) {
165
- this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result", "diffuseColor");
166
- return this;
167
- };
168
- CustomMaterial.prototype.Fragment_Custom_Alpha = function (shaderPart) {
169
- this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
170
- return this;
171
- };
172
- CustomMaterial.prototype.Fragment_Before_Lights = function (shaderPart) {
173
- this.CustomParts.Fragment_Before_Lights = shaderPart;
174
- return this;
175
- };
176
- CustomMaterial.prototype.Fragment_Before_Fog = function (shaderPart) {
177
- this.CustomParts.Fragment_Before_Fog = shaderPart;
178
- return this;
179
- };
180
- CustomMaterial.prototype.Fragment_Before_FragColor = function (shaderPart) {
181
- this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
182
- return this;
183
- };
184
- CustomMaterial.prototype.Vertex_Begin = function (shaderPart) {
185
- this.CustomParts.Vertex_Begin = shaderPart;
186
- return this;
187
- };
188
- CustomMaterial.prototype.Vertex_Definitions = function (shaderPart) {
189
- this.CustomParts.Vertex_Definitions = shaderPart;
190
- return this;
191
- };
192
- CustomMaterial.prototype.Vertex_MainBegin = function (shaderPart) {
193
- this.CustomParts.Vertex_MainBegin = shaderPart;
194
- return this;
195
- };
196
- CustomMaterial.prototype.Vertex_Before_PositionUpdated = function (shaderPart) {
197
- this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
198
- return this;
199
- };
200
- CustomMaterial.prototype.Vertex_Before_NormalUpdated = function (shaderPart) {
201
- this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
202
- return this;
203
- };
204
- CustomMaterial.prototype.Vertex_After_WorldPosComputed = function (shaderPart) {
205
- this.CustomParts.Vertex_After_WorldPosComputed = shaderPart;
206
- return this;
207
- };
208
- CustomMaterial.prototype.Vertex_MainEnd = function (shaderPart) {
209
- this.CustomParts.Vertex_MainEnd = shaderPart;
210
- return this;
211
- };
212
- CustomMaterial.ShaderIndexer = 1;
213
- return CustomMaterial;
214
- }(StandardMaterial));
215
- export { CustomMaterial };
216
- RegisterClass("BABYLON.CustomMaterial", CustomMaterial);
1
+ import { __extends } from "tslib";
2
+ import { Effect } from "@babylonjs/core/Materials/effect.js";
3
+ import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
4
+ import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
5
+ var CustomShaderStructure = /** @class */ (function () {
6
+ function CustomShaderStructure() {
7
+ }
8
+ return CustomShaderStructure;
9
+ }());
10
+ export { CustomShaderStructure };
11
+ var ShaderSpecialParts = /** @class */ (function () {
12
+ function ShaderSpecialParts() {
13
+ }
14
+ return ShaderSpecialParts;
15
+ }());
16
+ export { ShaderSpecialParts };
17
+ var CustomMaterial = /** @class */ (function (_super) {
18
+ __extends(CustomMaterial, _super);
19
+ function CustomMaterial(name, scene) {
20
+ var _this = _super.call(this, name, scene) || this;
21
+ _this.CustomParts = new ShaderSpecialParts();
22
+ _this.customShaderNameResolve = _this.Builder;
23
+ _this.FragmentShader = Effect.ShadersStore["defaultPixelShader"];
24
+ _this.VertexShader = Effect.ShadersStore["defaultVertexShader"];
25
+ return _this;
26
+ }
27
+ CustomMaterial.prototype.AttachAfterBind = function (mesh, effect) {
28
+ if (this._newUniformInstances) {
29
+ for (var el in this._newUniformInstances) {
30
+ var ea = el.toString().split("-");
31
+ if (ea[0] == "vec2") {
32
+ effect.setVector2(ea[1], this._newUniformInstances[el]);
33
+ }
34
+ else if (ea[0] == "vec3") {
35
+ effect.setVector3(ea[1], this._newUniformInstances[el]);
36
+ }
37
+ else if (ea[0] == "vec4") {
38
+ effect.setVector4(ea[1], this._newUniformInstances[el]);
39
+ }
40
+ else if (ea[0] == "mat4") {
41
+ effect.setMatrix(ea[1], this._newUniformInstances[el]);
42
+ }
43
+ else if (ea[0] == "float") {
44
+ effect.setFloat(ea[1], this._newUniformInstances[el]);
45
+ }
46
+ }
47
+ }
48
+ if (this._newSamplerInstances) {
49
+ for (var el in this._newSamplerInstances) {
50
+ var ea = el.toString().split("-");
51
+ if (ea[0] == "sampler2D" && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {
52
+ effect.setTexture(ea[1], this._newSamplerInstances[el]);
53
+ }
54
+ }
55
+ }
56
+ };
57
+ CustomMaterial.prototype.ReviewUniform = function (name, arr) {
58
+ if (name == "uniform" && this._newUniforms) {
59
+ for (var ind = 0; ind < this._newUniforms.length; ind++) {
60
+ if (this._customUniform[ind].indexOf("sampler") == -1) {
61
+ arr.push(this._newUniforms[ind]);
62
+ }
63
+ }
64
+ }
65
+ if (name == "sampler" && this._newUniforms) {
66
+ for (var ind = 0; ind < this._newUniforms.length; ind++) {
67
+ if (this._customUniform[ind].indexOf("sampler") != -1) {
68
+ arr.push(this._newUniforms[ind]);
69
+ }
70
+ }
71
+ }
72
+ return arr;
73
+ };
74
+ CustomMaterial.prototype.Builder = function (shaderName, uniforms, uniformBuffers, samplers, defines, attributes) {
75
+ var _this = this;
76
+ if (attributes && this._customAttributes && this._customAttributes.length > 0) {
77
+ attributes.push.apply(attributes, this._customAttributes);
78
+ }
79
+ this.ReviewUniform("uniform", uniforms);
80
+ this.ReviewUniform("sampler", samplers);
81
+ if (this._isCreatedShader) {
82
+ return this._createdShaderName;
83
+ }
84
+ this._isCreatedShader = false;
85
+ CustomMaterial.ShaderIndexer++;
86
+ var name = "custom_" + CustomMaterial.ShaderIndexer;
87
+ var fn_afterBind = this._afterBind.bind(this);
88
+ this._afterBind = function (m, e) {
89
+ if (!e) {
90
+ return;
91
+ }
92
+ _this.AttachAfterBind(m, e);
93
+ try {
94
+ fn_afterBind(m, e);
95
+ }
96
+ catch (e) { }
97
+ };
98
+ Effect.ShadersStore[name + "VertexShader"] = this.VertexShader.replace("#define CUSTOM_VERTEX_BEGIN", this.CustomParts.Vertex_Begin ? this.CustomParts.Vertex_Begin : "")
99
+ .replace("#define CUSTOM_VERTEX_DEFINITIONS", (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
100
+ .replace("#define CUSTOM_VERTEX_MAIN_BEGIN", this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : "")
101
+ .replace("#define CUSTOM_VERTEX_UPDATE_POSITION", this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : "")
102
+ .replace("#define CUSTOM_VERTEX_UPDATE_NORMAL", this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : "")
103
+ .replace("#define CUSTOM_VERTEX_MAIN_END", this.CustomParts.Vertex_MainEnd ? this.CustomParts.Vertex_MainEnd : "");
104
+ if (this.CustomParts.Vertex_After_WorldPosComputed) {
105
+ Effect.ShadersStore[name + "VertexShader"] = Effect.ShadersStore[name + "VertexShader"].replace("#define CUSTOM_VERTEX_UPDATE_WORLDPOS", this.CustomParts.Vertex_After_WorldPosComputed);
106
+ }
107
+ Effect.ShadersStore[name + "PixelShader"] = this.FragmentShader.replace("#define CUSTOM_FRAGMENT_BEGIN", this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : "")
108
+ .replace("#define CUSTOM_FRAGMENT_MAIN_BEGIN", this.CustomParts.Fragment_MainBegin ? this.CustomParts.Fragment_MainBegin : "")
109
+ .replace("#define CUSTOM_FRAGMENT_DEFINITIONS", (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
110
+ .replace("#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE", this.CustomParts.Fragment_Custom_Diffuse ? this.CustomParts.Fragment_Custom_Diffuse : "")
111
+ .replace("#define CUSTOM_FRAGMENT_UPDATE_ALPHA", this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : "")
112
+ .replace("#define CUSTOM_FRAGMENT_BEFORE_LIGHTS", this.CustomParts.Fragment_Before_Lights ? this.CustomParts.Fragment_Before_Lights : "")
113
+ .replace("#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR", this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : "")
114
+ .replace("#define CUSTOM_FRAGMENT_MAIN_END", this.CustomParts.Fragment_MainEnd ? this.CustomParts.Fragment_MainEnd : "");
115
+ if (this.CustomParts.Fragment_Before_Fog) {
116
+ Effect.ShadersStore[name + "PixelShader"] = Effect.ShadersStore[name + "PixelShader"].replace("#define CUSTOM_FRAGMENT_BEFORE_FOG", this.CustomParts.Fragment_Before_Fog);
117
+ }
118
+ this._isCreatedShader = true;
119
+ this._createdShaderName = name;
120
+ return name;
121
+ };
122
+ CustomMaterial.prototype.AddUniform = function (name, kind, param) {
123
+ if (!this._customUniform) {
124
+ this._customUniform = new Array();
125
+ this._newUniforms = new Array();
126
+ this._newSamplerInstances = {};
127
+ this._newUniformInstances = {};
128
+ }
129
+ if (param) {
130
+ if (kind.indexOf("sampler") != -1) {
131
+ this._newSamplerInstances[kind + "-" + name] = param;
132
+ }
133
+ else {
134
+ this._newUniformInstances[kind + "-" + name] = param;
135
+ }
136
+ }
137
+ this._customUniform.push("uniform " + kind + " " + name + ";");
138
+ this._newUniforms.push(name);
139
+ return this;
140
+ };
141
+ CustomMaterial.prototype.AddAttribute = function (name) {
142
+ if (!this._customAttributes) {
143
+ this._customAttributes = [];
144
+ }
145
+ this._customAttributes.push(name);
146
+ return this;
147
+ };
148
+ CustomMaterial.prototype.Fragment_Begin = function (shaderPart) {
149
+ this.CustomParts.Fragment_Begin = shaderPart;
150
+ return this;
151
+ };
152
+ CustomMaterial.prototype.Fragment_Definitions = function (shaderPart) {
153
+ this.CustomParts.Fragment_Definitions = shaderPart;
154
+ return this;
155
+ };
156
+ CustomMaterial.prototype.Fragment_MainBegin = function (shaderPart) {
157
+ this.CustomParts.Fragment_MainBegin = shaderPart;
158
+ return this;
159
+ };
160
+ CustomMaterial.prototype.Fragment_MainEnd = function (shaderPart) {
161
+ this.CustomParts.Fragment_MainEnd = shaderPart;
162
+ return this;
163
+ };
164
+ CustomMaterial.prototype.Fragment_Custom_Diffuse = function (shaderPart) {
165
+ this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result", "diffuseColor");
166
+ return this;
167
+ };
168
+ CustomMaterial.prototype.Fragment_Custom_Alpha = function (shaderPart) {
169
+ this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
170
+ return this;
171
+ };
172
+ CustomMaterial.prototype.Fragment_Before_Lights = function (shaderPart) {
173
+ this.CustomParts.Fragment_Before_Lights = shaderPart;
174
+ return this;
175
+ };
176
+ CustomMaterial.prototype.Fragment_Before_Fog = function (shaderPart) {
177
+ this.CustomParts.Fragment_Before_Fog = shaderPart;
178
+ return this;
179
+ };
180
+ CustomMaterial.prototype.Fragment_Before_FragColor = function (shaderPart) {
181
+ this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
182
+ return this;
183
+ };
184
+ CustomMaterial.prototype.Vertex_Begin = function (shaderPart) {
185
+ this.CustomParts.Vertex_Begin = shaderPart;
186
+ return this;
187
+ };
188
+ CustomMaterial.prototype.Vertex_Definitions = function (shaderPart) {
189
+ this.CustomParts.Vertex_Definitions = shaderPart;
190
+ return this;
191
+ };
192
+ CustomMaterial.prototype.Vertex_MainBegin = function (shaderPart) {
193
+ this.CustomParts.Vertex_MainBegin = shaderPart;
194
+ return this;
195
+ };
196
+ CustomMaterial.prototype.Vertex_Before_PositionUpdated = function (shaderPart) {
197
+ this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
198
+ return this;
199
+ };
200
+ CustomMaterial.prototype.Vertex_Before_NormalUpdated = function (shaderPart) {
201
+ this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
202
+ return this;
203
+ };
204
+ CustomMaterial.prototype.Vertex_After_WorldPosComputed = function (shaderPart) {
205
+ this.CustomParts.Vertex_After_WorldPosComputed = shaderPart;
206
+ return this;
207
+ };
208
+ CustomMaterial.prototype.Vertex_MainEnd = function (shaderPart) {
209
+ this.CustomParts.Vertex_MainEnd = shaderPart;
210
+ return this;
211
+ };
212
+ CustomMaterial.ShaderIndexer = 1;
213
+ return CustomMaterial;
214
+ }(StandardMaterial));
215
+ export { CustomMaterial };
216
+ RegisterClass("BABYLON.CustomMaterial", CustomMaterial);
217
217
  //# sourceMappingURL=customMaterial.js.map
package/custom/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./customMaterial";
2
- export * from "./pbrCustomMaterial";
1
+ export * from "./customMaterial";
2
+ export * from "./pbrCustomMaterial";
package/custom/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./customMaterial.js";
2
- export * from "./pbrCustomMaterial.js";
1
+ export * from "./customMaterial";
2
+ export * from "./pbrCustomMaterial";
3
3
  //# sourceMappingURL=index.js.map