@babylonjs/materials 6.39.0 → 6.40.0
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.
- package/custom/customMaterial.d.ts +203 -0
- package/custom/customMaterial.js +122 -0
- package/custom/customMaterial.js.map +1 -1
- package/custom/pbrCustomMaterial.d.ts +216 -0
- package/custom/pbrCustomMaterial.js +132 -0
- package/custom/pbrCustomMaterial.js.map +1 -1
- package/fur/furMaterial.js +1 -0
- package/fur/furMaterial.js.map +1 -1
- package/grid/gridMaterial.d.ts +4 -1
- package/grid/gridMaterial.js +1 -1
- package/grid/gridMaterial.js.map +1 -1
- package/package.json +2 -2
@@ -6,26 +6,86 @@ import type { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
|
6
6
|
import type { Scene } from "@babylonjs/core/scene.js";
|
7
7
|
import type { ICustomShaderNameResolveOptions } from "@babylonjs/core/Materials/material.js";
|
8
8
|
import type { Nullable } from "@babylonjs/core/types.js";
|
9
|
+
/**
|
10
|
+
* Albedo parts of the shader
|
11
|
+
*/
|
9
12
|
export declare class ShaderAlbedoParts {
|
10
13
|
constructor();
|
14
|
+
/**
|
15
|
+
* Beginning of the fragment shader
|
16
|
+
*/
|
11
17
|
Fragment_Begin: string;
|
18
|
+
/**
|
19
|
+
* Fragment definitions
|
20
|
+
*/
|
12
21
|
Fragment_Definitions: string;
|
22
|
+
/**
|
23
|
+
* Beginning of the main function
|
24
|
+
*/
|
13
25
|
Fragment_MainBegin: string;
|
26
|
+
/**
|
27
|
+
* End of main function
|
28
|
+
*/
|
14
29
|
Fragment_MainEnd: string;
|
30
|
+
/**
|
31
|
+
* Albedo color
|
32
|
+
*/
|
15
33
|
Fragment_Custom_Albedo: string;
|
34
|
+
/**
|
35
|
+
* Lights
|
36
|
+
*/
|
16
37
|
Fragment_Before_Lights: string;
|
38
|
+
/**
|
39
|
+
* Metallic and roughness
|
40
|
+
*/
|
17
41
|
Fragment_Custom_MetallicRoughness: string;
|
42
|
+
/**
|
43
|
+
* Microsurface
|
44
|
+
*/
|
18
45
|
Fragment_Custom_MicroSurface: string;
|
46
|
+
/**
|
47
|
+
* Fog computations
|
48
|
+
*/
|
19
49
|
Fragment_Before_Fog: string;
|
50
|
+
/**
|
51
|
+
* Alpha
|
52
|
+
*/
|
20
53
|
Fragment_Custom_Alpha: string;
|
54
|
+
/**
|
55
|
+
* Color composition
|
56
|
+
*/
|
21
57
|
Fragment_Before_FinalColorComposition: string;
|
58
|
+
/**
|
59
|
+
* Fragment color
|
60
|
+
*/
|
22
61
|
Fragment_Before_FragColor: string;
|
62
|
+
/**
|
63
|
+
* Beginning of vertex shader
|
64
|
+
*/
|
23
65
|
Vertex_Begin: string;
|
66
|
+
/**
|
67
|
+
* Vertex definitions
|
68
|
+
*/
|
24
69
|
Vertex_Definitions: string;
|
70
|
+
/**
|
71
|
+
* Vertex main begin
|
72
|
+
*/
|
25
73
|
Vertex_MainBegin: string;
|
74
|
+
/**
|
75
|
+
* Vertex before position updated
|
76
|
+
*/
|
26
77
|
Vertex_Before_PositionUpdated: string;
|
78
|
+
/**
|
79
|
+
* Vertex before normal updated
|
80
|
+
*/
|
27
81
|
Vertex_Before_NormalUpdated: string;
|
82
|
+
/**
|
83
|
+
* Vertex after world pos computed
|
84
|
+
*/
|
28
85
|
Vertex_After_WorldPosComputed: string;
|
86
|
+
/**
|
87
|
+
* Vertex main end
|
88
|
+
*/
|
29
89
|
Vertex_MainEnd: string;
|
30
90
|
}
|
31
91
|
/**
|
@@ -33,22 +93,71 @@ export declare class ShaderAlbedoParts {
|
|
33
93
|
*/
|
34
94
|
export declare const ShaderAlebdoParts: typeof ShaderAlbedoParts;
|
35
95
|
export declare class PBRCustomMaterial extends PBRMaterial {
|
96
|
+
/**
|
97
|
+
* Index for each created shader
|
98
|
+
*/
|
36
99
|
static ShaderIndexer: number;
|
100
|
+
/**
|
101
|
+
* Custom shader structure
|
102
|
+
*/
|
37
103
|
CustomParts: ShaderAlbedoParts;
|
104
|
+
/**
|
105
|
+
* Name of the shader
|
106
|
+
*/
|
38
107
|
_createdShaderName: string;
|
108
|
+
/**
|
109
|
+
* List of custom uniforms
|
110
|
+
*/
|
39
111
|
_customUniform: string[];
|
112
|
+
/**
|
113
|
+
* Names of the new uniforms
|
114
|
+
*/
|
40
115
|
_newUniforms: string[];
|
116
|
+
/**
|
117
|
+
* Instances of the new uniform objects
|
118
|
+
*/
|
41
119
|
_newUniformInstances: {
|
42
120
|
[name: string]: any;
|
43
121
|
};
|
122
|
+
/**
|
123
|
+
* Instances of the new sampler objects
|
124
|
+
*/
|
44
125
|
_newSamplerInstances: {
|
45
126
|
[name: string]: Texture;
|
46
127
|
};
|
128
|
+
/**
|
129
|
+
* List of the custom attributes
|
130
|
+
*/
|
47
131
|
_customAttributes: string[];
|
132
|
+
/**
|
133
|
+
* Fragment shader string
|
134
|
+
*/
|
48
135
|
FragmentShader: string;
|
136
|
+
/**
|
137
|
+
* Vertex shader string
|
138
|
+
*/
|
49
139
|
VertexShader: string;
|
140
|
+
/**
|
141
|
+
* Runs after the material is bound to a mesh
|
142
|
+
* @param mesh mesh bound
|
143
|
+
* @param effect bound effect used to render
|
144
|
+
*/
|
50
145
|
AttachAfterBind(mesh: Mesh | undefined, effect: Effect): void;
|
146
|
+
/**
|
147
|
+
* @internal
|
148
|
+
*/
|
51
149
|
ReviewUniform(name: string, arr: string[]): string[];
|
150
|
+
/**
|
151
|
+
* Builds the material
|
152
|
+
* @param shaderName name of the shader
|
153
|
+
* @param uniforms list of uniforms
|
154
|
+
* @param uniformBuffers list of uniform buffers
|
155
|
+
* @param samplers list of samplers
|
156
|
+
* @param defines list of defines
|
157
|
+
* @param attributes list of attributes
|
158
|
+
* @param options options to compile the shader
|
159
|
+
* @returns the shader name
|
160
|
+
*/
|
52
161
|
Builder(shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: MaterialDefines | string[], attributes?: string[], options?: ICustomShaderNameResolveOptions): string;
|
53
162
|
protected _injectCustomCode(code: string, shaderType: string): string;
|
54
163
|
protected _getCustomCode(shaderType: string): {
|
@@ -56,25 +165,132 @@ export declare class PBRCustomMaterial extends PBRMaterial {
|
|
56
165
|
};
|
57
166
|
constructor(name: string, scene?: Scene);
|
58
167
|
protected _afterBind(mesh?: Mesh, effect?: Nullable<Effect>): void;
|
168
|
+
/**
|
169
|
+
* Adds a new uniform to the shader
|
170
|
+
* @param name the name of the uniform to add
|
171
|
+
* @param kind the type of the uniform to add
|
172
|
+
* @param param the value of the uniform to add
|
173
|
+
* @returns the current material
|
174
|
+
*/
|
59
175
|
AddUniform(name: string, kind: string, param: any): PBRCustomMaterial;
|
176
|
+
/**
|
177
|
+
* Adds a custom attribute
|
178
|
+
* @param name the name of the attribute
|
179
|
+
* @returns the current material
|
180
|
+
*/
|
60
181
|
AddAttribute(name: string): PBRCustomMaterial;
|
182
|
+
/**
|
183
|
+
* Sets the code on Fragment_Begin portion
|
184
|
+
* @param shaderPart the code string
|
185
|
+
* @returns the current material
|
186
|
+
*/
|
61
187
|
Fragment_Begin(shaderPart: string): PBRCustomMaterial;
|
188
|
+
/**
|
189
|
+
* Sets the code on Fragment_Definitions portion
|
190
|
+
* @param shaderPart the code string
|
191
|
+
* @returns the current material
|
192
|
+
*/
|
62
193
|
Fragment_Definitions(shaderPart: string): PBRCustomMaterial;
|
194
|
+
/**
|
195
|
+
* Sets the code on Fragment_MainBegin portion
|
196
|
+
* @param shaderPart the code string
|
197
|
+
* @returns the current material
|
198
|
+
*/
|
63
199
|
Fragment_MainBegin(shaderPart: string): PBRCustomMaterial;
|
200
|
+
/**
|
201
|
+
* Sets the code on Fragment_Custom_Albedo portion
|
202
|
+
* @param shaderPart the code string
|
203
|
+
* @returns the current material
|
204
|
+
*/
|
64
205
|
Fragment_Custom_Albedo(shaderPart: string): PBRCustomMaterial;
|
206
|
+
/**
|
207
|
+
* Sets the code on Fragment_Custom_Alpha portion
|
208
|
+
* @param shaderPart the code string
|
209
|
+
* @returns the current material
|
210
|
+
*/
|
65
211
|
Fragment_Custom_Alpha(shaderPart: string): PBRCustomMaterial;
|
212
|
+
/**
|
213
|
+
* Sets the code on Fragment_Before_Lights portion
|
214
|
+
* @param shaderPart the code string
|
215
|
+
* @returns the current material
|
216
|
+
*/
|
66
217
|
Fragment_Before_Lights(shaderPart: string): PBRCustomMaterial;
|
218
|
+
/**
|
219
|
+
* Sets the code on Fragment_Custom_MetallicRoughness portion
|
220
|
+
* @param shaderPart the code string
|
221
|
+
* @returns the current material
|
222
|
+
*/
|
67
223
|
Fragment_Custom_MetallicRoughness(shaderPart: string): PBRCustomMaterial;
|
224
|
+
/**
|
225
|
+
* Sets the code on Fragment_Custom_MicroSurface portion
|
226
|
+
* @param shaderPart the code string
|
227
|
+
* @returns the current material
|
228
|
+
*/
|
68
229
|
Fragment_Custom_MicroSurface(shaderPart: string): PBRCustomMaterial;
|
230
|
+
/**
|
231
|
+
* Sets the code on Fragment_Before_Fog portion
|
232
|
+
* @param shaderPart the code string
|
233
|
+
* @returns the current material
|
234
|
+
*/
|
69
235
|
Fragment_Before_Fog(shaderPart: string): PBRCustomMaterial;
|
236
|
+
/**
|
237
|
+
* Sets the code on Fragment_Before_FinalColorComposition portion
|
238
|
+
* @param shaderPart the code string
|
239
|
+
* @returns the current material
|
240
|
+
*/
|
70
241
|
Fragment_Before_FinalColorComposition(shaderPart: string): PBRCustomMaterial;
|
242
|
+
/**
|
243
|
+
* Sets the code on Fragment_Before_FragColor portion
|
244
|
+
* @param shaderPart the code string
|
245
|
+
* @returns the current material
|
246
|
+
*/
|
71
247
|
Fragment_Before_FragColor(shaderPart: string): PBRCustomMaterial;
|
248
|
+
/**
|
249
|
+
* Sets the code on Fragment_MainEnd portion
|
250
|
+
* @param shaderPart the code string
|
251
|
+
* @returns the current material
|
252
|
+
*/
|
72
253
|
Fragment_MainEnd(shaderPart: string): PBRCustomMaterial;
|
254
|
+
/**
|
255
|
+
* Sets the code on Vertex_Begin portion
|
256
|
+
* @param shaderPart the code string
|
257
|
+
* @returns the current material
|
258
|
+
*/
|
73
259
|
Vertex_Begin(shaderPart: string): PBRCustomMaterial;
|
260
|
+
/**
|
261
|
+
* Sets the code on Vertex_Definitions portion
|
262
|
+
* @param shaderPart the code string
|
263
|
+
* @returns the current material
|
264
|
+
*/
|
74
265
|
Vertex_Definitions(shaderPart: string): PBRCustomMaterial;
|
266
|
+
/**
|
267
|
+
* Sets the code on Vertex_MainBegin portion
|
268
|
+
* @param shaderPart the code string
|
269
|
+
* @returns the current material
|
270
|
+
*/
|
75
271
|
Vertex_MainBegin(shaderPart: string): PBRCustomMaterial;
|
272
|
+
/**
|
273
|
+
* Sets the code on Vertex_Before_PositionUpdated portion
|
274
|
+
* @param shaderPart the code string
|
275
|
+
* @returns the current material
|
276
|
+
*/
|
76
277
|
Vertex_Before_PositionUpdated(shaderPart: string): PBRCustomMaterial;
|
278
|
+
/**
|
279
|
+
* Sets the code on Vertex_Before_NormalUpdated portion
|
280
|
+
* @param shaderPart the code string
|
281
|
+
* @returns the current material
|
282
|
+
*/
|
77
283
|
Vertex_Before_NormalUpdated(shaderPart: string): PBRCustomMaterial;
|
284
|
+
/**
|
285
|
+
* Sets the code on Vertex_After_WorldPosComputed portion
|
286
|
+
* @param shaderPart the code string
|
287
|
+
* @returns the current material
|
288
|
+
*/
|
78
289
|
Vertex_After_WorldPosComputed(shaderPart: string): PBRCustomMaterial;
|
290
|
+
/**
|
291
|
+
* Sets the code on Vertex_MainEnd portion
|
292
|
+
* @param shaderPart the code string
|
293
|
+
* @returns the current material
|
294
|
+
*/
|
79
295
|
Vertex_MainEnd(shaderPart: string): PBRCustomMaterial;
|
80
296
|
}
|
@@ -3,6 +3,9 @@ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
|
3
3
|
import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
|
4
4
|
import { ShaderCodeInliner } from "@babylonjs/core/Engines/Processors/shaderCodeInliner.js";
|
5
5
|
import { Color3, Color4 } from "@babylonjs/core/Maths/math.color.js";
|
6
|
+
/**
|
7
|
+
* Albedo parts of the shader
|
8
|
+
*/
|
6
9
|
export class ShaderAlbedoParts {
|
7
10
|
constructor() { }
|
8
11
|
}
|
@@ -11,6 +14,11 @@ export class ShaderAlbedoParts {
|
|
11
14
|
*/
|
12
15
|
export const ShaderAlebdoParts = ShaderAlbedoParts;
|
13
16
|
export class PBRCustomMaterial extends PBRMaterial {
|
17
|
+
/**
|
18
|
+
* Runs after the material is bound to a mesh
|
19
|
+
* @param mesh mesh bound
|
20
|
+
* @param effect bound effect used to render
|
21
|
+
*/
|
14
22
|
AttachAfterBind(mesh, effect) {
|
15
23
|
if (this._newUniformInstances) {
|
16
24
|
for (const el in this._newUniformInstances) {
|
@@ -52,6 +60,9 @@ export class PBRCustomMaterial extends PBRMaterial {
|
|
52
60
|
}
|
53
61
|
}
|
54
62
|
}
|
63
|
+
/**
|
64
|
+
* @internal
|
65
|
+
*/
|
55
66
|
ReviewUniform(name, arr) {
|
56
67
|
if (name == "uniform" && this._newUniforms) {
|
57
68
|
for (let ind = 0; ind < this._newUniforms.length; ind++) {
|
@@ -69,6 +80,17 @@ export class PBRCustomMaterial extends PBRMaterial {
|
|
69
80
|
}
|
70
81
|
return arr;
|
71
82
|
}
|
83
|
+
/**
|
84
|
+
* Builds the material
|
85
|
+
* @param shaderName name of the shader
|
86
|
+
* @param uniforms list of uniforms
|
87
|
+
* @param uniformBuffers list of uniform buffers
|
88
|
+
* @param samplers list of samplers
|
89
|
+
* @param defines list of defines
|
90
|
+
* @param attributes list of attributes
|
91
|
+
* @param options options to compile the shader
|
92
|
+
* @returns the shader name
|
93
|
+
*/
|
72
94
|
Builder(shaderName, uniforms, uniformBuffers, samplers, defines, attributes, options) {
|
73
95
|
if (options) {
|
74
96
|
const currentProcessing = options.processFinalCode;
|
@@ -155,6 +177,13 @@ export class PBRCustomMaterial extends PBRMaterial {
|
|
155
177
|
}
|
156
178
|
catch (e) { }
|
157
179
|
}
|
180
|
+
/**
|
181
|
+
* Adds a new uniform to the shader
|
182
|
+
* @param name the name of the uniform to add
|
183
|
+
* @param kind the type of the uniform to add
|
184
|
+
* @param param the value of the uniform to add
|
185
|
+
* @returns the current material
|
186
|
+
*/
|
158
187
|
AddUniform(name, kind, param) {
|
159
188
|
if (!this._customUniform) {
|
160
189
|
this._customUniform = new Array();
|
@@ -174,6 +203,11 @@ export class PBRCustomMaterial extends PBRMaterial {
|
|
174
203
|
this._newUniforms.push(name);
|
175
204
|
return this;
|
176
205
|
}
|
206
|
+
/**
|
207
|
+
* Adds a custom attribute
|
208
|
+
* @param name the name of the attribute
|
209
|
+
* @returns the current material
|
210
|
+
*/
|
177
211
|
AddAttribute(name) {
|
178
212
|
if (!this._customAttributes) {
|
179
213
|
this._customAttributes = [];
|
@@ -181,83 +215,181 @@ export class PBRCustomMaterial extends PBRMaterial {
|
|
181
215
|
this._customAttributes.push(name);
|
182
216
|
return this;
|
183
217
|
}
|
218
|
+
/**
|
219
|
+
* Sets the code on Fragment_Begin portion
|
220
|
+
* @param shaderPart the code string
|
221
|
+
* @returns the current material
|
222
|
+
*/
|
184
223
|
Fragment_Begin(shaderPart) {
|
185
224
|
this.CustomParts.Fragment_Begin = shaderPart;
|
186
225
|
return this;
|
187
226
|
}
|
227
|
+
/**
|
228
|
+
* Sets the code on Fragment_Definitions portion
|
229
|
+
* @param shaderPart the code string
|
230
|
+
* @returns the current material
|
231
|
+
*/
|
188
232
|
Fragment_Definitions(shaderPart) {
|
189
233
|
this.CustomParts.Fragment_Definitions = shaderPart;
|
190
234
|
return this;
|
191
235
|
}
|
236
|
+
/**
|
237
|
+
* Sets the code on Fragment_MainBegin portion
|
238
|
+
* @param shaderPart the code string
|
239
|
+
* @returns the current material
|
240
|
+
*/
|
192
241
|
Fragment_MainBegin(shaderPart) {
|
193
242
|
this.CustomParts.Fragment_MainBegin = shaderPart;
|
194
243
|
return this;
|
195
244
|
}
|
245
|
+
/**
|
246
|
+
* Sets the code on Fragment_Custom_Albedo portion
|
247
|
+
* @param shaderPart the code string
|
248
|
+
* @returns the current material
|
249
|
+
*/
|
196
250
|
Fragment_Custom_Albedo(shaderPart) {
|
197
251
|
this.CustomParts.Fragment_Custom_Albedo = shaderPart.replace("result", "surfaceAlbedo");
|
198
252
|
return this;
|
199
253
|
}
|
254
|
+
/**
|
255
|
+
* Sets the code on Fragment_Custom_Alpha portion
|
256
|
+
* @param shaderPart the code string
|
257
|
+
* @returns the current material
|
258
|
+
*/
|
200
259
|
Fragment_Custom_Alpha(shaderPart) {
|
201
260
|
this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
|
202
261
|
return this;
|
203
262
|
}
|
263
|
+
/**
|
264
|
+
* Sets the code on Fragment_Before_Lights portion
|
265
|
+
* @param shaderPart the code string
|
266
|
+
* @returns the current material
|
267
|
+
*/
|
204
268
|
Fragment_Before_Lights(shaderPart) {
|
205
269
|
this.CustomParts.Fragment_Before_Lights = shaderPart;
|
206
270
|
return this;
|
207
271
|
}
|
272
|
+
/**
|
273
|
+
* Sets the code on Fragment_Custom_MetallicRoughness portion
|
274
|
+
* @param shaderPart the code string
|
275
|
+
* @returns the current material
|
276
|
+
*/
|
208
277
|
Fragment_Custom_MetallicRoughness(shaderPart) {
|
209
278
|
this.CustomParts.Fragment_Custom_MetallicRoughness = shaderPart;
|
210
279
|
return this;
|
211
280
|
}
|
281
|
+
/**
|
282
|
+
* Sets the code on Fragment_Custom_MicroSurface portion
|
283
|
+
* @param shaderPart the code string
|
284
|
+
* @returns the current material
|
285
|
+
*/
|
212
286
|
Fragment_Custom_MicroSurface(shaderPart) {
|
213
287
|
this.CustomParts.Fragment_Custom_MicroSurface = shaderPart;
|
214
288
|
return this;
|
215
289
|
}
|
290
|
+
/**
|
291
|
+
* Sets the code on Fragment_Before_Fog portion
|
292
|
+
* @param shaderPart the code string
|
293
|
+
* @returns the current material
|
294
|
+
*/
|
216
295
|
Fragment_Before_Fog(shaderPart) {
|
217
296
|
this.CustomParts.Fragment_Before_Fog = shaderPart;
|
218
297
|
return this;
|
219
298
|
}
|
299
|
+
/**
|
300
|
+
* Sets the code on Fragment_Before_FinalColorComposition portion
|
301
|
+
* @param shaderPart the code string
|
302
|
+
* @returns the current material
|
303
|
+
*/
|
220
304
|
Fragment_Before_FinalColorComposition(shaderPart) {
|
221
305
|
this.CustomParts.Fragment_Before_FinalColorComposition = shaderPart;
|
222
306
|
return this;
|
223
307
|
}
|
308
|
+
/**
|
309
|
+
* Sets the code on Fragment_Before_FragColor portion
|
310
|
+
* @param shaderPart the code string
|
311
|
+
* @returns the current material
|
312
|
+
*/
|
224
313
|
Fragment_Before_FragColor(shaderPart) {
|
225
314
|
this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
|
226
315
|
return this;
|
227
316
|
}
|
317
|
+
/**
|
318
|
+
* Sets the code on Fragment_MainEnd portion
|
319
|
+
* @param shaderPart the code string
|
320
|
+
* @returns the current material
|
321
|
+
*/
|
228
322
|
Fragment_MainEnd(shaderPart) {
|
229
323
|
this.CustomParts.Fragment_MainEnd = shaderPart;
|
230
324
|
return this;
|
231
325
|
}
|
326
|
+
/**
|
327
|
+
* Sets the code on Vertex_Begin portion
|
328
|
+
* @param shaderPart the code string
|
329
|
+
* @returns the current material
|
330
|
+
*/
|
232
331
|
Vertex_Begin(shaderPart) {
|
233
332
|
this.CustomParts.Vertex_Begin = shaderPart;
|
234
333
|
return this;
|
235
334
|
}
|
335
|
+
/**
|
336
|
+
* Sets the code on Vertex_Definitions portion
|
337
|
+
* @param shaderPart the code string
|
338
|
+
* @returns the current material
|
339
|
+
*/
|
236
340
|
Vertex_Definitions(shaderPart) {
|
237
341
|
this.CustomParts.Vertex_Definitions = shaderPart;
|
238
342
|
return this;
|
239
343
|
}
|
344
|
+
/**
|
345
|
+
* Sets the code on Vertex_MainBegin portion
|
346
|
+
* @param shaderPart the code string
|
347
|
+
* @returns the current material
|
348
|
+
*/
|
240
349
|
Vertex_MainBegin(shaderPart) {
|
241
350
|
this.CustomParts.Vertex_MainBegin = shaderPart;
|
242
351
|
return this;
|
243
352
|
}
|
353
|
+
/**
|
354
|
+
* Sets the code on Vertex_Before_PositionUpdated portion
|
355
|
+
* @param shaderPart the code string
|
356
|
+
* @returns the current material
|
357
|
+
*/
|
244
358
|
Vertex_Before_PositionUpdated(shaderPart) {
|
245
359
|
this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
|
246
360
|
return this;
|
247
361
|
}
|
362
|
+
/**
|
363
|
+
* Sets the code on Vertex_Before_NormalUpdated portion
|
364
|
+
* @param shaderPart the code string
|
365
|
+
* @returns the current material
|
366
|
+
*/
|
248
367
|
Vertex_Before_NormalUpdated(shaderPart) {
|
249
368
|
this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
|
250
369
|
return this;
|
251
370
|
}
|
371
|
+
/**
|
372
|
+
* Sets the code on Vertex_After_WorldPosComputed portion
|
373
|
+
* @param shaderPart the code string
|
374
|
+
* @returns the current material
|
375
|
+
*/
|
252
376
|
Vertex_After_WorldPosComputed(shaderPart) {
|
253
377
|
this.CustomParts.Vertex_After_WorldPosComputed = shaderPart;
|
254
378
|
return this;
|
255
379
|
}
|
380
|
+
/**
|
381
|
+
* Sets the code on Vertex_MainEnd portion
|
382
|
+
* @param shaderPart the code string
|
383
|
+
* @returns the current material
|
384
|
+
*/
|
256
385
|
Vertex_MainEnd(shaderPart) {
|
257
386
|
this.CustomParts.Vertex_MainEnd = shaderPart;
|
258
387
|
return this;
|
259
388
|
}
|
260
389
|
}
|
390
|
+
/**
|
391
|
+
* Index for each created shader
|
392
|
+
*/
|
261
393
|
PBRCustomMaterial.ShaderIndexer = 1;
|
262
394
|
RegisterClass("BABYLON.PBRCustomMaterial", PBRCustomMaterial);
|
263
395
|
//# sourceMappingURL=pbrCustomMaterial.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pbrCustomMaterial.js","sourceRoot":"","sources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,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QAC7F,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,6BAA6B,CAAC,UAAkB;QACnD,IAAI,CAAC,WAAW,CAAC,6BAA6B,GAAG,UAAU,CAAC;QAC5D,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,cAAc,CAAC,UAAkB;QACpC,IAAI,CAAC,WAAW,CAAC,cAAc,GAAG,UAAU,CAAC;QAC7C,OAAO,IAAI,CAAC;IAChB,CAAC;;AA1Sa,+BAAa,GAAG,CAAC,CAAC;AA6SpC,aAAa,CAAC,2BAA2B,EAAE,iBAAiB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport type { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport { ShaderCodeInliner } from \"core/Engines/Processors/shaderCodeInliner\";\r\nimport type { ICustomShaderNameResolveOptions } from \"core/Materials/material\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nexport class ShaderAlbedoParts {\r\n constructor() {}\r\n\r\n public Fragment_Begin: string;\r\n public Fragment_Definitions: string;\r\n public Fragment_MainBegin: string;\r\n public Fragment_MainEnd: string;\r\n\r\n // albedoColor\r\n public Fragment_Custom_Albedo: string;\r\n // lights\r\n public Fragment_Before_Lights: string;\r\n // roughness\r\n public Fragment_Custom_MetallicRoughness: string;\r\n // microsurface\r\n public Fragment_Custom_MicroSurface: string;\r\n // fog\r\n public Fragment_Before_Fog: string;\r\n // alpha\r\n public Fragment_Custom_Alpha: string;\r\n // color composition\r\n public Fragment_Before_FinalColorComposition: string;\r\n // frag color\r\n public Fragment_Before_FragColor: string;\r\n\r\n public Vertex_Begin: string;\r\n public Vertex_Definitions: string;\r\n public Vertex_MainBegin: string;\r\n\r\n // positionUpdated\r\n public Vertex_Before_PositionUpdated: string;\r\n\r\n // normalUpdated\r\n public Vertex_Before_NormalUpdated: string;\r\n\r\n // worldPosComputed\r\n public Vertex_After_WorldPosComputed: string;\r\n\r\n // mainEnd\r\n public Vertex_MainEnd: string;\r\n}\r\n\r\n/**\r\n * @deprecated use ShaderAlbedoParts instead.\r\n */\r\nexport const ShaderAlebdoParts = ShaderAlbedoParts;\r\n\r\nexport class PBRCustomMaterial extends PBRMaterial {\r\n public static ShaderIndexer = 1;\r\n public CustomParts: ShaderAlbedoParts;\r\n _createdShaderName: string;\r\n _customUniform: string[];\r\n _newUniforms: string[];\r\n _newUniformInstances: { [name: string]: any };\r\n _newSamplerInstances: { [name: string]: Texture };\r\n _customAttributes: string[];\r\n\r\n public FragmentShader: string;\r\n public VertexShader: string;\r\n\r\n public AttachAfterBind(mesh: Mesh | undefined, effect: Effect) {\r\n if (this._newUniformInstances) {\r\n for (const el in this._newUniformInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"vec2\") {\r\n effect.setVector2(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"vec3\") {\r\n if (this._newUniformInstances[el] instanceof Color3) {\r\n effect.setColor3(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector3(ea[1], this._newUniformInstances[el]);\r\n }\r\n } else if (ea[0] == \"vec4\") {\r\n if (this._newUniformInstances[el] instanceof Color4) {\r\n effect.setDirectColor4(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n }\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"mat4\") {\r\n effect.setMatrix(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"float\") {\r\n effect.setFloat(ea[1], this._newUniformInstances[el]);\r\n }\r\n }\r\n }\r\n if (this._newSamplerInstances) {\r\n for (const el in this._newSamplerInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"sampler2D\" && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {\r\n effect.setTexture(ea[1], this._newSamplerInstances[el]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n public ReviewUniform(name: string, arr: string[]): string[] {\r\n if (name == \"uniform\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") == -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n if (name == \"sampler\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") != -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n return arr;\r\n }\r\n\r\n public Builder(\r\n shaderName: string,\r\n uniforms: string[],\r\n uniformBuffers: string[],\r\n samplers: string[],\r\n defines: MaterialDefines | string[],\r\n attributes?: string[],\r\n options?: ICustomShaderNameResolveOptions\r\n ): string {\r\n if (options) {\r\n const currentProcessing = options.processFinalCode;\r\n options.processFinalCode = (type: string, code: string) => {\r\n if (type === \"vertex\") {\r\n return currentProcessing ? currentProcessing(type, code) : code;\r\n }\r\n const sci = new ShaderCodeInliner(code);\r\n sci.inlineToken = \"#define pbr_inline\";\r\n sci.processCode();\r\n return currentProcessing ? currentProcessing(type, sci.code) : sci.code;\r\n };\r\n }\r\n\r\n if (attributes && this._customAttributes && this._customAttributes.length > 0) {\r\n attributes.push(...this._customAttributes);\r\n }\r\n\r\n this.ReviewUniform(\"uniform\", uniforms);\r\n this.ReviewUniform(\"sampler\", samplers);\r\n\r\n const name = this._createdShaderName;\r\n\r\n if (Effect.ShadersStore[name + \"VertexShader\"] && Effect.ShadersStore[name + \"PixelShader\"]) {\r\n return name;\r\n }\r\n Effect.ShadersStore[name + \"VertexShader\"] = this._injectCustomCode(this.VertexShader, \"vertex\");\r\n Effect.ShadersStore[name + \"PixelShader\"] = this._injectCustomCode(this.FragmentShader, \"fragment\");\r\n\r\n return name;\r\n }\r\n\r\n protected _injectCustomCode(code: string, shaderType: string): string {\r\n const customCode = this._getCustomCode(shaderType);\r\n\r\n for (const point in customCode) {\r\n const injectedCode = customCode[point];\r\n\r\n if (injectedCode && injectedCode.length > 0) {\r\n const fullPointName = \"#define \" + point;\r\n code = code.replace(fullPointName, \"\\n\" + injectedCode + \"\\n\" + fullPointName);\r\n }\r\n }\r\n\r\n return code;\r\n }\r\n\r\n protected _getCustomCode(shaderType: string): { [pointName: string]: string } {\r\n if (shaderType === \"vertex\") {\r\n return {\r\n CUSTOM_VERTEX_BEGIN: this.CustomParts.Vertex_Begin,\r\n CUSTOM_VERTEX_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Vertex_Definitions || \"\"),\r\n CUSTOM_VERTEX_MAIN_BEGIN: this.CustomParts.Vertex_MainBegin,\r\n CUSTOM_VERTEX_UPDATE_POSITION: this.CustomParts.Vertex_Before_PositionUpdated,\r\n CUSTOM_VERTEX_UPDATE_NORMAL: this.CustomParts.Vertex_Before_NormalUpdated,\r\n CUSTOM_VERTEX_MAIN_END: this.CustomParts.Vertex_MainEnd,\r\n CUSTOM_VERTEX_UPDATE_WORLDPOS: this.CustomParts.Vertex_After_WorldPosComputed,\r\n };\r\n }\r\n return {\r\n CUSTOM_FRAGMENT_BEGIN: this.CustomParts.Fragment_Begin,\r\n CUSTOM_FRAGMENT_MAIN_BEGIN: this.CustomParts.Fragment_MainBegin,\r\n CUSTOM_FRAGMENT_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Fragment_Definitions || \"\"),\r\n CUSTOM_FRAGMENT_UPDATE_ALBEDO: this.CustomParts.Fragment_Custom_Albedo,\r\n CUSTOM_FRAGMENT_UPDATE_ALPHA: this.CustomParts.Fragment_Custom_Alpha,\r\n CUSTOM_FRAGMENT_BEFORE_LIGHTS: this.CustomParts.Fragment_Before_Lights,\r\n CUSTOM_FRAGMENT_UPDATE_METALLICROUGHNESS: this.CustomParts.Fragment_Custom_MetallicRoughness,\r\n CUSTOM_FRAGMENT_UPDATE_MICROSURFACE: this.CustomParts.Fragment_Custom_MicroSurface,\r\n CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: this.CustomParts.Fragment_Before_FinalColorComposition,\r\n CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: this.CustomParts.Fragment_Before_FragColor,\r\n CUSTOM_FRAGMENT_MAIN_END: this.CustomParts.Fragment_MainEnd,\r\n CUSTOM_FRAGMENT_BEFORE_FOG: this.CustomParts.Fragment_Before_Fog,\r\n };\r\n }\r\n\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n this.CustomParts = new ShaderAlbedoParts();\r\n this.customShaderNameResolve = this.Builder;\r\n\r\n this.FragmentShader = Effect.ShadersStore[\"pbrPixelShader\"];\r\n this.VertexShader = Effect.ShadersStore[\"pbrVertexShader\"];\r\n\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockAlbedoOpacity>/g, Effect.IncludesShadersStore[\"pbrBlockAlbedoOpacity\"]);\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockReflectivity>/g, Effect.IncludesShadersStore[\"pbrBlockReflectivity\"]);\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockFinalColorComposition>/g, Effect.IncludesShadersStore[\"pbrBlockFinalColorComposition\"]);\r\n\r\n PBRCustomMaterial.ShaderIndexer++;\r\n this._createdShaderName = \"custompbr_\" + PBRCustomMaterial.ShaderIndexer;\r\n }\r\n\r\n protected _afterBind(mesh?: Mesh, effect: Nullable<Effect> = null): void {\r\n if (!effect) {\r\n return;\r\n }\r\n this.AttachAfterBind(mesh, effect);\r\n try {\r\n super._afterBind(mesh, effect);\r\n } catch (e) {}\r\n }\r\n\r\n public AddUniform(name: string, kind: string, param: any): PBRCustomMaterial {\r\n if (!this._customUniform) {\r\n this._customUniform = new Array();\r\n this._newUniforms = new Array();\r\n this._newSamplerInstances = {};\r\n this._newUniformInstances = {};\r\n }\r\n if (param) {\r\n if (kind.indexOf(\"sampler\") != -1) {\r\n (<any>this._newSamplerInstances)[kind + \"-\" + name] = param;\r\n } else {\r\n (<any>this._newUniformInstances)[kind + \"-\" + name] = param;\r\n }\r\n }\r\n this._customUniform.push(\"uniform \" + kind + \" \" + name + \";\");\r\n this._newUniforms.push(name);\r\n\r\n return this;\r\n }\r\n\r\n public AddAttribute(name: string): PBRCustomMaterial {\r\n if (!this._customAttributes) {\r\n this._customAttributes = [];\r\n }\r\n\r\n this._customAttributes.push(name);\r\n\r\n return this;\r\n }\r\n\r\n public Fragment_Begin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Definitions(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_MainBegin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_Albedo(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_Albedo = shaderPart.replace(\"result\", \"surfaceAlbedo\");\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_Alpha(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace(\"result\", \"alpha\");\r\n return this;\r\n }\r\n\r\n public Fragment_Before_Lights(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_Lights = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_MetallicRoughness(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_MetallicRoughness = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_MicroSurface(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_MicroSurface = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_Fog(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_Fog = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_FinalColorComposition(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_FinalColorComposition = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_FragColor(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_FragColor = shaderPart.replace(\"result\", \"color\");\r\n return this;\r\n }\r\n\r\n public Fragment_MainEnd(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_MainEnd = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Begin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Definitions(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_MainBegin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Before_PositionUpdated(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace(\"result\", \"positionUpdated\");\r\n return this;\r\n }\r\n\r\n public Vertex_Before_NormalUpdated(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace(\"result\", \"normalUpdated\");\r\n return this;\r\n }\r\n\r\n public Vertex_After_WorldPosComputed(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_After_WorldPosComputed = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_MainEnd(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_MainEnd = shaderPart;\r\n return this;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.PBRCustomMaterial\", PBRCustomMaterial);\r\n"]}
|
1
|
+
{"version":3,"file":"pbrCustomMaterial.js","sourceRoot":"","sources":["../../../../dev/materials/src/custom/pbrCustomMaterial.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAE/C,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAG7D,OAAO,EAAE,aAAa,EAAE,0CAA4B;AACpD,OAAO,EAAE,iBAAiB,EAAE,gEAAkD;AAE9E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,4CAA8B;AAGvD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAC1B,gBAAe,CAAC;CAoFnB;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAEnD,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IA2C9C;;;;OAIG;IACI,eAAe,CAAC,IAAsB,EAAE,MAAc;QACzD,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,oBAAoB,EAAE;gBACxC,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACpC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE;oBACjB,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC;iBAC3D;qBAAM,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE;oBACxB,IAAI,IAAI,CAAC,oBAAoB,CAAC,EAAE,CAAC,YAAY,MAAM,EAAE;wBACjD,MAAM,CAAC,SAAS,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AC;IAChB,CAAC;IAED;;;;OAIG;IACI,kBAAkB,CAAC,UAAkB;QACxC,IAAI,CAAC,WAAW,CAAC,kBAAkB,GAAG,UAAU,CAAC;QACjD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACI,gBAAgB,CAAC,UAAkB;QACtC,IAAI,CAAC,WAAW,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAC/C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACI,6BAA6B,CAAC,UAAkB;QACnD,IAAI,CAAC,WAAW,CAAC,6BAA6B,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;QACjG,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACI,2BAA2B,CAAC,UAAkB;QACjD,IAAI,CAAC,WAAW,CAAC,2BAA2B,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QAC7F,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACI,6BAA6B,CAAC,UAAkB;QACnD,IAAI,CAAC,WAAW,CAAC,6BAA6B,GAAG,UAAU,CAAC;QAC5D,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACI,cAAc,CAAC,UAAkB;QACpC,IAAI,CAAC,WAAW,CAAC,cAAc,GAAG,UAAU,CAAC;QAC7C,OAAO,IAAI,CAAC;IAChB,CAAC;;AAtcD;;GAEG;AACW,+BAAa,GAAG,CAAC,CAAC;AAscpC,aAAa,CAAC,2BAA2B,EAAE,iBAAiB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport type { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport { ShaderCodeInliner } from \"core/Engines/Processors/shaderCodeInliner\";\r\nimport type { ICustomShaderNameResolveOptions } from \"core/Materials/material\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\n/**\r\n * Albedo parts of the shader\r\n */\r\nexport class ShaderAlbedoParts {\r\n constructor() {}\r\n\r\n /**\r\n * Beginning of the fragment shader\r\n */\r\n public Fragment_Begin: string;\r\n /**\r\n * Fragment definitions\r\n */\r\n public Fragment_Definitions: string;\r\n /**\r\n * Beginning of the main function\r\n */\r\n public Fragment_MainBegin: string;\r\n /**\r\n * End of main function\r\n */\r\n public Fragment_MainEnd: string;\r\n\r\n /**\r\n * Albedo color\r\n */\r\n public Fragment_Custom_Albedo: string;\r\n /**\r\n * Lights\r\n */\r\n public Fragment_Before_Lights: string;\r\n /**\r\n * Metallic and roughness\r\n */\r\n public Fragment_Custom_MetallicRoughness: string;\r\n /**\r\n * Microsurface\r\n */\r\n public Fragment_Custom_MicroSurface: string;\r\n /**\r\n * Fog computations\r\n */\r\n public Fragment_Before_Fog: string;\r\n /**\r\n * Alpha\r\n */\r\n public Fragment_Custom_Alpha: string;\r\n /**\r\n * Color composition\r\n */\r\n public Fragment_Before_FinalColorComposition: string;\r\n /**\r\n * Fragment color\r\n */\r\n public Fragment_Before_FragColor: string;\r\n\r\n /**\r\n * Beginning of vertex shader\r\n */\r\n public Vertex_Begin: string;\r\n /**\r\n * Vertex definitions\r\n */\r\n public Vertex_Definitions: string;\r\n /**\r\n * Vertex main begin\r\n */\r\n public Vertex_MainBegin: string;\r\n\r\n /**\r\n * Vertex before position updated\r\n */\r\n public Vertex_Before_PositionUpdated: string;\r\n\r\n /**\r\n * Vertex before normal updated\r\n */\r\n public Vertex_Before_NormalUpdated: string;\r\n\r\n /**\r\n * Vertex after world pos computed\r\n */\r\n public Vertex_After_WorldPosComputed: string;\r\n\r\n /**\r\n * Vertex main end\r\n */\r\n public Vertex_MainEnd: string;\r\n}\r\n\r\n/**\r\n * @deprecated use ShaderAlbedoParts instead.\r\n */\r\nexport const ShaderAlebdoParts = ShaderAlbedoParts;\r\n\r\nexport class PBRCustomMaterial extends PBRMaterial {\r\n /**\r\n * Index for each created shader\r\n */\r\n public static ShaderIndexer = 1;\r\n /**\r\n * Custom shader structure\r\n */\r\n public CustomParts: ShaderAlbedoParts;\r\n /**\r\n * Name of the shader\r\n */\r\n _createdShaderName: string;\r\n /**\r\n * List of custom uniforms\r\n */\r\n _customUniform: string[];\r\n /**\r\n * Names of the new uniforms\r\n */\r\n _newUniforms: string[];\r\n /**\r\n * Instances of the new uniform objects\r\n */\r\n _newUniformInstances: { [name: string]: any };\r\n /**\r\n * Instances of the new sampler objects\r\n */\r\n _newSamplerInstances: { [name: string]: Texture };\r\n /**\r\n * List of the custom attributes\r\n */\r\n _customAttributes: string[];\r\n\r\n /**\r\n * Fragment shader string\r\n */\r\n public FragmentShader: string;\r\n /**\r\n * Vertex shader string\r\n */\r\n public VertexShader: string;\r\n\r\n /**\r\n * Runs after the material is bound to a mesh\r\n * @param mesh mesh bound\r\n * @param effect bound effect used to render\r\n */\r\n public AttachAfterBind(mesh: Mesh | undefined, effect: Effect) {\r\n if (this._newUniformInstances) {\r\n for (const el in this._newUniformInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"vec2\") {\r\n effect.setVector2(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"vec3\") {\r\n if (this._newUniformInstances[el] instanceof Color3) {\r\n effect.setColor3(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector3(ea[1], this._newUniformInstances[el]);\r\n }\r\n } else if (ea[0] == \"vec4\") {\r\n if (this._newUniformInstances[el] instanceof Color4) {\r\n effect.setDirectColor4(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n }\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"mat4\") {\r\n effect.setMatrix(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"float\") {\r\n effect.setFloat(ea[1], this._newUniformInstances[el]);\r\n }\r\n }\r\n }\r\n if (this._newSamplerInstances) {\r\n for (const el in this._newSamplerInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"sampler2D\" && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {\r\n effect.setTexture(ea[1], this._newSamplerInstances[el]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public ReviewUniform(name: string, arr: string[]): string[] {\r\n if (name == \"uniform\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") == -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n if (name == \"sampler\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") != -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n return arr;\r\n }\r\n\r\n /**\r\n * Builds the material\r\n * @param shaderName name of the shader\r\n * @param uniforms list of uniforms\r\n * @param uniformBuffers list of uniform buffers\r\n * @param samplers list of samplers\r\n * @param defines list of defines\r\n * @param attributes list of attributes\r\n * @param options options to compile the shader\r\n * @returns the shader name\r\n */\r\n public Builder(\r\n shaderName: string,\r\n uniforms: string[],\r\n uniformBuffers: string[],\r\n samplers: string[],\r\n defines: MaterialDefines | string[],\r\n attributes?: string[],\r\n options?: ICustomShaderNameResolveOptions\r\n ): string {\r\n if (options) {\r\n const currentProcessing = options.processFinalCode;\r\n options.processFinalCode = (type: string, code: string) => {\r\n if (type === \"vertex\") {\r\n return currentProcessing ? currentProcessing(type, code) : code;\r\n }\r\n const sci = new ShaderCodeInliner(code);\r\n sci.inlineToken = \"#define pbr_inline\";\r\n sci.processCode();\r\n return currentProcessing ? currentProcessing(type, sci.code) : sci.code;\r\n };\r\n }\r\n\r\n if (attributes && this._customAttributes && this._customAttributes.length > 0) {\r\n attributes.push(...this._customAttributes);\r\n }\r\n\r\n this.ReviewUniform(\"uniform\", uniforms);\r\n this.ReviewUniform(\"sampler\", samplers);\r\n\r\n const name = this._createdShaderName;\r\n\r\n if (Effect.ShadersStore[name + \"VertexShader\"] && Effect.ShadersStore[name + \"PixelShader\"]) {\r\n return name;\r\n }\r\n Effect.ShadersStore[name + \"VertexShader\"] = this._injectCustomCode(this.VertexShader, \"vertex\");\r\n Effect.ShadersStore[name + \"PixelShader\"] = this._injectCustomCode(this.FragmentShader, \"fragment\");\r\n\r\n return name;\r\n }\r\n\r\n protected _injectCustomCode(code: string, shaderType: string): string {\r\n const customCode = this._getCustomCode(shaderType);\r\n\r\n for (const point in customCode) {\r\n const injectedCode = customCode[point];\r\n\r\n if (injectedCode && injectedCode.length > 0) {\r\n const fullPointName = \"#define \" + point;\r\n code = code.replace(fullPointName, \"\\n\" + injectedCode + \"\\n\" + fullPointName);\r\n }\r\n }\r\n\r\n return code;\r\n }\r\n\r\n protected _getCustomCode(shaderType: string): { [pointName: string]: string } {\r\n if (shaderType === \"vertex\") {\r\n return {\r\n CUSTOM_VERTEX_BEGIN: this.CustomParts.Vertex_Begin,\r\n CUSTOM_VERTEX_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Vertex_Definitions || \"\"),\r\n CUSTOM_VERTEX_MAIN_BEGIN: this.CustomParts.Vertex_MainBegin,\r\n CUSTOM_VERTEX_UPDATE_POSITION: this.CustomParts.Vertex_Before_PositionUpdated,\r\n CUSTOM_VERTEX_UPDATE_NORMAL: this.CustomParts.Vertex_Before_NormalUpdated,\r\n CUSTOM_VERTEX_MAIN_END: this.CustomParts.Vertex_MainEnd,\r\n CUSTOM_VERTEX_UPDATE_WORLDPOS: this.CustomParts.Vertex_After_WorldPosComputed,\r\n };\r\n }\r\n return {\r\n CUSTOM_FRAGMENT_BEGIN: this.CustomParts.Fragment_Begin,\r\n CUSTOM_FRAGMENT_MAIN_BEGIN: this.CustomParts.Fragment_MainBegin,\r\n CUSTOM_FRAGMENT_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Fragment_Definitions || \"\"),\r\n CUSTOM_FRAGMENT_UPDATE_ALBEDO: this.CustomParts.Fragment_Custom_Albedo,\r\n CUSTOM_FRAGMENT_UPDATE_ALPHA: this.CustomParts.Fragment_Custom_Alpha,\r\n CUSTOM_FRAGMENT_BEFORE_LIGHTS: this.CustomParts.Fragment_Before_Lights,\r\n CUSTOM_FRAGMENT_UPDATE_METALLICROUGHNESS: this.CustomParts.Fragment_Custom_MetallicRoughness,\r\n CUSTOM_FRAGMENT_UPDATE_MICROSURFACE: this.CustomParts.Fragment_Custom_MicroSurface,\r\n CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: this.CustomParts.Fragment_Before_FinalColorComposition,\r\n CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: this.CustomParts.Fragment_Before_FragColor,\r\n CUSTOM_FRAGMENT_MAIN_END: this.CustomParts.Fragment_MainEnd,\r\n CUSTOM_FRAGMENT_BEFORE_FOG: this.CustomParts.Fragment_Before_Fog,\r\n };\r\n }\r\n\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n this.CustomParts = new ShaderAlbedoParts();\r\n this.customShaderNameResolve = this.Builder;\r\n\r\n this.FragmentShader = Effect.ShadersStore[\"pbrPixelShader\"];\r\n this.VertexShader = Effect.ShadersStore[\"pbrVertexShader\"];\r\n\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockAlbedoOpacity>/g, Effect.IncludesShadersStore[\"pbrBlockAlbedoOpacity\"]);\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockReflectivity>/g, Effect.IncludesShadersStore[\"pbrBlockReflectivity\"]);\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockFinalColorComposition>/g, Effect.IncludesShadersStore[\"pbrBlockFinalColorComposition\"]);\r\n\r\n PBRCustomMaterial.ShaderIndexer++;\r\n this._createdShaderName = \"custompbr_\" + PBRCustomMaterial.ShaderIndexer;\r\n }\r\n\r\n protected _afterBind(mesh?: Mesh, effect: Nullable<Effect> = null): void {\r\n if (!effect) {\r\n return;\r\n }\r\n this.AttachAfterBind(mesh, effect);\r\n try {\r\n super._afterBind(mesh, effect);\r\n } catch (e) {}\r\n }\r\n\r\n /**\r\n * Adds a new uniform to the shader\r\n * @param name the name of the uniform to add\r\n * @param kind the type of the uniform to add\r\n * @param param the value of the uniform to add\r\n * @returns the current material\r\n */\r\n public AddUniform(name: string, kind: string, param: any): PBRCustomMaterial {\r\n if (!this._customUniform) {\r\n this._customUniform = new Array();\r\n this._newUniforms = new Array();\r\n this._newSamplerInstances = {};\r\n this._newUniformInstances = {};\r\n }\r\n if (param) {\r\n if (kind.indexOf(\"sampler\") != -1) {\r\n (<any>this._newSamplerInstances)[kind + \"-\" + name] = param;\r\n } else {\r\n (<any>this._newUniformInstances)[kind + \"-\" + name] = param;\r\n }\r\n }\r\n this._customUniform.push(\"uniform \" + kind + \" \" + name + \";\");\r\n this._newUniforms.push(name);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a custom attribute\r\n * @param name the name of the attribute\r\n * @returns the current material\r\n */\r\n public AddAttribute(name: string): PBRCustomMaterial {\r\n if (!this._customAttributes) {\r\n this._customAttributes = [];\r\n }\r\n\r\n this._customAttributes.push(name);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_Begin portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_Begin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_Definitions portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_Definitions(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_MainBegin portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_MainBegin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_Custom_Albedo portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_Custom_Albedo(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_Albedo = shaderPart.replace(\"result\", \"surfaceAlbedo\");\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_Custom_Alpha portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_Custom_Alpha(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace(\"result\", \"alpha\");\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_Before_Lights portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_Before_Lights(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_Lights = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_Custom_MetallicRoughness portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_Custom_MetallicRoughness(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_MetallicRoughness = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_Custom_MicroSurface portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_Custom_MicroSurface(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_MicroSurface = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_Before_Fog portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_Before_Fog(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_Fog = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_Before_FinalColorComposition portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_Before_FinalColorComposition(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_FinalColorComposition = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_Before_FragColor portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_Before_FragColor(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_FragColor = shaderPart.replace(\"result\", \"color\");\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Fragment_MainEnd portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Fragment_MainEnd(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_MainEnd = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Vertex_Begin portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Vertex_Begin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Vertex_Definitions portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Vertex_Definitions(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Vertex_MainBegin portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Vertex_MainBegin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Vertex_Before_PositionUpdated portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Vertex_Before_PositionUpdated(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace(\"result\", \"positionUpdated\");\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Vertex_Before_NormalUpdated portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Vertex_Before_NormalUpdated(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace(\"result\", \"normalUpdated\");\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Vertex_After_WorldPosComputed portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Vertex_After_WorldPosComputed(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_After_WorldPosComputed = shaderPart;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the code on Vertex_MainEnd portion\r\n * @param shaderPart the code string\r\n * @returns the current material\r\n */\r\n public Vertex_MainEnd(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_MainEnd = shaderPart;\r\n return this;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.PBRCustomMaterial\", PBRCustomMaterial);\r\n"]}
|