@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
|
@@ -10,6 +10,7 @@ import { ShaderDefineExpression } from "./Expressions/shaderDefineExpression.js"
|
|
|
10
10
|
import { ShaderDefineArithmeticOperator } from "./Expressions/Operators/shaderDefineArithmeticOperator.js";
|
|
11
11
|
import { _WarnImport } from "../../Misc/devTools.js";
|
|
12
12
|
import { ShaderLanguage } from "../../Materials/shaderLanguage.js";
|
|
13
|
+
import { _getGlobalDefines } from "../abstractEngine.functions.js";
|
|
13
14
|
const regexSE = /defined\s*?\((.+?)\)/g;
|
|
14
15
|
const regexSERevert = /defined\s*?\[(.+?)\]/g;
|
|
15
16
|
const regexShaderInclude = /#include\s?<(.+)>(\((.*)\))*(\[(.*)\])*/g;
|
|
@@ -17,375 +18,387 @@ const regexShaderDecl = /__decl__/;
|
|
|
17
18
|
const regexLightX = /light\{X\}.(\w*)/g;
|
|
18
19
|
const regexX = /\{X\}/g;
|
|
19
20
|
const reusableMatches = [];
|
|
21
|
+
const _MoveCursorRegex = /(#ifdef)|(#else)|(#elif)|(#endif)|(#ifndef)|(#if)/;
|
|
22
|
+
export function Initialize(options) {
|
|
23
|
+
if (options.processor && options.processor.initializeShaders) {
|
|
24
|
+
options.processor.initializeShaders(options.processingContext);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
20
27
|
/** @internal */
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
options.processor.initializeShaders(options.processingContext);
|
|
25
|
-
}
|
|
28
|
+
export function Process(sourceCode, options, callback, engine) {
|
|
29
|
+
if (options.processor?.preProcessShaderCode) {
|
|
30
|
+
sourceCode = options.processor.preProcessShaderCode(sourceCode, options.isFragment);
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
if (options.
|
|
29
|
-
|
|
32
|
+
_ProcessIncludes(sourceCode, options, (codeWithIncludes) => {
|
|
33
|
+
if (options.processCodeAfterIncludes) {
|
|
34
|
+
codeWithIncludes = options.processCodeAfterIncludes(options.isFragment ? "fragment" : "vertex", codeWithIncludes);
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const migratedCode = _ProcessShaderConversion(codeWithIncludes, options, engine);
|
|
37
|
+
callback(migratedCode, codeWithIncludes);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** @internal */
|
|
41
|
+
export function PreProcess(sourceCode, options, callback, engine) {
|
|
42
|
+
if (options.processor?.preProcessShaderCode) {
|
|
43
|
+
sourceCode = options.processor.preProcessShaderCode(sourceCode, options.isFragment);
|
|
38
44
|
}
|
|
39
|
-
|
|
40
|
-
if (options.
|
|
41
|
-
|
|
45
|
+
_ProcessIncludes(sourceCode, options, (codeWithIncludes) => {
|
|
46
|
+
if (options.processCodeAfterIncludes) {
|
|
47
|
+
codeWithIncludes = options.processCodeAfterIncludes(options.isFragment ? "fragment" : "vertex", codeWithIncludes);
|
|
42
48
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
const migratedCode = _ApplyPreProcessing(codeWithIncludes, options, engine);
|
|
50
|
+
callback(migratedCode, codeWithIncludes);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** @internal */
|
|
54
|
+
export function Finalize(vertexCode, fragmentCode, options) {
|
|
55
|
+
if (!options.processor || !options.processor.finalizeShaders) {
|
|
56
|
+
return { vertexCode, fragmentCode };
|
|
50
57
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return
|
|
58
|
+
return options.processor.finalizeShaders(vertexCode, fragmentCode, options.processingContext);
|
|
59
|
+
}
|
|
60
|
+
function _ProcessPrecision(source, options) {
|
|
61
|
+
if (options.processor?.noPrecision) {
|
|
62
|
+
return source;
|
|
56
63
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const shouldUseHighPrecisionShader = options.shouldUseHighPrecisionShader;
|
|
62
|
-
if (source.indexOf("precision highp float") === -1) {
|
|
63
|
-
if (!shouldUseHighPrecisionShader) {
|
|
64
|
-
source = "precision mediump float;\n" + source;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
source = "precision highp float;\n" + source;
|
|
68
|
-
}
|
|
64
|
+
const shouldUseHighPrecisionShader = options.shouldUseHighPrecisionShader;
|
|
65
|
+
if (source.indexOf("precision highp float") === -1) {
|
|
66
|
+
if (!shouldUseHighPrecisionShader) {
|
|
67
|
+
source = "precision mediump float;\n" + source;
|
|
69
68
|
}
|
|
70
69
|
else {
|
|
71
|
-
|
|
72
|
-
// Moving highp to mediump
|
|
73
|
-
source = source.replace("precision highp float", "precision mediump float");
|
|
74
|
-
}
|
|
70
|
+
source = "precision highp float;\n" + source;
|
|
75
71
|
}
|
|
76
|
-
return source;
|
|
77
72
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return new ShaderDefineIsDefinedOperator(match[1].trim(), expression[0] === "!");
|
|
73
|
+
else {
|
|
74
|
+
if (!shouldUseHighPrecisionShader) {
|
|
75
|
+
// Moving highp to mediump
|
|
76
|
+
source = source.replace("precision highp float", "precision mediump float");
|
|
83
77
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
78
|
+
}
|
|
79
|
+
return source;
|
|
80
|
+
}
|
|
81
|
+
function _ExtractOperation(expression) {
|
|
82
|
+
const regex = /defined\((.+)\)/;
|
|
83
|
+
const match = regex.exec(expression);
|
|
84
|
+
if (match && match.length) {
|
|
85
|
+
return new ShaderDefineIsDefinedOperator(match[1].trim(), expression[0] === "!");
|
|
86
|
+
}
|
|
87
|
+
const operators = ["==", "!=", ">=", "<=", "<", ">"];
|
|
88
|
+
let operator = "";
|
|
89
|
+
let indexOperator = 0;
|
|
90
|
+
for (operator of operators) {
|
|
91
|
+
indexOperator = expression.indexOf(operator);
|
|
92
|
+
if (indexOperator > -1) {
|
|
93
|
+
break;
|
|
95
94
|
}
|
|
96
|
-
const define = expression.substring(0, indexOperator).trim();
|
|
97
|
-
const value = expression.substring(indexOperator + operator.length).trim();
|
|
98
|
-
return new ShaderDefineArithmeticOperator(define, operator, value);
|
|
99
95
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
96
|
+
if (indexOperator === -1) {
|
|
97
|
+
return new ShaderDefineIsDefinedOperator(expression);
|
|
98
|
+
}
|
|
99
|
+
const define = expression.substring(0, indexOperator).trim();
|
|
100
|
+
const value = expression.substring(indexOperator + operator.length).trim();
|
|
101
|
+
return new ShaderDefineArithmeticOperator(define, operator, value);
|
|
102
|
+
}
|
|
103
|
+
function _BuildSubExpression(expression) {
|
|
104
|
+
expression = expression.replace(regexSE, "defined[$1]");
|
|
105
|
+
const postfix = ShaderDefineExpression.infixToPostfix(expression);
|
|
106
|
+
const stack = [];
|
|
107
|
+
for (const c of postfix) {
|
|
108
|
+
if (c !== "||" && c !== "&&") {
|
|
109
|
+
stack.push(c);
|
|
110
|
+
}
|
|
111
|
+
else if (stack.length >= 2) {
|
|
112
|
+
let v1 = stack[stack.length - 1], v2 = stack[stack.length - 2];
|
|
113
|
+
stack.length -= 2;
|
|
114
|
+
const operator = c == "&&" ? new ShaderDefineAndOperator() : new ShaderDefineOrOperator();
|
|
115
|
+
if (typeof v1 === "string") {
|
|
116
|
+
v1 = v1.replace(regexSERevert, "defined($1)");
|
|
107
117
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
stack.length -= 2;
|
|
111
|
-
const operator = c == "&&" ? new ShaderDefineAndOperator() : new ShaderDefineOrOperator();
|
|
112
|
-
if (typeof v1 === "string") {
|
|
113
|
-
v1 = v1.replace(regexSERevert, "defined($1)");
|
|
114
|
-
}
|
|
115
|
-
if (typeof v2 === "string") {
|
|
116
|
-
v2 = v2.replace(regexSERevert, "defined($1)");
|
|
117
|
-
}
|
|
118
|
-
operator.leftOperand = typeof v2 === "string" ? this._ExtractOperation(v2) : v2;
|
|
119
|
-
operator.rightOperand = typeof v1 === "string" ? this._ExtractOperation(v1) : v1;
|
|
120
|
-
stack.push(operator);
|
|
118
|
+
if (typeof v2 === "string") {
|
|
119
|
+
v2 = v2.replace(regexSERevert, "defined($1)");
|
|
121
120
|
}
|
|
121
|
+
operator.leftOperand = typeof v2 === "string" ? _ExtractOperation(v2) : v2;
|
|
122
|
+
operator.rightOperand = typeof v1 === "string" ? _ExtractOperation(v1) : v1;
|
|
123
|
+
stack.push(operator);
|
|
122
124
|
}
|
|
123
|
-
let result = stack[stack.length - 1];
|
|
124
|
-
if (typeof result === "string") {
|
|
125
|
-
result = result.replace(regexSERevert, "defined($1)");
|
|
126
|
-
}
|
|
127
|
-
// note: stack.length !== 1 if there was an error in the parsing
|
|
128
|
-
return typeof result === "string" ? this._ExtractOperation(result) : result;
|
|
129
125
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
let expression = line.substring(start);
|
|
134
|
-
expression = expression.substring(0, (expression.indexOf("//") + 1 || expression.length + 1) - 1).trim();
|
|
135
|
-
if (command === "#ifdef") {
|
|
136
|
-
node.testExpression = new ShaderDefineIsDefinedOperator(expression);
|
|
137
|
-
}
|
|
138
|
-
else if (command === "#ifndef") {
|
|
139
|
-
node.testExpression = new ShaderDefineIsDefinedOperator(expression, true);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
node.testExpression = this._BuildSubExpression(expression);
|
|
143
|
-
}
|
|
144
|
-
return node;
|
|
126
|
+
let result = stack[stack.length - 1];
|
|
127
|
+
if (typeof result === "string") {
|
|
128
|
+
result = result.replace(regexSERevert, "defined($1)");
|
|
145
129
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
130
|
+
// note: stack.length !== 1 if there was an error in the parsing
|
|
131
|
+
return typeof result === "string" ? _ExtractOperation(result) : result;
|
|
132
|
+
}
|
|
133
|
+
function _BuildExpression(line, start) {
|
|
134
|
+
const node = new ShaderCodeTestNode();
|
|
135
|
+
const command = line.substring(0, start);
|
|
136
|
+
let expression = line.substring(start);
|
|
137
|
+
expression = expression.substring(0, (expression.indexOf("//") + 1 || expression.length + 1) - 1).trim();
|
|
138
|
+
if (command === "#ifdef") {
|
|
139
|
+
node.testExpression = new ShaderDefineIsDefinedOperator(expression);
|
|
140
|
+
}
|
|
141
|
+
else if (command === "#ifndef") {
|
|
142
|
+
node.testExpression = new ShaderDefineIsDefinedOperator(expression, true);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
node.testExpression = _BuildSubExpression(expression);
|
|
146
|
+
}
|
|
147
|
+
return node;
|
|
148
|
+
}
|
|
149
|
+
function _MoveCursorWithinIf(cursor, rootNode, ifNode) {
|
|
150
|
+
let line = cursor.currentLine;
|
|
151
|
+
while (_MoveCursor(cursor, ifNode)) {
|
|
152
|
+
line = cursor.currentLine;
|
|
153
|
+
const first5 = line.substring(0, 5).toLowerCase();
|
|
154
|
+
if (first5 === "#else") {
|
|
155
|
+
const elseNode = new ShaderCodeNode();
|
|
156
|
+
rootNode.children.push(elseNode);
|
|
157
|
+
_MoveCursor(cursor, elseNode);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
else if (first5 === "#elif") {
|
|
161
|
+
const elifNode = _BuildExpression(line, 5);
|
|
162
|
+
rootNode.children.push(elifNode);
|
|
163
|
+
ifNode = elifNode;
|
|
162
164
|
}
|
|
163
165
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
166
|
+
}
|
|
167
|
+
function _MoveCursor(cursor, rootNode) {
|
|
168
|
+
while (cursor.canRead) {
|
|
169
|
+
cursor.lineIndex++;
|
|
170
|
+
const line = cursor.currentLine;
|
|
171
|
+
if (line.indexOf("#") >= 0) {
|
|
172
|
+
const matches = _MoveCursorRegex.exec(line);
|
|
173
|
+
if (matches && matches.length) {
|
|
174
|
+
const keyword = matches[0];
|
|
175
|
+
switch (keyword) {
|
|
176
|
+
case "#ifdef": {
|
|
177
|
+
const newRootNode = new ShaderCodeConditionNode();
|
|
178
|
+
rootNode.children.push(newRootNode);
|
|
179
|
+
const ifNode = _BuildExpression(line, 6);
|
|
180
|
+
newRootNode.children.push(ifNode);
|
|
181
|
+
_MoveCursorWithinIf(cursor, newRootNode, ifNode);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case "#else":
|
|
185
|
+
case "#elif":
|
|
186
|
+
return true;
|
|
187
|
+
case "#endif":
|
|
188
|
+
return false;
|
|
189
|
+
case "#ifndef": {
|
|
190
|
+
const newRootNode = new ShaderCodeConditionNode();
|
|
191
|
+
rootNode.children.push(newRootNode);
|
|
192
|
+
const ifNode = _BuildExpression(line, 7);
|
|
193
|
+
newRootNode.children.push(ifNode);
|
|
194
|
+
_MoveCursorWithinIf(cursor, newRootNode, ifNode);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case "#if": {
|
|
198
|
+
const newRootNode = new ShaderCodeConditionNode();
|
|
199
|
+
const ifNode = _BuildExpression(line, 3);
|
|
200
|
+
rootNode.children.push(newRootNode);
|
|
201
|
+
newRootNode.children.push(ifNode);
|
|
202
|
+
_MoveCursorWithinIf(cursor, newRootNode, ifNode);
|
|
203
|
+
break;
|
|
202
204
|
}
|
|
203
|
-
continue;
|
|
204
205
|
}
|
|
206
|
+
continue;
|
|
205
207
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
208
|
+
}
|
|
209
|
+
const newNode = new ShaderCodeNode();
|
|
210
|
+
newNode.line = line;
|
|
211
|
+
rootNode.children.push(newNode);
|
|
212
|
+
// Detect additional defines
|
|
213
|
+
if (line[0] === "#" && line[1] === "d") {
|
|
214
|
+
const split = line.replace(";", "").split(" ");
|
|
215
|
+
newNode.additionalDefineKey = split[1];
|
|
216
|
+
if (split.length === 3) {
|
|
217
|
+
newNode.additionalDefineValue = split[2];
|
|
216
218
|
}
|
|
217
219
|
}
|
|
218
|
-
return false;
|
|
219
220
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
function _EvaluatePreProcessors(sourceCode, preprocessors, options) {
|
|
224
|
+
const rootNode = new ShaderCodeNode();
|
|
225
|
+
const cursor = new ShaderCodeCursor();
|
|
226
|
+
cursor.lineIndex = -1;
|
|
227
|
+
cursor.lines = sourceCode.split("\n");
|
|
228
|
+
// Decompose (We keep it in 2 steps so it is easier to maintain and perf hit is insignificant)
|
|
229
|
+
_MoveCursor(cursor, rootNode);
|
|
230
|
+
// Recompose
|
|
231
|
+
return rootNode.process(preprocessors, options);
|
|
232
|
+
}
|
|
233
|
+
function _PreparePreProcessors(options, engine) {
|
|
234
|
+
const defines = options.defines;
|
|
235
|
+
const preprocessors = {};
|
|
236
|
+
for (const define of defines) {
|
|
237
|
+
const keyValue = define.replace("#define", "").replace(";", "").trim();
|
|
238
|
+
const split = keyValue.split(" ");
|
|
239
|
+
preprocessors[split[0]] = split.length > 1 ? split[1] : "";
|
|
229
240
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
preprocessors[options.platformName] = "true";
|
|
243
|
-
engine._getGlobalDefines(preprocessors);
|
|
244
|
-
return preprocessors;
|
|
241
|
+
if (options.processor?.shaderLanguage === ShaderLanguage.GLSL) {
|
|
242
|
+
preprocessors["GL_ES"] = "true";
|
|
243
|
+
}
|
|
244
|
+
preprocessors["__VERSION__"] = options.version;
|
|
245
|
+
preprocessors[options.platformName] = "true";
|
|
246
|
+
_getGlobalDefines(preprocessors, engine?.isNDCHalfZRange, engine?.useReverseDepthBuffer, engine?.useExactSrgbConversions);
|
|
247
|
+
return preprocessors;
|
|
248
|
+
}
|
|
249
|
+
function _ProcessShaderConversion(sourceCode, options, engine) {
|
|
250
|
+
let preparedSourceCode = _ProcessPrecision(sourceCode, options);
|
|
251
|
+
if (!options.processor) {
|
|
252
|
+
return preparedSourceCode;
|
|
245
253
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
254
|
+
// Already converted
|
|
255
|
+
if (options.processor.shaderLanguage === ShaderLanguage.GLSL && preparedSourceCode.indexOf("#version 3") !== -1) {
|
|
256
|
+
preparedSourceCode = preparedSourceCode.replace("#version 300 es", "");
|
|
257
|
+
if (!options.processor.parseGLES3) {
|
|
249
258
|
return preparedSourceCode;
|
|
250
259
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
260
|
+
}
|
|
261
|
+
const defines = options.defines;
|
|
262
|
+
const preprocessors = _PreparePreProcessors(options, engine);
|
|
263
|
+
// General pre processing
|
|
264
|
+
if (options.processor.preProcessor) {
|
|
265
|
+
preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);
|
|
266
|
+
}
|
|
267
|
+
preparedSourceCode = _EvaluatePreProcessors(preparedSourceCode, preprocessors, options);
|
|
268
|
+
// Post processing
|
|
269
|
+
if (options.processor.postProcessor) {
|
|
270
|
+
preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine
|
|
271
|
+
? {
|
|
272
|
+
drawBuffersExtensionDisabled: engine.getCaps().drawBuffersExtension ? false : true,
|
|
256
273
|
}
|
|
257
|
-
|
|
258
|
-
const defines = options.defines;
|
|
259
|
-
const preprocessors = this._PreparePreProcessors(options, engine);
|
|
260
|
-
// General pre processing
|
|
261
|
-
if (options.processor.preProcessor) {
|
|
262
|
-
preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);
|
|
263
|
-
}
|
|
264
|
-
preparedSourceCode = this._EvaluatePreProcessors(preparedSourceCode, preprocessors, options);
|
|
265
|
-
// Post processing
|
|
266
|
-
if (options.processor.postProcessor) {
|
|
267
|
-
preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine);
|
|
268
|
-
}
|
|
269
|
-
// Inline functions tagged with #define inline
|
|
270
|
-
if (engine._features.needShaderCodeInlining) {
|
|
271
|
-
preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);
|
|
272
|
-
}
|
|
273
|
-
return preparedSourceCode;
|
|
274
|
+
: {});
|
|
274
275
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const preprocessors = this._PreparePreProcessors(options, engine);
|
|
279
|
-
// General pre processing
|
|
280
|
-
if (options.processor?.preProcessor) {
|
|
281
|
-
preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);
|
|
282
|
-
}
|
|
283
|
-
preparedSourceCode = this._EvaluatePreProcessors(preparedSourceCode, preprocessors, options);
|
|
284
|
-
// Post processing
|
|
285
|
-
if (options.processor?.postProcessor) {
|
|
286
|
-
preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine);
|
|
287
|
-
}
|
|
288
|
-
// Inline functions tagged with #define inline
|
|
289
|
-
if (engine._features.needShaderCodeInlining) {
|
|
290
|
-
preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);
|
|
291
|
-
}
|
|
292
|
-
return preparedSourceCode;
|
|
276
|
+
// Inline functions tagged with #define inline
|
|
277
|
+
if (engine?._features.needShaderCodeInlining) {
|
|
278
|
+
preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);
|
|
293
279
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
280
|
+
return preparedSourceCode;
|
|
281
|
+
}
|
|
282
|
+
function _ApplyPreProcessing(sourceCode, options, engine) {
|
|
283
|
+
let preparedSourceCode = sourceCode;
|
|
284
|
+
const defines = options.defines;
|
|
285
|
+
const preprocessors = _PreparePreProcessors(options, engine);
|
|
286
|
+
// General pre processing
|
|
287
|
+
if (options.processor?.preProcessor) {
|
|
288
|
+
preparedSourceCode = options.processor.preProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext);
|
|
289
|
+
}
|
|
290
|
+
preparedSourceCode = _EvaluatePreProcessors(preparedSourceCode, preprocessors, options);
|
|
291
|
+
// Post processing
|
|
292
|
+
if (options.processor?.postProcessor) {
|
|
293
|
+
preparedSourceCode = options.processor.postProcessor(preparedSourceCode, defines, options.isFragment, options.processingContext, engine
|
|
294
|
+
? {
|
|
295
|
+
drawBuffersExtensionDisabled: engine.getCaps().drawBuffersExtension ? false : true,
|
|
296
|
+
}
|
|
297
|
+
: {});
|
|
298
|
+
}
|
|
299
|
+
// Inline functions tagged with #define inline
|
|
300
|
+
if (engine._features.needShaderCodeInlining) {
|
|
301
|
+
preparedSourceCode = engine.inlineShaderCode(preparedSourceCode);
|
|
302
|
+
}
|
|
303
|
+
return preparedSourceCode;
|
|
304
|
+
}
|
|
305
|
+
/** @internal */
|
|
306
|
+
export function _ProcessIncludes(sourceCode, options, callback) {
|
|
307
|
+
reusableMatches.length = 0;
|
|
308
|
+
let match;
|
|
309
|
+
// stay back-compat to the old matchAll syntax
|
|
310
|
+
while ((match = regexShaderInclude.exec(sourceCode)) !== null) {
|
|
311
|
+
reusableMatches.push(match);
|
|
312
|
+
}
|
|
313
|
+
let returnValue = String(sourceCode);
|
|
314
|
+
let parts = [sourceCode];
|
|
315
|
+
let keepProcessing = false;
|
|
316
|
+
for (const match of reusableMatches) {
|
|
317
|
+
let includeFile = match[1];
|
|
318
|
+
// Uniform declaration
|
|
319
|
+
if (includeFile.indexOf("__decl__") !== -1) {
|
|
320
|
+
includeFile = includeFile.replace(regexShaderDecl, "");
|
|
321
|
+
if (options.supportsUniformBuffers) {
|
|
322
|
+
includeFile = includeFile.replace("Vertex", "Ubo").replace("Fragment", "Ubo");
|
|
323
|
+
}
|
|
324
|
+
includeFile = includeFile + "Declaration";
|
|
301
325
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
includeFile = includeFile.replace("Vertex", "Ubo").replace("Fragment", "Ubo");
|
|
326
|
+
if (options.includesShadersStore[includeFile]) {
|
|
327
|
+
// Substitution
|
|
328
|
+
let includeContent = options.includesShadersStore[includeFile];
|
|
329
|
+
if (match[2]) {
|
|
330
|
+
const splits = match[3].split(",");
|
|
331
|
+
for (let index = 0; index < splits.length; index += 2) {
|
|
332
|
+
const source = new RegExp(splits[index], "g");
|
|
333
|
+
const dest = splits[index + 1];
|
|
334
|
+
includeContent = includeContent.replace(source, dest);
|
|
312
335
|
}
|
|
313
|
-
includeFile = includeFile + "Declaration";
|
|
314
336
|
}
|
|
315
|
-
if (
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
337
|
+
if (match[4]) {
|
|
338
|
+
const indexString = match[5];
|
|
339
|
+
if (indexString.indexOf("..") !== -1) {
|
|
340
|
+
const indexSplits = indexString.split("..");
|
|
341
|
+
const minIndex = parseInt(indexSplits[0]);
|
|
342
|
+
let maxIndex = parseInt(indexSplits[1]);
|
|
343
|
+
let sourceIncludeContent = includeContent.slice(0);
|
|
344
|
+
includeContent = "";
|
|
345
|
+
if (isNaN(maxIndex)) {
|
|
346
|
+
maxIndex = options.indexParameters[indexSplits[1]];
|
|
324
347
|
}
|
|
325
|
-
|
|
326
|
-
if (match[4]) {
|
|
327
|
-
const indexString = match[5];
|
|
328
|
-
if (indexString.indexOf("..") !== -1) {
|
|
329
|
-
const indexSplits = indexString.split("..");
|
|
330
|
-
const minIndex = parseInt(indexSplits[0]);
|
|
331
|
-
let maxIndex = parseInt(indexSplits[1]);
|
|
332
|
-
let sourceIncludeContent = includeContent.slice(0);
|
|
333
|
-
includeContent = "";
|
|
334
|
-
if (isNaN(maxIndex)) {
|
|
335
|
-
maxIndex = options.indexParameters[indexSplits[1]];
|
|
336
|
-
}
|
|
337
|
-
for (let i = minIndex; i < maxIndex; i++) {
|
|
338
|
-
if (!options.supportsUniformBuffers) {
|
|
339
|
-
// Ubo replacement
|
|
340
|
-
sourceIncludeContent = sourceIncludeContent.replace(regexLightX, (str, p1) => {
|
|
341
|
-
return p1 + "{X}";
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
includeContent += sourceIncludeContent.replace(regexX, i.toString()) + "\n";
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
+
for (let i = minIndex; i < maxIndex; i++) {
|
|
348
349
|
if (!options.supportsUniformBuffers) {
|
|
349
350
|
// Ubo replacement
|
|
350
|
-
|
|
351
|
+
sourceIncludeContent = sourceIncludeContent.replace(regexLightX, (str, p1) => {
|
|
351
352
|
return p1 + "{X}";
|
|
352
353
|
});
|
|
353
354
|
}
|
|
354
|
-
includeContent
|
|
355
|
+
includeContent += sourceIncludeContent.replace(regexX, i.toString()) + "\n";
|
|
355
356
|
}
|
|
356
357
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
newParts.push(splitPart[i]);
|
|
364
|
-
newParts.push(includeContent);
|
|
358
|
+
else {
|
|
359
|
+
if (!options.supportsUniformBuffers) {
|
|
360
|
+
// Ubo replacement
|
|
361
|
+
includeContent = includeContent.replace(regexLightX, (str, p1) => {
|
|
362
|
+
return p1 + "{X}";
|
|
363
|
+
});
|
|
365
364
|
}
|
|
366
|
-
|
|
365
|
+
includeContent = includeContent.replace(regexX, indexString);
|
|
367
366
|
}
|
|
368
|
-
parts = newParts;
|
|
369
|
-
keepProcessing = keepProcessing || includeContent.indexOf("#include<") >= 0 || includeContent.indexOf("#include <") >= 0;
|
|
370
367
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
368
|
+
// Replace
|
|
369
|
+
// Split all parts on match[0] and intersperse the parts with the include content
|
|
370
|
+
const newParts = [];
|
|
371
|
+
for (const part of parts) {
|
|
372
|
+
const splitPart = part.split(match[0]);
|
|
373
|
+
for (let i = 0; i < splitPart.length - 1; i++) {
|
|
374
|
+
newParts.push(splitPart[i]);
|
|
375
|
+
newParts.push(includeContent);
|
|
376
|
+
}
|
|
377
|
+
newParts.push(splitPart[splitPart.length - 1]);
|
|
378
378
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
returnValue = parts.join("");
|
|
382
|
-
if (keepProcessing) {
|
|
383
|
-
this._ProcessIncludes(returnValue.toString(), options, callback);
|
|
379
|
+
parts = newParts;
|
|
380
|
+
keepProcessing = keepProcessing || includeContent.indexOf("#include<") >= 0 || includeContent.indexOf("#include <") >= 0;
|
|
384
381
|
}
|
|
385
382
|
else {
|
|
386
|
-
|
|
383
|
+
const includeShaderUrl = options.shadersRepository + "ShadersInclude/" + includeFile + ".fx";
|
|
384
|
+
_functionContainer.loadFile(includeShaderUrl, (fileContent) => {
|
|
385
|
+
options.includesShadersStore[includeFile] = fileContent;
|
|
386
|
+
_ProcessIncludes(parts.join(""), options, callback);
|
|
387
|
+
});
|
|
388
|
+
return;
|
|
387
389
|
}
|
|
388
390
|
}
|
|
391
|
+
reusableMatches.length = 0;
|
|
392
|
+
returnValue = parts.join("");
|
|
393
|
+
if (keepProcessing) {
|
|
394
|
+
_ProcessIncludes(returnValue.toString(), options, callback);
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
callback(returnValue);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/** @internal */
|
|
401
|
+
export const _functionContainer = {
|
|
389
402
|
/**
|
|
390
403
|
* Loads a file from a url
|
|
391
404
|
* @param url url to load
|
|
@@ -397,9 +410,8 @@ export class ShaderProcessor {
|
|
|
397
410
|
* @returns a file request object
|
|
398
411
|
* @internal
|
|
399
412
|
*/
|
|
400
|
-
|
|
413
|
+
loadFile: (url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError) => {
|
|
401
414
|
throw _WarnImport("FileTools");
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
ShaderProcessor._MoveCursorRegex = /(#ifdef)|(#else)|(#elif)|(#endif)|(#ifndef)|(#if)/;
|
|
415
|
+
},
|
|
416
|
+
};
|
|
405
417
|
//# sourceMappingURL=shaderProcessor.js.map
|