@babylonjs/core 7.3.2 → 7.3.3
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/Compute/computeEffect.js +4 -4
- package/Compute/computeEffect.js.map +1 -1
- package/Engines/IPipelineContext.d.ts +3 -0
- package/Engines/IPipelineContext.js.map +1 -1
- package/Engines/Native/nativePipelineContext.d.ts +2 -0
- package/Engines/Native/nativePipelineContext.js +3 -0
- package/Engines/Native/nativePipelineContext.js.map +1 -1
- package/Engines/Processors/iShaderProcessor.d.ts +3 -2
- package/Engines/Processors/iShaderProcessor.js.map +1 -1
- package/Engines/Processors/shaderProcessor.d.ts +15 -23
- package/Engines/Processors/shaderProcessor.js +332 -320
- package/Engines/Processors/shaderProcessor.js.map +1 -1
- package/Engines/WebGL/webGLPipelineContext.d.ts +2 -0
- package/Engines/WebGL/webGLPipelineContext.js +3 -0
- package/Engines/WebGL/webGLPipelineContext.js.map +1 -1
- package/Engines/WebGL/webGLShaderProcessors.d.ts +3 -2
- package/Engines/WebGL/webGLShaderProcessors.js +2 -2
- package/Engines/WebGL/webGLShaderProcessors.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.computeShader.js +1 -1
- package/Engines/WebGPU/Extensions/engine.computeShader.js.map +1 -1
- package/Engines/WebGPU/webgpuPipelineContext.d.ts +2 -0
- package/Engines/WebGPU/webgpuPipelineContext.js +3 -0
- package/Engines/WebGPU/webgpuPipelineContext.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessorsGLSL.d.ts +3 -2
- package/Engines/WebGPU/webgpuShaderProcessorsGLSL.js +2 -4
- package/Engines/WebGPU/webgpuShaderProcessorsGLSL.js.map +1 -1
- package/Engines/abstractEngine.d.ts +10 -5
- package/Engines/abstractEngine.functions.d.ts +38 -0
- package/Engines/abstractEngine.functions.js +75 -0
- package/Engines/abstractEngine.functions.js.map +1 -0
- package/Engines/abstractEngine.js +22 -14
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/constants.d.ts +2 -0
- package/Engines/constants.js +2 -0
- package/Engines/constants.js.map +1 -1
- package/Engines/thinEngine.d.ts +11 -6
- package/Engines/thinEngine.functions.d.ts +96 -0
- package/Engines/thinEngine.functions.js +249 -0
- package/Engines/thinEngine.functions.js.map +1 -0
- package/Engines/thinEngine.js +50 -129
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +5 -1
- package/Engines/webgpuEngine.js.map +1 -1
- package/Materials/Node/Blocks/Dual/textureBlock.js +3 -3
- package/Materials/Node/Blocks/Dual/textureBlock.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.d.ts +9 -1
- package/Materials/Textures/Procedurals/proceduralTexture.js +16 -0
- package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
- package/Materials/effect.d.ts +11 -6
- package/Materials/effect.functions.d.ts +86 -0
- package/Materials/effect.functions.js +185 -0
- package/Materials/effect.functions.js.map +1 -0
- package/Materials/effect.js +94 -153
- package/Materials/effect.js.map +1 -1
- package/Materials/effect.webgl.functions.d.ts +13 -0
- package/Materials/effect.webgl.functions.js +83 -0
- package/Materials/effect.webgl.functions.js.map +1 -0
- package/Materials/materialPluginManager.js +2 -2
- package/Materials/materialPluginManager.js.map +1 -1
- package/Meshes/Compression/dracoCompression.js.map +1 -1
- package/Meshes/Compression/dracoCompressionWorker.d.ts +1 -1
- package/Meshes/Compression/dracoCompressionWorker.js +21 -10
- package/Meshes/Compression/dracoCompressionWorker.js.map +1 -1
- package/Meshes/Node/nodeGeometryBlock.js +1 -0
- package/Meshes/Node/nodeGeometryBlock.js.map +1 -1
- package/Misc/fileTools.js +4 -3
- package/Misc/fileTools.js.map +1 -1
- package/package.json +1 -1
package/Materials/effect.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { InternalTexture } from "../Materials/Textures/internalTexture";
|
|
|
13
13
|
import type { ThinTexture } from "../Materials/Textures/thinTexture";
|
|
14
14
|
import type { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
|
|
15
15
|
import type { PostProcess } from "../PostProcesses/postProcess";
|
|
16
|
+
import type { IPipelineGenerationOptions } from "./effect.functions";
|
|
16
17
|
/**
|
|
17
18
|
* Defines the route to the shader code. The priority is as follows:
|
|
18
19
|
* * object: `{ vertexSource: "vertex shader code string", fragmentSource: "fragment shader code string" }` for directly passing the shader code
|
|
@@ -112,6 +113,10 @@ export interface IEffectCreationOptions {
|
|
|
112
113
|
* The language the shader is written in (default: GLSL)
|
|
113
114
|
*/
|
|
114
115
|
shaderLanguage?: ShaderLanguage;
|
|
116
|
+
/**
|
|
117
|
+
* Provide an existing pipeline context to avoid creating a new one
|
|
118
|
+
*/
|
|
119
|
+
existingPipelineContext?: IPipelineContext;
|
|
115
120
|
}
|
|
116
121
|
/**
|
|
117
122
|
* Effect containing vertex and fragment shader that can be executed on an object.
|
|
@@ -210,13 +215,13 @@ export declare class Effect implements IDisposable {
|
|
|
210
215
|
/** @internal */
|
|
211
216
|
_fragmentSourceCode: string;
|
|
212
217
|
/** @internal */
|
|
213
|
-
|
|
218
|
+
_vertexSourceCodeBeforeMigration: string;
|
|
214
219
|
/** @internal */
|
|
215
|
-
|
|
220
|
+
_fragmentSourceCodeBeforeMigration: string;
|
|
216
221
|
/** @internal */
|
|
217
|
-
|
|
222
|
+
_rawVertexSourceCode: string;
|
|
218
223
|
/** @internal */
|
|
219
|
-
|
|
224
|
+
_rawFragmentSourceCode: string;
|
|
220
225
|
private static _BaseCache;
|
|
221
226
|
private _processingContext;
|
|
222
227
|
private _processCodeAfterIncludes;
|
|
@@ -244,7 +249,6 @@ export declare class Effect implements IDisposable {
|
|
|
244
249
|
constructor(baseName: IShaderPath | string, attributesNamesOrOptions: string[] | IEffectCreationOptions, uniformsNamesOrEngine: string[] | AbstractEngine, samplers?: Nullable<string[]>, engine?: AbstractEngine, defines?: Nullable<string>, fallbacks?: Nullable<IEffectFallbacks>, onCompiled?: Nullable<(effect: Effect) => void>, onError?: Nullable<(effect: Effect, errors: string) => void>, indexParameters?: any, key?: string, shaderLanguage?: ShaderLanguage);
|
|
245
250
|
/** @internal */
|
|
246
251
|
_processShaderCode(shaderProcessor?: Nullable<IShaderProcessor>, keepExistingPipelineContext?: boolean): void;
|
|
247
|
-
private _useFinalCode;
|
|
248
252
|
/**
|
|
249
253
|
* Unique key for this effect
|
|
250
254
|
*/
|
|
@@ -335,7 +339,6 @@ export declare class Effect implements IDisposable {
|
|
|
335
339
|
*/
|
|
336
340
|
executeWhenCompiled(func: (effect: Effect) => void): void;
|
|
337
341
|
private _checkIsReady;
|
|
338
|
-
private _loadShader;
|
|
339
342
|
/**
|
|
340
343
|
* Gets the vertex shader source code of this effect
|
|
341
344
|
* This is the final source code that will be compiled, after all the processing has been done (pre-processing applied, code injection/replacement, etc)
|
|
@@ -366,6 +369,7 @@ export declare class Effect implements IDisposable {
|
|
|
366
369
|
* Gets the fragment shader source code before it has been modified by any processing
|
|
367
370
|
*/
|
|
368
371
|
get rawFragmentSourceCode(): string;
|
|
372
|
+
getPipelineGenerationOptions(): IPipelineGenerationOptions;
|
|
369
373
|
/**
|
|
370
374
|
* Recompiles the webGL program
|
|
371
375
|
* @param vertexSourceCode The source code for the vertex shader.
|
|
@@ -375,6 +379,7 @@ export declare class Effect implements IDisposable {
|
|
|
375
379
|
* @internal
|
|
376
380
|
*/
|
|
377
381
|
_rebuildProgram(vertexSourceCode: string, fragmentSourceCode: string, onCompiled: (pipelineContext: IPipelineContext) => void, onError: (message: string) => void): void;
|
|
382
|
+
private _onRenderingStateCompiled;
|
|
378
383
|
/**
|
|
379
384
|
* Prepares the effect
|
|
380
385
|
* @internal
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ProcessingOptions, ShaderCustomProcessingFunction, ShaderProcessingContext } from "../Engines/Processors/shaderProcessingOptions.js";
|
|
2
|
+
import type { Nullable } from "../types.js";
|
|
3
|
+
import { ShaderLanguage } from "./shaderLanguage";
|
|
4
|
+
import type { WebGLContext } from "../Engines/thinEngine.functions.js";
|
|
5
|
+
import type { AbstractEngine } from "../Engines/abstractEngine.js";
|
|
6
|
+
import type { Effect, IShaderPath } from "./effect";
|
|
7
|
+
import type { IPipelineContext } from "../Engines/IPipelineContext.js";
|
|
8
|
+
/**
|
|
9
|
+
* Options to be used when creating a pipeline
|
|
10
|
+
*/
|
|
11
|
+
export interface IPipelineGenerationOptions {
|
|
12
|
+
/**
|
|
13
|
+
* The definition of the shader content.
|
|
14
|
+
* Can be either a unified name, name per vertex and frament or the shader code content itself
|
|
15
|
+
*/
|
|
16
|
+
shaderNameOrContent: string | IShaderPath;
|
|
17
|
+
/**
|
|
18
|
+
* Unique key to identify the pipeline.
|
|
19
|
+
* Note that though not mandatory, it's recommended to provide a key to be able to use the automated pipeline loading system.
|
|
20
|
+
*/
|
|
21
|
+
key?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The list of defines to be used in the shader
|
|
24
|
+
*/
|
|
25
|
+
defines?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* If true, the global defines will be added to the defines array
|
|
28
|
+
*/
|
|
29
|
+
addGlobalDefines?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The shader language.
|
|
32
|
+
* Defaults to the language suiting the platform name (GLSL for WEBGL2, WGSL for WEBGPU)
|
|
33
|
+
*/
|
|
34
|
+
shaderLanguage?: ShaderLanguage;
|
|
35
|
+
/**
|
|
36
|
+
* The name of the platform to be used when processing the shader
|
|
37
|
+
* defaults to WEBGL2
|
|
38
|
+
*/
|
|
39
|
+
platformName?: string;
|
|
40
|
+
/**
|
|
41
|
+
* extend the processing options when running code processing
|
|
42
|
+
*/
|
|
43
|
+
extendedProcessingOptions?: Partial<ProcessingOptions>;
|
|
44
|
+
/**
|
|
45
|
+
* extend the pipeline generation options
|
|
46
|
+
*/
|
|
47
|
+
extendedCreatePipelineOptions?: Partial<ICreateAndPreparePipelineContextOptions>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
export interface ICreateAndPreparePipelineContextOptions {
|
|
53
|
+
parallelShaderCompile?: {
|
|
54
|
+
COMPLETION_STATUS_KHR: number;
|
|
55
|
+
};
|
|
56
|
+
shaderProcessingContext: Nullable<ShaderProcessingContext>;
|
|
57
|
+
existingPipelineContext?: Nullable<IPipelineContext>;
|
|
58
|
+
name?: string;
|
|
59
|
+
rebuildRebind?: (vertexSourceCode: string, fragmentSourceCode: string, onCompiled: (pipelineContext: IPipelineContext) => void, onError: (message: string) => void) => void;
|
|
60
|
+
onRenderingStateCompiled?: (pipelineContext?: IPipelineContext) => void;
|
|
61
|
+
context?: WebGL2RenderingContext | WebGLRenderingContext;
|
|
62
|
+
createAsRaw?: boolean;
|
|
63
|
+
vertex: string;
|
|
64
|
+
fragment: string;
|
|
65
|
+
defines: Nullable<string>;
|
|
66
|
+
transformFeedbackVaryings: Nullable<string[]>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get a cached pipeline context
|
|
70
|
+
* @param name the pipeline name
|
|
71
|
+
* @param context the context to be used when creating the pipeline
|
|
72
|
+
* @returns the cached pipeline context if it exists
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
export declare function getCachedPipeline(name: string, context: WebGLContext): IPipelineContext | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
export declare function resetCachedPipeline(pipeline: IPipelineContext): void;
|
|
80
|
+
/** @internal */
|
|
81
|
+
export declare function _processShaderCode(processorOptions: ProcessingOptions, baseName: any, processFinalCode?: Nullable<ShaderCustomProcessingFunction>, onFinalCodeReady?: (vertexCode: string, fragmentCode: string) => void, shaderLanguage?: ShaderLanguage, engine?: AbstractEngine, effectContext?: Effect): void;
|
|
82
|
+
/**
|
|
83
|
+
* Creates and prepares a pipeline context
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
export declare const createAndPreparePipelineContext: (options: ICreateAndPreparePipelineContextOptions, createPipelineContext: (shaderProcessingContext: Nullable<ShaderProcessingContext>) => IPipelineContext, _preparePipelineContext: (pipelineContext: IPipelineContext, vertexSourceCode: string, fragmentSourceCode: string, createAsRaw: boolean, rawVertexSourceCode: string, rawFragmentSourceCode: string, rebuildRebind: any, defines: Nullable<string>, transformFeedbackVaryings: Nullable<string[]>, key: string) => void) => IPipelineContext;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { GetDOMTextContent, IsWindowObjectExist } from "../Misc/domManagement.js";
|
|
2
|
+
import { ShaderLanguage } from "./shaderLanguage.js";
|
|
3
|
+
import { _executeWhenRenderingStateIsCompiled, getStateObject } from "../Engines/thinEngine.functions.js";
|
|
4
|
+
import { ShaderStore } from "../Engines/shaderStore.js";
|
|
5
|
+
import { Logger } from "../Misc/logger.js";
|
|
6
|
+
import { Finalize, Initialize, Process } from "../Engines/Processors/shaderProcessor.js";
|
|
7
|
+
/**
|
|
8
|
+
* Get a cached pipeline context
|
|
9
|
+
* @param name the pipeline name
|
|
10
|
+
* @param context the context to be used when creating the pipeline
|
|
11
|
+
* @returns the cached pipeline context if it exists
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export function getCachedPipeline(name, context) {
|
|
15
|
+
const stateObject = getStateObject(context);
|
|
16
|
+
return stateObject.cachedPipelines[name];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export function resetCachedPipeline(pipeline) {
|
|
22
|
+
const name = pipeline._name;
|
|
23
|
+
const context = pipeline.context;
|
|
24
|
+
if (name && context) {
|
|
25
|
+
const stateObject = getStateObject(context);
|
|
26
|
+
const cachedPipeline = stateObject.cachedPipelines[name];
|
|
27
|
+
cachedPipeline?.dispose();
|
|
28
|
+
delete stateObject.cachedPipelines[name];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** @internal */
|
|
32
|
+
export function _processShaderCode(processorOptions, baseName, processFinalCode, onFinalCodeReady, shaderLanguage, engine, effectContext) {
|
|
33
|
+
let vertexSource;
|
|
34
|
+
let fragmentSource;
|
|
35
|
+
// const baseName = this.name;
|
|
36
|
+
const hostDocument = IsWindowObjectExist() ? engine?.getHostDocument() : null;
|
|
37
|
+
if (typeof baseName === "string") {
|
|
38
|
+
vertexSource = baseName;
|
|
39
|
+
}
|
|
40
|
+
else if (baseName.vertexSource) {
|
|
41
|
+
vertexSource = "source:" + baseName.vertexSource;
|
|
42
|
+
}
|
|
43
|
+
else if (baseName.vertexElement) {
|
|
44
|
+
vertexSource = hostDocument?.getElementById(baseName.vertexElement) || baseName.vertexElement;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
vertexSource = baseName.vertex || baseName;
|
|
48
|
+
}
|
|
49
|
+
if (typeof baseName === "string") {
|
|
50
|
+
fragmentSource = baseName;
|
|
51
|
+
}
|
|
52
|
+
else if (baseName.fragmentSource) {
|
|
53
|
+
fragmentSource = "source:" + baseName.fragmentSource;
|
|
54
|
+
}
|
|
55
|
+
else if (baseName.fragmentElement) {
|
|
56
|
+
fragmentSource = hostDocument?.getElementById(baseName.fragmentElement) || baseName.fragmentElement;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
fragmentSource = baseName.fragment || baseName;
|
|
60
|
+
}
|
|
61
|
+
const shaderCodes = [undefined, undefined];
|
|
62
|
+
const shadersLoaded = () => {
|
|
63
|
+
if (shaderCodes[0] && shaderCodes[1]) {
|
|
64
|
+
processorOptions.isFragment = true;
|
|
65
|
+
const [migratedVertexCode, fragmentCode] = shaderCodes;
|
|
66
|
+
Process(fragmentCode, processorOptions, (migratedFragmentCode, codeBeforeMigration) => {
|
|
67
|
+
if (effectContext) {
|
|
68
|
+
effectContext._fragmentSourceCodeBeforeMigration = codeBeforeMigration;
|
|
69
|
+
}
|
|
70
|
+
if (processFinalCode) {
|
|
71
|
+
migratedFragmentCode = processFinalCode("fragment", migratedFragmentCode);
|
|
72
|
+
}
|
|
73
|
+
const finalShaders = Finalize(migratedVertexCode, migratedFragmentCode, processorOptions);
|
|
74
|
+
processorOptions = null;
|
|
75
|
+
const finalCode = _useFinalCode(finalShaders.vertexCode, finalShaders.fragmentCode, baseName, shaderLanguage);
|
|
76
|
+
onFinalCodeReady?.(finalCode.vertexSourceCode, finalCode.fragmentSourceCode);
|
|
77
|
+
}, engine);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
_loadShader(vertexSource, "Vertex", "", (vertexCode) => {
|
|
81
|
+
Initialize(processorOptions);
|
|
82
|
+
Process(vertexCode, processorOptions, (migratedVertexCode, codeBeforeMigration) => {
|
|
83
|
+
if (effectContext) {
|
|
84
|
+
effectContext._rawVertexSourceCode = vertexCode;
|
|
85
|
+
effectContext._vertexSourceCodeBeforeMigration = codeBeforeMigration;
|
|
86
|
+
}
|
|
87
|
+
if (processFinalCode) {
|
|
88
|
+
migratedVertexCode = processFinalCode("vertex", migratedVertexCode);
|
|
89
|
+
}
|
|
90
|
+
shaderCodes[0] = migratedVertexCode;
|
|
91
|
+
shadersLoaded();
|
|
92
|
+
}, engine);
|
|
93
|
+
}, shaderLanguage);
|
|
94
|
+
_loadShader(fragmentSource, "Fragment", "Pixel", (fragmentCode) => {
|
|
95
|
+
if (effectContext) {
|
|
96
|
+
effectContext._rawFragmentSourceCode = fragmentCode;
|
|
97
|
+
}
|
|
98
|
+
shaderCodes[1] = fragmentCode;
|
|
99
|
+
shadersLoaded();
|
|
100
|
+
}, shaderLanguage);
|
|
101
|
+
}
|
|
102
|
+
function _loadShader(shader, key, optionalKey, callback, shaderLanguage, _loadFileInjection) {
|
|
103
|
+
if (typeof HTMLElement !== "undefined") {
|
|
104
|
+
// DOM element ?
|
|
105
|
+
if (shader instanceof HTMLElement) {
|
|
106
|
+
const shaderCode = GetDOMTextContent(shader);
|
|
107
|
+
callback(shaderCode);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Direct source ?
|
|
112
|
+
if (shader.substr(0, 7) === "source:") {
|
|
113
|
+
callback(shader.substr(7));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
// Base64 encoded ?
|
|
117
|
+
if (shader.substr(0, 7) === "base64:") {
|
|
118
|
+
const shaderBinary = window.atob(shader.substr(7));
|
|
119
|
+
callback(shaderBinary);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const shaderStore = ShaderStore.GetShadersStore(shaderLanguage);
|
|
123
|
+
// Is in local store ?
|
|
124
|
+
if (shaderStore[shader + key + "Shader"]) {
|
|
125
|
+
callback(shaderStore[shader + key + "Shader"]);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (optionalKey && shaderStore[shader + optionalKey + "Shader"]) {
|
|
129
|
+
callback(shaderStore[shader + optionalKey + "Shader"]);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
let shaderUrl;
|
|
133
|
+
if (shader[0] === "." || shader[0] === "/" || shader.indexOf("http") > -1) {
|
|
134
|
+
shaderUrl = shader;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
shaderUrl = ShaderStore.GetShadersRepository(shaderLanguage) + shader;
|
|
138
|
+
}
|
|
139
|
+
if (!_loadFileInjection) {
|
|
140
|
+
// we got to this point and loadFile was not injected - throw an error
|
|
141
|
+
throw new Error("loadFileInjection is not defined");
|
|
142
|
+
}
|
|
143
|
+
// Vertex shader
|
|
144
|
+
_loadFileInjection(shaderUrl + "." + key.toLowerCase() + ".fx", callback);
|
|
145
|
+
}
|
|
146
|
+
function _useFinalCode(migratedVertexCode, migratedFragmentCode, baseName, shaderLanguage) {
|
|
147
|
+
if (baseName) {
|
|
148
|
+
const vertex = baseName.vertexElement || baseName.vertex || baseName.spectorName || baseName;
|
|
149
|
+
const fragment = baseName.fragmentElement || baseName.fragment || baseName.spectorName || baseName;
|
|
150
|
+
return {
|
|
151
|
+
vertexSourceCode: (shaderLanguage === ShaderLanguage.WGSL ? "//" : "") + "#define SHADER_NAME vertex:" + vertex + "\n" + migratedVertexCode,
|
|
152
|
+
fragmentSourceCode: (shaderLanguage === ShaderLanguage.WGSL ? "//" : "") + "#define SHADER_NAME fragment:" + fragment + "\n" + migratedFragmentCode,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
return {
|
|
157
|
+
vertexSourceCode: migratedVertexCode,
|
|
158
|
+
fragmentSourceCode: migratedFragmentCode,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Creates and prepares a pipeline context
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
export const createAndPreparePipelineContext = (options, createPipelineContext, _preparePipelineContext) => {
|
|
167
|
+
try {
|
|
168
|
+
const pipelineContext = options.existingPipelineContext || createPipelineContext(options.shaderProcessingContext);
|
|
169
|
+
pipelineContext._name = options.name;
|
|
170
|
+
if (options.name && options.context) {
|
|
171
|
+
const stateObject = getStateObject(options.context);
|
|
172
|
+
stateObject.cachedPipelines[options.name] = pipelineContext;
|
|
173
|
+
}
|
|
174
|
+
_preparePipelineContext(pipelineContext, options.vertex, options.fragment, !!options.createAsRaw, "", "", options.rebuildRebind, options.defines, options.transformFeedbackVaryings, "");
|
|
175
|
+
_executeWhenRenderingStateIsCompiled(pipelineContext, (context) => {
|
|
176
|
+
options.onRenderingStateCompiled?.(context);
|
|
177
|
+
});
|
|
178
|
+
return pipelineContext;
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
Logger.Error("Error compiling effect");
|
|
182
|
+
throw e;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
//# sourceMappingURL=effect.functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effect.functions.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/effect.functions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,iCAAgC;AAEjF,OAAO,EA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ACL;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC3C,OAAgD,EAChD,qBAA4E,EAC5E,uBAAgF,EAClF,EAAE;IACA,IAAI;QACA,MAAM,eAAe,GAAqB,OAAO,CAAC,uBAAuB,IAAI,qBAAqB,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;QACpI,eAAe,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;QACrC,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE;YACjC,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACpD,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC;SAC/D;QAED,uBAAuB,CACnB,eAAe,EACf,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,QAAQ,EAChB,CAAC,CAAC,OAAO,CAAC,WAAW,EACrB,EAAE,EACF,EAAE,EACF,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,yBAAyB,EACjC,EAAE,CACL,CAAC;QAEF,oCAAoC,CAAC,eAAe,EAAE,CAAC,OAAO,EAAE,EAAE;YAC9D,OAAO,CAAC,wBAAwB,EAAE,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;QAEH,OAAO,eAAe,CAAC;KAC1B;IAAC,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;QACvC,MAAM,CAAC,CAAC;KACX;AACL,CAAC,CAAC","sourcesContent":["import type { ProcessingOptions, ShaderCustomProcessingFunction, ShaderProcessingContext } from \"core/Engines/Processors/shaderProcessingOptions\";\r\nimport { GetDOMTextContent, IsWindowObjectExist } from \"core/Misc/domManagement\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { ShaderLanguage } from \"./shaderLanguage\";\r\nimport type { WebGLContext } from \"core/Engines/thinEngine.functions\";\r\nimport { _executeWhenRenderingStateIsCompiled, getStateObject } from \"core/Engines/thinEngine.functions\";\r\nimport { ShaderStore } from \"core/Engines/shaderStore\";\r\nimport type { AbstractEngine } from \"core/Engines/abstractEngine\";\r\nimport type { Effect, IShaderPath } from \"./effect\";\r\nimport type { IPipelineContext } from \"core/Engines/IPipelineContext\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { Finalize, Initialize, Process } from \"core/Engines/Processors/shaderProcessor\";\r\nimport type { _loadFile } from \"core/Engines/abstractEngine.functions\";\r\nimport type { WebGLPipelineContext } from \"core/Engines/WebGL/webGLPipelineContext\";\r\n\r\n/**\r\n * Options to be used when creating a pipeline\r\n */\r\nexport interface IPipelineGenerationOptions {\r\n /**\r\n * The definition of the shader content.\r\n * Can be either a unified name, name per vertex and frament or the shader code content itself\r\n */\r\n shaderNameOrContent: string | IShaderPath;\r\n /**\r\n * Unique key to identify the pipeline.\r\n * Note that though not mandatory, it's recommended to provide a key to be able to use the automated pipeline loading system.\r\n */\r\n key?: string;\r\n /**\r\n * The list of defines to be used in the shader\r\n */\r\n defines?: string[];\r\n\r\n /**\r\n * If true, the global defines will be added to the defines array\r\n */\r\n addGlobalDefines?: boolean;\r\n /**\r\n * The shader language.\r\n * Defaults to the language suiting the platform name (GLSL for WEBGL2, WGSL for WEBGPU)\r\n */\r\n shaderLanguage?: ShaderLanguage;\r\n\r\n /**\r\n * The name of the platform to be used when processing the shader\r\n * defaults to WEBGL2\r\n */\r\n platformName?: string /* \"WEBGL2\" | \"WEBGL1\" | \"WEBGPU\" */;\r\n\r\n /**\r\n * extend the processing options when running code processing\r\n */\r\n extendedProcessingOptions?: Partial<ProcessingOptions>;\r\n\r\n /**\r\n * extend the pipeline generation options\r\n */\r\n extendedCreatePipelineOptions?: Partial<ICreateAndPreparePipelineContextOptions>;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface ICreateAndPreparePipelineContextOptions {\r\n parallelShaderCompile?: { COMPLETION_STATUS_KHR: number };\r\n shaderProcessingContext: Nullable<ShaderProcessingContext>;\r\n existingPipelineContext?: Nullable<IPipelineContext>;\r\n name?: string;\r\n rebuildRebind?: (vertexSourceCode: string, fragmentSourceCode: string, onCompiled: (pipelineContext: IPipelineContext) => void, onError: (message: string) => void) => void;\r\n onRenderingStateCompiled?: (pipelineContext?: IPipelineContext) => void;\r\n context?: WebGL2RenderingContext | WebGLRenderingContext;\r\n // preparePipeline options\r\n createAsRaw?: boolean;\r\n vertex: string;\r\n fragment: string;\r\n defines: Nullable<string>;\r\n transformFeedbackVaryings: Nullable<string[]>;\r\n}\r\n\r\n/**\r\n * Get a cached pipeline context\r\n * @param name the pipeline name\r\n * @param context the context to be used when creating the pipeline\r\n * @returns the cached pipeline context if it exists\r\n * @internal\r\n */\r\nexport function getCachedPipeline(name: string, context: WebGLContext): IPipelineContext | undefined {\r\n const stateObject = getStateObject(context);\r\n return stateObject.cachedPipelines[name];\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function resetCachedPipeline(pipeline: IPipelineContext): void {\r\n const name = pipeline._name;\r\n const context = (pipeline as WebGLPipelineContext).context;\r\n if (name && context) {\r\n const stateObject = getStateObject(context!);\r\n const cachedPipeline = stateObject.cachedPipelines[name];\r\n cachedPipeline?.dispose();\r\n delete stateObject.cachedPipelines[name];\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport function _processShaderCode(\r\n processorOptions: ProcessingOptions,\r\n baseName: any,\r\n processFinalCode?: Nullable<ShaderCustomProcessingFunction>,\r\n onFinalCodeReady?: (vertexCode: string, fragmentCode: string) => void,\r\n shaderLanguage?: ShaderLanguage,\r\n engine?: AbstractEngine,\r\n effectContext?: Effect\r\n) {\r\n let vertexSource: string | HTMLElement | IShaderPath;\r\n let fragmentSource: string | HTMLElement | IShaderPath;\r\n\r\n // const baseName = this.name;\r\n const hostDocument = IsWindowObjectExist() ? engine?.getHostDocument() : null;\r\n\r\n if (typeof baseName === \"string\") {\r\n vertexSource = baseName;\r\n } else if (baseName.vertexSource) {\r\n vertexSource = \"source:\" + baseName.vertexSource;\r\n } else if (baseName.vertexElement) {\r\n vertexSource = hostDocument?.getElementById(baseName.vertexElement) || baseName.vertexElement;\r\n } else {\r\n vertexSource = baseName.vertex || baseName;\r\n }\r\n if (typeof baseName === \"string\") {\r\n fragmentSource = baseName;\r\n } else if (baseName.fragmentSource) {\r\n fragmentSource = \"source:\" + baseName.fragmentSource;\r\n } else if (baseName.fragmentElement) {\r\n fragmentSource = hostDocument?.getElementById(baseName.fragmentElement) || baseName.fragmentElement;\r\n } else {\r\n fragmentSource = baseName.fragment || baseName;\r\n }\r\n\r\n const shaderCodes: [string | undefined, string | undefined] = [undefined, undefined];\r\n const shadersLoaded = () => {\r\n if (shaderCodes[0] && shaderCodes[1]) {\r\n processorOptions.isFragment = true;\r\n const [migratedVertexCode, fragmentCode] = shaderCodes;\r\n Process(\r\n fragmentCode,\r\n processorOptions,\r\n (migratedFragmentCode, codeBeforeMigration) => {\r\n if (effectContext) {\r\n effectContext._fragmentSourceCodeBeforeMigration = codeBeforeMigration;\r\n }\r\n if (processFinalCode) {\r\n migratedFragmentCode = processFinalCode(\"fragment\", migratedFragmentCode);\r\n }\r\n const finalShaders = Finalize(migratedVertexCode, migratedFragmentCode, processorOptions);\r\n processorOptions = null as any;\r\n const finalCode = _useFinalCode(finalShaders.vertexCode, finalShaders.fragmentCode, baseName, shaderLanguage);\r\n onFinalCodeReady?.(finalCode.vertexSourceCode, finalCode.fragmentSourceCode);\r\n },\r\n engine\r\n );\r\n }\r\n };\r\n _loadShader(\r\n vertexSource,\r\n \"Vertex\",\r\n \"\",\r\n (vertexCode) => {\r\n Initialize(processorOptions);\r\n Process(\r\n vertexCode,\r\n processorOptions,\r\n (migratedVertexCode, codeBeforeMigration) => {\r\n if (effectContext) {\r\n effectContext._rawVertexSourceCode = vertexCode;\r\n effectContext._vertexSourceCodeBeforeMigration = codeBeforeMigration;\r\n }\r\n if (processFinalCode) {\r\n migratedVertexCode = processFinalCode(\"vertex\", migratedVertexCode);\r\n }\r\n shaderCodes[0] = migratedVertexCode;\r\n shadersLoaded();\r\n },\r\n engine\r\n );\r\n },\r\n shaderLanguage\r\n );\r\n _loadShader(\r\n fragmentSource,\r\n \"Fragment\",\r\n \"Pixel\",\r\n (fragmentCode) => {\r\n if (effectContext) {\r\n effectContext._rawFragmentSourceCode = fragmentCode;\r\n }\r\n shaderCodes[1] = fragmentCode;\r\n shadersLoaded();\r\n },\r\n shaderLanguage\r\n );\r\n}\r\n\r\nfunction _loadShader(shader: any, key: string, optionalKey: string, callback: (data: any) => void, shaderLanguage?: ShaderLanguage, _loadFileInjection?: typeof _loadFile) {\r\n if (typeof HTMLElement !== \"undefined\") {\r\n // DOM element ?\r\n if (shader instanceof HTMLElement) {\r\n const shaderCode = GetDOMTextContent(shader);\r\n callback(shaderCode);\r\n return;\r\n }\r\n }\r\n\r\n // Direct source ?\r\n if (shader.substr(0, 7) === \"source:\") {\r\n callback(shader.substr(7));\r\n return;\r\n }\r\n\r\n // Base64 encoded ?\r\n if (shader.substr(0, 7) === \"base64:\") {\r\n const shaderBinary = window.atob(shader.substr(7));\r\n callback(shaderBinary);\r\n return;\r\n }\r\n\r\n const shaderStore = ShaderStore.GetShadersStore(shaderLanguage);\r\n\r\n // Is in local store ?\r\n if (shaderStore[shader + key + \"Shader\"]) {\r\n callback(shaderStore[shader + key + \"Shader\"]);\r\n return;\r\n }\r\n\r\n if (optionalKey && shaderStore[shader + optionalKey + \"Shader\"]) {\r\n callback(shaderStore[shader + optionalKey + \"Shader\"]);\r\n return;\r\n }\r\n\r\n let shaderUrl;\r\n\r\n if (shader[0] === \".\" || shader[0] === \"/\" || shader.indexOf(\"http\") > -1) {\r\n shaderUrl = shader;\r\n } else {\r\n shaderUrl = ShaderStore.GetShadersRepository(shaderLanguage) + shader;\r\n }\r\n if (!_loadFileInjection) {\r\n // we got to this point and loadFile was not injected - throw an error\r\n throw new Error(\"loadFileInjection is not defined\");\r\n }\r\n // Vertex shader\r\n _loadFileInjection(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\r\n}\r\n\r\nfunction _useFinalCode(migratedVertexCode: string, migratedFragmentCode: string, baseName: any, shaderLanguage?: ShaderLanguage) {\r\n if (baseName) {\r\n const vertex = baseName.vertexElement || baseName.vertex || baseName.spectorName || baseName;\r\n const fragment = baseName.fragmentElement || baseName.fragment || baseName.spectorName || baseName;\r\n\r\n return {\r\n vertexSourceCode: (shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME vertex:\" + vertex + \"\\n\" + migratedVertexCode,\r\n fragmentSourceCode: (shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME fragment:\" + fragment + \"\\n\" + migratedFragmentCode,\r\n };\r\n } else {\r\n return {\r\n vertexSourceCode: migratedVertexCode,\r\n fragmentSourceCode: migratedFragmentCode,\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Creates and prepares a pipeline context\r\n * @internal\r\n */\r\nexport const createAndPreparePipelineContext = (\r\n options: ICreateAndPreparePipelineContextOptions,\r\n createPipelineContext: typeof AbstractEngine.prototype.createPipelineContext,\r\n _preparePipelineContext: typeof AbstractEngine.prototype._preparePipelineContext\r\n) => {\r\n try {\r\n const pipelineContext: IPipelineContext = options.existingPipelineContext || createPipelineContext(options.shaderProcessingContext);\r\n pipelineContext._name = options.name;\r\n if (options.name && options.context) {\r\n const stateObject = getStateObject(options.context);\r\n stateObject.cachedPipelines[options.name] = pipelineContext;\r\n }\r\n\r\n _preparePipelineContext(\r\n pipelineContext,\r\n options.vertex,\r\n options.fragment,\r\n !!options.createAsRaw,\r\n \"\",\r\n \"\",\r\n options.rebuildRebind,\r\n options.defines,\r\n options.transformFeedbackVaryings,\r\n \"\"\r\n );\r\n\r\n _executeWhenRenderingStateIsCompiled(pipelineContext, (context) => {\r\n options.onRenderingStateCompiled?.(context);\r\n });\r\n\r\n return pipelineContext;\r\n } catch (e) {\r\n Logger.Error(\"Error compiling effect\");\r\n throw e;\r\n }\r\n};\r\n"]}
|