Skip to content

Commit 5bc6cb1

Browse files
committed
address code review feedback
1 parent c32a853 commit 5bc6cb1

File tree

3 files changed

+46
-29
lines changed

3 files changed

+46
-29
lines changed

src/graphics/program-lib/programs/node.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,7 @@ var node = {
2121
return key;
2222
},
2323

24-
createShaderDefinition: function (device, options) {
25-
// generate graph
26-
var rootDeclGLSL = options.shaderGraph.generateRootDeclGlsl();
27-
var rootCallGLSL = options.shaderGraph.generateRootCallGlsl();
28-
29-
// GENERATE ATTRIBUTES
30-
var attributes = {
31-
vertex_position: SEMANTIC_POSITION,
32-
vertex_normal: SEMANTIC_NORMAL,
33-
vertex_color: SEMANTIC_COLOR,
34-
vertex_texCoord0: SEMANTIC_TEXCOORD0
35-
};
36-
if (options.skin) {
37-
attributes.vertex_boneWeights = SEMANTIC_BLENDWEIGHT;
38-
attributes.vertex_boneIndices = SEMANTIC_BLENDINDICES;
39-
}
40-
24+
_generateVertexShader: function (device, options, rootDeclGLSL, rootCallGLSL) {
4125
var chunks = shaderChunks;
4226

4327
// GENERATE VERTEX SHADER
@@ -109,6 +93,12 @@ var node = {
10993
vshader = startCode + vshader;
11094
}
11195

96+
return vshader;
97+
},
98+
99+
_generateFragmentShader: function (device, options, rootDeclGLSL, rootCallGLSL) {
100+
var chunks = shaderChunks;
101+
112102
// GENERATE FRAGMENT SHADER
113103
if (options.forceFragmentPrecision && options.forceFragmentPrecision != "highp" &&
114104
options.forceFragmentPrecision !== "mediump" && options.forceFragmentPrecision !== "lowp")
@@ -119,7 +109,7 @@ var node = {
119109
if (options.forceFragmentPrecision === "mediump" && device.maxPrecision === "lowp") options.forceFragmentPrecision = "lowp";
120110
}
121111

122-
code = '';
112+
var code = '';
123113

124114
if (device.webgl2) {
125115
code += versionCode(device);
@@ -179,7 +169,30 @@ var node = {
179169

180170
code += end();
181171

182-
var fshader = code;
172+
return code;
173+
},
174+
175+
createShaderDefinition: function (device, options) {
176+
// generate graph
177+
// TODO: support generation of shader variants based on options
178+
var rootDeclGLSL = options.shaderGraph.generateRootDeclGlsl();
179+
var rootCallGLSL = options.shaderGraph.generateRootCallGlsl();
180+
181+
// GENERATE ATTRIBUTES
182+
var attributes = {
183+
vertex_position: SEMANTIC_POSITION,
184+
vertex_normal: SEMANTIC_NORMAL,
185+
vertex_color: SEMANTIC_COLOR,
186+
vertex_texCoord0: SEMANTIC_TEXCOORD0
187+
};
188+
if (options.skin) {
189+
attributes.vertex_boneWeights = SEMANTIC_BLENDWEIGHT;
190+
attributes.vertex_boneIndices = SEMANTIC_BLENDINDICES;
191+
}
192+
193+
var vshader = this._generateVertexShader(device, options, rootDeclGLSL, rootCallGLSL);
194+
195+
var fshader = this._generateFragmentShader(device, options, rootDeclGLSL, rootCallGLSL);
183196

184197
return {
185198
attributes: attributes,

src/resources/node-material.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import { NodeMaterial } from '../scene/materials/node-material.js';
88
* @class
99
* @name pc.NodeMaterialBinder
1010
* @classdesc Resource binder used for binding {@link pc.NodeMaterial} resources.
11-
* @param {pc.Application} app - The running {@link pc.Application}.
11+
* @param {pc.AssetRegistry} assets - The asset registry.
12+
* @param {pc.GraphicsDevice} device - The graphics device of the application.
1213
* @param {pc.JsonNodeMaterialParser} parser - JSON parser for {@link pc.NodeMaterial} owned by global {@link pc.MaterialHandler}
1314
*/
14-
function NodeMaterialBinder(app, parser) {
15-
this._assets = app.assets;
16-
this._device = app.graphicsDevice;
15+
function NodeMaterialBinder(assets, device, parser) {
16+
this._assets = assets;
17+
this._device = device;
1718
this._parser = parser;
1819

1920
this._placeholderGraph = null;

src/scene/materials/node-material.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ Object.assign(NodeMaterial.prototype, {
254254
} else if (typeof(value) === 'number') {
255255
graphVar = { type: type, name: name, valueX: value };
256256
} else {
257-
graphVar = { type: type, name: name };
257+
// currently unsupported value type - should not be possible in editor
258+
// TODO: deal with this case when script interface is completed.
258259
}
259260

260261
this.graphData.graphVars.push(graphVar);
@@ -389,12 +390,14 @@ Object.assign(NodeMaterial.prototype, {
389390
return callString;
390391
},
391392

392-
_getGraphVarByName: function (name) {
393+
// this is currently not used - but will be used by the shadergraph script interface
394+
// TODO: re-enable and optimize using transient name map
395+
// _getGraphVarByName: function (name) {
393396
// convienient but not fast - TODO: optimize?
394-
return this.graphData.graphVars.filter(function (graphVar) {
395-
return graphVar.name === name;
396-
})[0];
397-
},
397+
// return this.graphData.graphVars.filter(function (graphVar) {
398+
// return graphVar.name === name;
399+
// })[0];
400+
// },
398401

399402
_generateSubGraphFuncs: function (depGraphFuncs, depGraphVarList) {
400403
var i;

0 commit comments

Comments
 (0)