@shaderfrog/core 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/package.json +10 -7
  2. package/cjs/engine.js +0 -218
  3. package/cjs/graph/base-node.js +0 -13
  4. package/cjs/graph/code-nodes.js +0 -23
  5. package/cjs/graph/context.js +0 -253
  6. package/cjs/graph/data-nodes.js +0 -146
  7. package/cjs/graph/edge.js +0 -12
  8. package/cjs/graph/evaluate.js +0 -32
  9. package/cjs/graph/graph-node.js +0 -143
  10. package/cjs/graph/graph-types.js +0 -25
  11. package/cjs/graph/graph.js +0 -533
  12. package/cjs/graph/graph.test.js +0 -173
  13. package/cjs/graph/index.js +0 -27
  14. package/cjs/graph/parsers.js +0 -219
  15. package/cjs/graph/shader-sections.js +0 -268
  16. package/cjs/index.js +0 -19
  17. package/cjs/package.json +0 -1
  18. package/cjs/plugins/babylon/bablyengine.js +0 -597
  19. package/cjs/plugins/babylon/importers.js +0 -66
  20. package/cjs/plugins/babylon/index.js +0 -5
  21. package/cjs/plugins/playcanvas/importers.js +0 -30
  22. package/cjs/plugins/playcanvas/index.js +0 -5
  23. package/cjs/plugins/playcanvas/playengine.js +0 -549
  24. package/cjs/plugins/three/importers.js +0 -17
  25. package/cjs/plugins/three/index.js +0 -6
  26. package/cjs/plugins/three/threngine.js +0 -619
  27. package/cjs/strategy/assignemntTo.js +0 -31
  28. package/cjs/strategy/declarationOf.js +0 -28
  29. package/cjs/strategy/hardCode.js +0 -28
  30. package/cjs/strategy/index.js +0 -25
  31. package/cjs/strategy/inject.js +0 -127
  32. package/cjs/strategy/namedAttribute.js +0 -53
  33. package/cjs/strategy/strategy.js +0 -35
  34. package/cjs/strategy/stratgies.test.js +0 -192
  35. package/cjs/strategy/texture2D.js +0 -88
  36. package/cjs/strategy/uniform.js +0 -195
  37. package/cjs/strategy/variable.js +0 -85
  38. package/cjs/util/ast.js +0 -351
  39. package/cjs/util/ensure.js +0 -11
  40. package/cjs/util/id.js +0 -6
  41. package/esm/engine.d.ts +0 -69
  42. package/esm/graph/base-node.d.ts +0 -36
  43. package/esm/graph/code-nodes.d.ts +0 -44
  44. package/esm/graph/context.d.ts +0 -37
  45. package/esm/graph/data-nodes.d.ts +0 -83
  46. package/esm/graph/edge.d.ts +0 -13
  47. package/esm/graph/evaluate.d.ts +0 -9
  48. package/esm/graph/graph-node.d.ts +0 -8
  49. package/esm/graph/graph-types.d.ts +0 -38
  50. package/esm/graph/graph.d.ts +0 -89
  51. package/esm/graph/graph.test.d.ts +0 -1
  52. package/esm/graph/index.d.ts +0 -11
  53. package/esm/graph/parsers.d.ts +0 -39
  54. package/esm/graph/shader-sections.d.ts +0 -47
  55. package/esm/index.d.ts +0 -3
  56. package/esm/package.json +0 -1
  57. package/esm/plugins/babylon/bablyengine.d.ts +0 -28
  58. package/esm/plugins/babylon/importers.d.ts +0 -3
  59. package/esm/plugins/babylon/index.d.ts +0 -2
  60. package/esm/plugins/playcanvas/importers.d.ts +0 -3
  61. package/esm/plugins/playcanvas/index.d.ts +0 -2
  62. package/esm/plugins/playcanvas/playengine.d.ts +0 -39
  63. package/esm/plugins/three/importers.d.ts +0 -3
  64. package/esm/plugins/three/index.d.ts +0 -2
  65. package/esm/plugins/three/threngine.d.ts +0 -34
  66. package/esm/strategy/assignemntTo.d.ts +0 -9
  67. package/esm/strategy/declarationOf.d.ts +0 -9
  68. package/esm/strategy/hardCode.d.ts +0 -15
  69. package/esm/strategy/index.d.ts +0 -9
  70. package/esm/strategy/inject.d.ts +0 -15
  71. package/esm/strategy/namedAttribute.d.ts +0 -9
  72. package/esm/strategy/strategy.d.ts +0 -28
  73. package/esm/strategy/stratgies.test.d.ts +0 -1
  74. package/esm/strategy/texture2D.d.ts +0 -6
  75. package/esm/strategy/uniform.d.ts +0 -6
  76. package/esm/strategy/variable.d.ts +0 -6
  77. package/esm/util/ast.d.ts +0 -30
  78. package/esm/util/ensure.d.ts +0 -1
  79. package/esm/util/id.d.ts +0 -1
  80. /package/{cjs/engine.d.ts → engine.d.ts} +0 -0
  81. /package/{esm/engine.js → engine.js} +0 -0
  82. /package/{cjs/graph → graph}/base-node.d.ts +0 -0
  83. /package/{esm/graph → graph}/base-node.js +0 -0
  84. /package/{cjs/graph → graph}/code-nodes.d.ts +0 -0
  85. /package/{esm/graph → graph}/code-nodes.js +0 -0
  86. /package/{cjs/graph → graph}/context.d.ts +0 -0
  87. /package/{esm/graph → graph}/context.js +0 -0
  88. /package/{cjs/graph → graph}/data-nodes.d.ts +0 -0
  89. /package/{esm/graph → graph}/data-nodes.js +0 -0
  90. /package/{cjs/graph → graph}/edge.d.ts +0 -0
  91. /package/{esm/graph → graph}/edge.js +0 -0
  92. /package/{cjs/graph → graph}/evaluate.d.ts +0 -0
  93. /package/{esm/graph → graph}/evaluate.js +0 -0
  94. /package/{cjs/graph → graph}/graph-node.d.ts +0 -0
  95. /package/{esm/graph → graph}/graph-node.js +0 -0
  96. /package/{cjs/graph → graph}/graph-types.d.ts +0 -0
  97. /package/{esm/graph → graph}/graph-types.js +0 -0
  98. /package/{cjs/graph → graph}/graph.d.ts +0 -0
  99. /package/{esm/graph → graph}/graph.js +0 -0
  100. /package/{cjs/graph → graph}/graph.test.d.ts +0 -0
  101. /package/{esm/graph → graph}/graph.test.js +0 -0
  102. /package/{cjs/graph → graph}/index.d.ts +0 -0
  103. /package/{esm/graph → graph}/index.js +0 -0
  104. /package/{cjs/graph → graph}/parsers.d.ts +0 -0
  105. /package/{esm/graph → graph}/parsers.js +0 -0
  106. /package/{cjs/graph → graph}/shader-sections.d.ts +0 -0
  107. /package/{esm/graph → graph}/shader-sections.js +0 -0
  108. /package/{cjs/index.d.ts → index.d.ts} +0 -0
  109. /package/{esm/index.js → index.js} +0 -0
  110. /package/{cjs/plugins → plugins}/babylon/bablyengine.d.ts +0 -0
  111. /package/{esm/plugins → plugins}/babylon/bablyengine.js +0 -0
  112. /package/{cjs/plugins → plugins}/babylon/importers.d.ts +0 -0
  113. /package/{esm/plugins → plugins}/babylon/importers.js +0 -0
  114. /package/{cjs/plugins → plugins}/babylon/index.d.ts +0 -0
  115. /package/{esm/plugins → plugins}/babylon/index.js +0 -0
  116. /package/{cjs/plugins → plugins}/playcanvas/importers.d.ts +0 -0
  117. /package/{esm/plugins → plugins}/playcanvas/importers.js +0 -0
  118. /package/{cjs/plugins → plugins}/playcanvas/index.d.ts +0 -0
  119. /package/{esm/plugins → plugins}/playcanvas/index.js +0 -0
  120. /package/{cjs/plugins → plugins}/playcanvas/playengine.d.ts +0 -0
  121. /package/{esm/plugins → plugins}/playcanvas/playengine.js +0 -0
  122. /package/{cjs/plugins → plugins}/three/importers.d.ts +0 -0
  123. /package/{esm/plugins → plugins}/three/importers.js +0 -0
  124. /package/{cjs/plugins → plugins}/three/index.d.ts +0 -0
  125. /package/{esm/plugins → plugins}/three/index.js +0 -0
  126. /package/{cjs/plugins → plugins}/three/threngine.d.ts +0 -0
  127. /package/{esm/plugins → plugins}/three/threngine.js +0 -0
  128. /package/{cjs/strategy → strategy}/assignemntTo.d.ts +0 -0
  129. /package/{esm/strategy → strategy}/assignemntTo.js +0 -0
  130. /package/{cjs/strategy → strategy}/declarationOf.d.ts +0 -0
  131. /package/{esm/strategy → strategy}/declarationOf.js +0 -0
  132. /package/{cjs/strategy → strategy}/hardCode.d.ts +0 -0
  133. /package/{esm/strategy → strategy}/hardCode.js +0 -0
  134. /package/{cjs/strategy → strategy}/index.d.ts +0 -0
  135. /package/{esm/strategy → strategy}/index.js +0 -0
  136. /package/{cjs/strategy → strategy}/inject.d.ts +0 -0
  137. /package/{esm/strategy → strategy}/inject.js +0 -0
  138. /package/{cjs/strategy → strategy}/namedAttribute.d.ts +0 -0
  139. /package/{esm/strategy → strategy}/namedAttribute.js +0 -0
  140. /package/{cjs/strategy → strategy}/strategy.d.ts +0 -0
  141. /package/{esm/strategy → strategy}/strategy.js +0 -0
  142. /package/{cjs/strategy → strategy}/stratgies.test.d.ts +0 -0
  143. /package/{esm/strategy → strategy}/stratgies.test.js +0 -0
  144. /package/{cjs/strategy → strategy}/texture2D.d.ts +0 -0
  145. /package/{esm/strategy → strategy}/texture2D.js +0 -0
  146. /package/{cjs/strategy → strategy}/uniform.d.ts +0 -0
  147. /package/{esm/strategy → strategy}/uniform.js +0 -0
  148. /package/{cjs/strategy → strategy}/variable.d.ts +0 -0
  149. /package/{esm/strategy → strategy}/variable.js +0 -0
  150. /package/{cjs/util → util}/ast.d.ts +0 -0
  151. /package/{esm/util → util}/ast.js +0 -0
  152. /package/{cjs/util → util}/ensure.d.ts +0 -0
  153. /package/{esm/util → util}/ensure.js +0 -0
  154. /package/{cjs/util → util}/id.d.ts +0 -0
  155. /package/{esm/util → util}/id.js +0 -0
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- var engine_1 = require("../../engine");
5
- var nodeInputMap = {
6
- normalMap: 'bumpSampler',
7
- property_map: 'property_albedoTexture',
8
- property_normalMap: 'property_bumpTexture',
9
- property_color: 'property_albedoColor',
10
- property_metalness: 'property_metallic',
11
- filler_position: 'filler_position',
12
- };
13
- var importers = {
14
- three: {
15
- convertAst: function (ast, type) {
16
- throw new Error('Not implemented');
17
- },
18
- nodeInputMap: (_a = {},
19
- _a[engine_1.EngineNodeType.physical] = nodeInputMap,
20
- _a),
21
- edgeMap: {
22
- normalMap: 'bumpSampler',
23
- property_map: 'property_albedoTexture',
24
- property_normalMap: 'property_bumpTexture',
25
- property_color: 'property_albedoColor',
26
- property_metalness: 'property_metallic',
27
- },
28
- },
29
- };
30
- exports.default = importers;
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.engine = void 0;
4
- var playengine_1 = require("./playengine");
5
- Object.defineProperty(exports, "engine", { enumerable: true, get: function () { return playengine_1.playengine; } });
@@ -1,549 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
- return new (P || (P = Promise))(function (resolve, reject) {
39
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- };
45
- var __generator = (this && this.__generator) || function (thisArg, body) {
46
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
- function verb(n) { return function (v) { return step([n, v]); }; }
49
- function step(op) {
50
- if (f) throw new TypeError("Generator is already executing.");
51
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
- if (y = 0, t) op = [op[0] & 2, t.value];
54
- switch (op[0]) {
55
- case 0: case 1: t = op; break;
56
- case 4: _.label++; return { value: op[1], done: false };
57
- case 5: _.label++; y = op[1]; op = [0]; continue;
58
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
- default:
60
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
- if (t[2]) _.ops.pop();
65
- _.trys.pop(); continue;
66
- }
67
- op = body.call(thisArg, _);
68
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
- }
71
- };
72
- var __read = (this && this.__read) || function (o, n) {
73
- var m = typeof Symbol === "function" && o[Symbol.iterator];
74
- if (!m) return o;
75
- var i = m.call(o), r, ar = [], e;
76
- try {
77
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
78
- }
79
- catch (error) { e = { error: error }; }
80
- finally {
81
- try {
82
- if (r && !r.done && (m = i["return"])) m.call(i);
83
- }
84
- finally { if (e) throw e.error; }
85
- }
86
- return ar;
87
- };
88
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
89
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
90
- if (ar || !(i in from)) {
91
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
92
- ar[i] = from[i];
93
- }
94
- }
95
- return to.concat(ar || Array.prototype.slice.call(from));
96
- };
97
- var __importDefault = (this && this.__importDefault) || function (mod) {
98
- return (mod && mod.__esModule) ? mod : { "default": mod };
99
- };
100
- var _a, _b;
101
- Object.defineProperty(exports, "__esModule", { value: true });
102
- exports.playengine = exports.mIdx = exports.toonNode = exports.physicalNode = exports.defaultPropertySetting = exports.physicalDefaultProperties = void 0;
103
- var pc = __importStar(require("playcanvas"));
104
- var engine_1 = require("../../engine");
105
- var graph_1 = require("../../graph/graph");
106
- var graph_types_1 = require("../../graph/graph-types");
107
- var importers_1 = __importDefault(require("./importers"));
108
- var ast_1 = require("../../util/ast");
109
- var code_nodes_1 = require("../../graph/code-nodes");
110
- var strategy_1 = require("../../strategy");
111
- var log = function () {
112
- var _a;
113
- var args = [];
114
- for (var _i = 0; _i < arguments.length; _i++) {
115
- args[_i] = arguments[_i];
116
- }
117
- return (_a = console.log).call.apply(_a, __spreadArray([console, '\x1b[33m(playengine)\x1b[0m'], __read(args), false));
118
- };
119
- exports.physicalDefaultProperties = {
120
- // Required for objects with opacity
121
- blendType: pc.BLEND_NORMAL,
122
- // Hack (for now?). Playcanvas optimizes their materials to not calculate in
123
- // the generated GLSL, if opacity is set to 1 or is unused. This forces the
124
- // generated shader to include the opacity calculation. When we tween the
125
- // opacity slider at runtime, playcanvas instantly generates a new shader +
126
- // GLSL. The front-end code hijacks that call, and for now, for conveneinece,
127
- // uses the GLSL from the core here that always includes opacity. Another
128
- // option is to hijack both variations of the shader and generate two core
129
- // variations. I might need to consider that with additional parameter
130
- // variations.
131
- opacity: 0.5,
132
- // not sure if required for metalness https://developer.playcanvas.com/en/api/pc.StandardMaterial.html#useMetalness
133
- useMetalness: true,
134
- // Double sided
135
- cull: pc.CULLFACE_NONE,
136
- };
137
- /**
138
- * For the use of "0.5", apparently PlayCanvas optimizes uniform
139
- * generation where if you set diffuse to white (1,1,1) then it doesn't
140
- * add the diffuse uniform, because that's the default state.
141
- */
142
- var defaultPropertySetting = function (app, property) {
143
- if (property.type === 'texture') {
144
- return new pc.Texture(app.graphicsDevice);
145
- }
146
- else if (property.type === 'number') {
147
- return 0.5;
148
- }
149
- else if (property.type === 'rgb') {
150
- return new pc.Color(0.5, 0.5, 0.5);
151
- }
152
- else if (property.type === 'rgba') {
153
- return new pc.Color(0.5, 0.5, 0.5, 0.5);
154
- }
155
- };
156
- exports.defaultPropertySetting = defaultPropertySetting;
157
- var applyPlayMaterialProperties = function (engineContext, shaderMaterial, app, graph, node, sibling) {
158
- // Find inputs to this node that are dependent on a property of the material
159
- var propertyInputs = node.inputs
160
- .filter(function (i) { return i.property; })
161
- .reduce(function (acc, input) {
162
- var _a;
163
- return (__assign(__assign({}, acc), (_a = {}, _a[input.id] = input, _a)));
164
- }, {});
165
- // Then look for any edges into those inputs and set the material property
166
- var props = graph.edges
167
- .filter(function (edge) { return edge.to === node.id || edge.to === (sibling === null || sibling === void 0 ? void 0 : sibling.id); })
168
- .reduce(function (acc, edge) {
169
- // Check if we've plugged into an input for a property
170
- var propertyInput = propertyInputs[edge.input];
171
- if (propertyInput) {
172
- // Find the property itself
173
- var property_1 = (node.config.properties || []).find(function (p) { return p.property === propertyInput.property; });
174
- /**
175
- * For the mutation, you apparently need to explicitily call .set() on
176
- * some properties, like diffuse:
177
- * material.diffuse = new pc.Color(0.5, 0.5, 0.5)
178
- * has no effect. You have to do
179
- * material.diffuse.set(0.5, 0.5, 0.5)
180
- * and note the API isn't great, you can't do
181
- * material.diffuse.set(new pc.Color(...))
182
- * This code will probably error on some properties because I don't know
183
- * if all "rgb" properties have to be set in this painful way.
184
- */
185
- acc[property_1.property] = (0, exports.defaultPropertySetting)(app, property_1);
186
- // @ts-ignore
187
- shaderMaterial[property_1.property] = acc[property_1.property];
188
- }
189
- return acc;
190
- }, {});
191
- return props;
192
- };
193
- var physicalNode = function (id, name, position, uniforms, stage) {
194
- return (0, graph_1.prepopulatePropertyInputs)({
195
- id: id,
196
- name: 'StandardMaterial',
197
- position: position,
198
- engine: true,
199
- type: engine_1.EngineNodeType.physical,
200
- config: {
201
- uniforms: uniforms,
202
- version: 3,
203
- mangle: false,
204
- preprocess: true,
205
- properties: [
206
- (0, code_nodes_1.property)('Color', 'diffuse', 'rgb'),
207
- // Object is black while using these
208
- // property('Emissive', 'emissive', 'rgb'),
209
- // property('Emissive Intensity', 'emissiveIntensity', 'number'),
210
- // property('Emissive Map', 'emissiveMap', 'texture'),
211
- (0, code_nodes_1.property)('Diffuse Map', 'diffuseMap', 'texture', 'filler_texture_diffuseMap'),
212
- (0, code_nodes_1.property)('Normal Map', 'normalMap', 'texture', 'filler_texture_normalMap'),
213
- (0, code_nodes_1.property)('Bumpiness', 'bumpiness', 'number'),
214
- (0, code_nodes_1.property)('Specular', 'specular', 'rgb'),
215
- (0, code_nodes_1.property)('Glossiness', 'gloss', 'number'),
216
- (0, code_nodes_1.property)('Opacity', 'opacity', 'number'),
217
- (0, code_nodes_1.property)('Opacity Map', 'opacityMap', 'texture'),
218
- (0, code_nodes_1.property)('Metalness', 'metalness', 'number'),
219
- (0, code_nodes_1.property)('Reflectivity', 'reflectivity', 'number'),
220
- (0, code_nodes_1.property)('Refraction', 'refraction', 'number'),
221
- (0, code_nodes_1.property)('Refraction Index', 'refractionIndex', 'number'),
222
- // property('Bump Map', 'bumpTexture', 'texture', 'filler_bumpSampler'),
223
- // property('Metalness', 'metallic', 'number'),
224
- // property('Roughness', 'roughness', 'number'),
225
- // property('Env Map', 'environmentTexture', 'samplerCube'),
226
- // property('Reflection Texture', 'reflectionTexture', 'samplerCube'),
227
- // property('Refraction Texture', 'refractionTexture', 'samplerCube'),
228
- // property('Index Of Refraction', 'indexOfRefraction', 'number'),
229
- // property('Alpha', 'alpha', 'number'),
230
- // property('Direct Intensity', 'directIntensity', 'number'),
231
- // property('Environment Intensity', 'environmentIntensity', 'number'),
232
- // property('Camera Exposure', 'cameraExposure', 'number'),
233
- // property('Camera Contrast', 'cameraContrast', 'number'),
234
- // property('Micro Surface', 'microSurface', 'number'),
235
- // property('Reflectivity Color', 'reflectivityColor', 'rgb'),
236
- ],
237
- hardCodedProperties: exports.physicalDefaultProperties,
238
- strategies: [
239
- (0, strategy_1.uniformStrategy)(),
240
- stage === 'fragment'
241
- ? (0, strategy_1.texture2DStrategy)()
242
- : (0, strategy_1.namedAttributeStrategy)('vertex_position'),
243
- ],
244
- },
245
- inputs: [],
246
- outputs: [
247
- {
248
- name: 'vector4',
249
- dataType: 'vector4',
250
- category: 'data',
251
- id: '1',
252
- },
253
- ],
254
- source: '',
255
- stage: stage,
256
- });
257
- };
258
- exports.physicalNode = physicalNode;
259
- var toonNode = function (id, name, position, uniforms, stage) {
260
- return (0, graph_1.prepopulatePropertyInputs)({
261
- id: id,
262
- name: name,
263
- position: position,
264
- engine: true,
265
- type: engine_1.EngineNodeType.toon,
266
- config: {
267
- uniforms: uniforms,
268
- version: 3,
269
- preprocess: true,
270
- mangle: false,
271
- properties: [
272
- (0, code_nodes_1.property)('Color', 'color', 'rgb', 'uniform_diffuse'),
273
- (0, code_nodes_1.property)('Texture', 'map', 'texture', 'filler_map'),
274
- (0, code_nodes_1.property)('Gradient Map', 'gradientMap', 'texture', 'filler_gradientMap'),
275
- (0, code_nodes_1.property)('Normal Map', 'normalMap', 'texture', 'filler_normalMap'),
276
- (0, code_nodes_1.property)('Normal Scale', 'normalScale', 'vector2'),
277
- (0, code_nodes_1.property)('Displacement Map', 'displacementMap', 'texture'),
278
- (0, code_nodes_1.property)('Env Map', 'envMap', 'samplerCube'),
279
- ],
280
- strategies: [
281
- (0, strategy_1.uniformStrategy)(),
282
- stage === 'fragment'
283
- ? (0, strategy_1.texture2DStrategy)()
284
- : (0, strategy_1.namedAttributeStrategy)('position'),
285
- ],
286
- },
287
- inputs: [],
288
- outputs: [
289
- {
290
- name: 'vector4',
291
- dataType: 'vector4',
292
- category: 'data',
293
- id: '1',
294
- },
295
- ],
296
- source: '',
297
- stage: stage,
298
- });
299
- };
300
- exports.toonNode = toonNode;
301
- exports.mIdx = 0;
302
- var id = function () { return exports.mIdx++; };
303
- var nodeCacheKey = function (graph, node) {
304
- return ('[ID:' +
305
- node.id +
306
- 'Edges:' +
307
- graph.edges
308
- .filter(function (edge) { return edge.to === node.id; })
309
- .map(function (edge) { return "(".concat(edge.to, "->").concat(edge.input, ")"); })
310
- .sort()
311
- .join(',') +
312
- ']'
313
- // Currently excluding node inputs because these are calculated *after*
314
- // the onbeforecompile, so the next compile, they'll all change!
315
- // node.inputs.map((i) => `${i.id}${i.bakeable}`)
316
- );
317
- };
318
- var programCacheKey = function (engineContext, graph, node, sibling) {
319
- var app = engineContext.runtime.app;
320
- var lights = app.root
321
- .findComponents('light')
322
- .map(function (l) { return l.type; });
323
- return ([node, sibling]
324
- .filter(function (n) { return !!n; })
325
- .sort(function (a, b) { return a.id.localeCompare(b.id); })
326
- .map(function (n) { return nodeCacheKey(graph, n); })
327
- .join('-') +
328
- '|Lights:' +
329
- lights.join(',') +
330
- '|Envtex:' +
331
- [app.scene.envAtlas, app.scene.prefilteredCubemaps].join(','));
332
- };
333
- var cacher = function (engineContext, graph, node, sibling, newValue) { return __awaiter(void 0, void 0, void 0, function () {
334
- var cacheKey, materialData;
335
- return __generator(this, function (_a) {
336
- switch (_a.label) {
337
- case 0:
338
- cacheKey = programCacheKey(engineContext, graph, node, sibling);
339
- if (engineContext.runtime.cache.data[cacheKey]) {
340
- log("Cache hit \"".concat(cacheKey, "\""));
341
- }
342
- else {
343
- log("Cache miss \"".concat(cacheKey, "\""));
344
- }
345
- return [4 /*yield*/, (engineContext.runtime.cache.data[cacheKey] ||
346
- newValue())];
347
- case 1:
348
- materialData = _a.sent();
349
- log("Material cache \"".concat(cacheKey, "\" is now"), materialData);
350
- engineContext.runtime.cache.data[cacheKey] = materialData;
351
- engineContext.runtime.engineMaterial = materialData.material;
352
- // TODO: We mutate the nodes here, can we avoid that later?
353
- node.source =
354
- node.stage === 'fragment' ? materialData.fragment : materialData.vertex;
355
- if (sibling) {
356
- sibling.source =
357
- sibling.stage === 'fragment'
358
- ? materialData.fragment
359
- : materialData.vertex;
360
- }
361
- return [2 /*return*/];
362
- }
363
- });
364
- }); };
365
- var onBeforeCompileMegaShader = function (engineContext, graph, node, sibling) { return __awaiter(void 0, void 0, void 0, function () {
366
- var _a, appUn, sceneData, app, pbrName, shaderMaterial, newProperties, applied, vertexSource, fragmentSource, origMat;
367
- var _b;
368
- return __generator(this, function (_c) {
369
- _a = engineContext.runtime, appUn = _a.app, sceneData = _a.sceneData;
370
- app = appUn;
371
- pbrName = "engine_pbr".concat(id());
372
- shaderMaterial = new pc.StandardMaterial();
373
- shaderMaterial.name = pbrName;
374
- newProperties = __assign({}, (node.config.hardCodedProperties ||
375
- ((_b = sibling === null || sibling === void 0 ? void 0 : sibling.config) === null || _b === void 0 ? void 0 : _b.hardCodedProperties) ||
376
- {}));
377
- Object.assign(shaderMaterial, newProperties);
378
- applied = applyPlayMaterialProperties(engineContext, shaderMaterial, app, graph, node, sibling);
379
- log('Engine megashader initial properties', __assign(__assign({}, newProperties), applied));
380
- // This is a hack to force the material to regenerate. The chunks are used
381
- // internally in playcanvas to generate the material cache key. If you use
382
- // a real chunk, it messes up the GLSL. So this introduces a fake chunk that
383
- // isn't used in the GLSL, but forces a new material to generate. The code
384
- // path I'm hacking through is:
385
- // render() -> renderForward() -> updatePassShader() -> getShaderVariant() ->
386
- // library.getProgram() -> generateShaderDefinition()
387
- // TODO: Try using the new hook https://github.com/playcanvas/engine/pull/5524
388
- shaderMaterial.chunks.engineHackSource = "".concat(Math.random());
389
- // I had this here before for testing, I commented it out trying to figure out
390
- // the opacity issue while working on Playcanvas. Can remove if I ever figure
391
- // out the opacity issue
392
- // shaderMaterial.clearVariants();
393
- shaderMaterial.update();
394
- origMat = sceneData.mesh.render.meshInstances[0].material;
395
- sceneData.mesh.render.meshInstances[0].material = shaderMaterial;
396
- // Force shader compilation
397
- app.render();
398
- sceneData.mesh.render.meshInstances[0].material = origMat;
399
- return [2 /*return*/, new Promise(function (resolve) {
400
- var variants = shaderMaterial.variants;
401
- if (variants.size === 1) {
402
- var _a = __read(variants.entries().next().value, 2), untypedVariant = _a[1];
403
- var variant = untypedVariant;
404
- var _b = variant.definition, fshader = _b.fshader, vshader = _b.vshader;
405
- fragmentSource = fshader;
406
- vertexSource = vshader;
407
- engineContext.runtime.cache.nodes[node.id] = {
408
- fragment: fshader,
409
- vertex: vshader,
410
- };
411
- }
412
- else {
413
- console.error('Bad variants!', variants);
414
- }
415
- resolve({
416
- material: shaderMaterial,
417
- fragment: fragmentSource,
418
- vertex: vertexSource,
419
- });
420
- })];
421
- });
422
- }); };
423
- // TODO: NEED TO DO SAME THREE MANGLIGN STEP HERE
424
- var megaShaderMainpulateAst = function (engineContext, engine, graph, ast, inputEdges, node, sibling) {
425
- var programAst = ast;
426
- var mainName = 'main' || (0, graph_1.nodeName)(node);
427
- if (node.stage === 'vertex') {
428
- if ((0, graph_1.doesLinkThruShader)(graph, node)) {
429
- (0, ast_1.returnGlPositionHardCoded)(mainName, programAst, 'vec3', 'transformed');
430
- }
431
- else {
432
- (0, ast_1.returnGlPosition)(mainName, programAst);
433
- }
434
- }
435
- // We specify engine nodes are mangle: false, which is the graph step that
436
- // handles renaming the main fn, so we have to do it ourselves
437
- (0, graph_1.mangleMainFn)(programAst, node, sibling);
438
- return programAst;
439
- };
440
- var evaluateNode = function (node) {
441
- if (node.type === 'number') {
442
- return parseFloat(node.value);
443
- // Apparently PlayCanvas can't use new pc.Vec2(...), etc for vector uniforms,
444
- // and instead requires arrays? But can (maybe) use a pc.Color() for other
445
- // uniforms? I need to test the color assumption, but it's weird PC doesn't
446
- // use its own types for uniforms
447
- }
448
- else if (node.type === 'texture') {
449
- return node;
450
- }
451
- else if (node.type === 'vector2') {
452
- return [parseFloat(node.value[0]), parseFloat(node.value[1])];
453
- }
454
- else if (node.type === 'vector3') {
455
- return [
456
- parseFloat(node.value[0]),
457
- parseFloat(node.value[1]),
458
- parseFloat(node.value[2]),
459
- ];
460
- }
461
- else if (node.type === 'vector4') {
462
- return [
463
- parseFloat(node.value[0]),
464
- parseFloat(node.value[1]),
465
- parseFloat(node.value[2]),
466
- parseFloat(node.value[3]),
467
- ];
468
- }
469
- else if (node.type === 'rgb') {
470
- return [
471
- parseFloat(node.value[0]),
472
- parseFloat(node.value[1]),
473
- parseFloat(node.value[2]),
474
- ];
475
- }
476
- else if (node.type === 'rgba') {
477
- return [
478
- parseFloat(node.value[0]),
479
- parseFloat(node.value[1]),
480
- parseFloat(node.value[2]),
481
- parseFloat(node.value[3]),
482
- ];
483
- }
484
- else {
485
- return node.value;
486
- }
487
- };
488
- exports.playengine = {
489
- name: 'playcanvas',
490
- displayName: 'PlayCanvas',
491
- importers: importers_1.default,
492
- mergeOptions: {
493
- includePrecisions: true,
494
- includeVersion: false,
495
- },
496
- evaluateNode: evaluateNode,
497
- constructors: (_a = {},
498
- _a[engine_1.EngineNodeType.physical] = exports.physicalNode,
499
- _a[engine_1.EngineNodeType.toon] = exports.toonNode,
500
- _a),
501
- // TODO: Move into core based on engine shader scrape
502
- preserve: new Set([
503
- 'matrix_model',
504
- 'matrix_normal',
505
- 'matrix_view',
506
- 'matrix_viewProjection',
507
- 'time',
508
- 'vertex_color',
509
- 'vertex_normal',
510
- 'vertex_position',
511
- 'vertex_tangent',
512
- 'vertex_tangent',
513
- 'vertex_texCoord0',
514
- 'vertex_texCoord1',
515
- 'vNormalW',
516
- 'vPositionW',
517
- 'vUv0',
518
- ]),
519
- parsers: (_b = {},
520
- _b[graph_types_1.NodeType.SOURCE] = {
521
- manipulateAst: function (engineContext, engine, graph, ast, inputEdges, node, sibling) {
522
- var programAst = ast;
523
- var mainName = 'main' || (0, graph_1.nodeName)(node);
524
- // This hinges on the vertex shader calling vec3(p)
525
- if (node.stage === 'vertex') {
526
- if ((0, graph_1.doesLinkThruShader)(graph, node)) {
527
- (0, ast_1.returnGlPositionVec3Right)(mainName, programAst);
528
- }
529
- else {
530
- (0, ast_1.returnGlPosition)(mainName, programAst);
531
- }
532
- }
533
- return ast;
534
- },
535
- },
536
- _b[engine_1.EngineNodeType.physical] = {
537
- onBeforeCompile: function (graph, engineContext, node, sibling) {
538
- return cacher(engineContext, graph, node, sibling, function () {
539
- return onBeforeCompileMegaShader(engineContext, graph, node, sibling);
540
- });
541
- },
542
- manipulateAst: megaShaderMainpulateAst,
543
- },
544
- _b),
545
- };
546
- exports.playengine.parsers[engine_1.EngineNodeType.toon] =
547
- exports.playengine.parsers[engine_1.EngineNodeType.physical];
548
- exports.playengine.parsers[engine_1.EngineNodeType.phong] =
549
- exports.playengine.parsers[engine_1.EngineNodeType.physical];
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var utils_1 = require("@shaderfrog/glsl-parser/parser/utils");
4
- var importers = {
5
- babylon: {
6
- convertAst: function (ast, type) {
7
- (0, utils_1.renameBindings)(ast.scopes[0], function (name) {
8
- return name === 'vMainUV1' ? 'vUv' : name === 'vNormalW' ? 'vNormal' : name;
9
- });
10
- },
11
- nodeInputMap: {},
12
- edgeMap: {
13
- bumpSampler: 'normalMap',
14
- },
15
- },
16
- };
17
- exports.default = importers;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.engine = exports.createMaterial = void 0;
4
- var threngine_1 = require("./threngine");
5
- Object.defineProperty(exports, "createMaterial", { enumerable: true, get: function () { return threngine_1.createMaterial; } });
6
- Object.defineProperty(exports, "engine", { enumerable: true, get: function () { return threngine_1.threngine; } });