Skip to content

Commit 7726ddc

Browse files
committed
remove WIP shadergraph script interface
1 parent 08adb50 commit 7726ddc

File tree

4 files changed

+4
-250
lines changed

4 files changed

+4
-250
lines changed

examples/graphics/shader-node.html

Lines changed: 0 additions & 123 deletions
This file was deleted.

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export { Model } from './scene/model.js';
8787
export { Morph } from './scene/morph.js';
8888
export { MorphInstance } from './scene/morph-instance.js';
8989
export { MorphTarget } from './scene/morph-target.js';
90-
export { NodeMaterial, shadergraph } from './scene/materials/node-material.js';
90+
export { NodeMaterial } from './scene/materials/node-material.js';
9191
export { ParticleEmitter } from './scene/particle-system/particle-emitter.js';
9292
export { Picker } from './scene/pick.js';
9393
export { Scene } from './scene/scene.js';

src/resources/parser/material/json-node-material.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NodeMaterial, shadergraph } from '../../../scene/materials/node-material.js';
1+
import { NodeMaterial } from '../../../scene/materials/node-material.js';
22

33
/**
44
* @class
@@ -165,23 +165,7 @@ JsonNodeMaterialParser.prototype._validate = function (data) {
165165
};
166166

167167
JsonNodeMaterialParser.prototype._genPlaceholderNodeMat = function () {
168-
// start building shader graph
169-
shadergraph.start();
170-
171-
// create a blank PS shader graph node
172-
var blankPSNode = shadergraph.customNode('blankPS', 'vec4 blankPS() { return vec4(0,0,1,1); }');
173-
174-
// hook up PS outputs
175-
shadergraph.connectFragOut(blankPSNode);
176-
177-
// create a blank vertex offset shader graph node
178-
var blankVSNode = shadergraph.customNode('blankVS', 'vec3 blankVS() { return vec3(0,0,0); }');
179-
180-
// hook up VS output
181-
shadergraph.connectVertexOffset(blankVSNode);
182-
183-
// end graph and assign built graph to material
184-
var material = shadergraph.end();
168+
var material = new NodeMaterial('void placeHolder(out vec3 vertOff, out vec4 fragOut){ vertOff=vec3(0); fragOut=vec4(0,0,1,1);}');
185169

186170
// initialize shader and update uniforms
187171
material.initShader(this._device);

src/scene/materials/node-material.js

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -722,111 +722,4 @@ Object.assign(NodeMaterial.prototype, {
722722

723723
});
724724

725-
var shadergraph = {};
726-
727-
shadergraph.graphCounter = 0;
728-
729-
shadergraph.nodeRegistry = {};
730-
731-
shadergraph._getNode = function (name, funcString, declString) {
732-
if (!this.nodeRegistry[name]) {
733-
this.nodeRegistry[name] = new NodeMaterial(funcString, declString);
734-
}
735-
736-
return this.nodeRegistry[name];
737-
};
738-
739-
shadergraph.start = function () {
740-
// check current graph is null?
741-
shadergraph.graph = this._getNode('graphRoot_' + shadergraph.graphCounter);
742-
shadergraph.graph.name = 'graphRoot_' + shadergraph.graphCounter;
743-
};
744-
745-
shadergraph.end = function () {
746-
var ret = shadergraph.graph;
747-
shadergraph.graph = null;
748-
shadergraph.graphCounter++;
749-
return ret;
750-
};
751-
752-
shadergraph.textureSample2D = function (name, texture, uv) {
753-
754-
var texSampNode = this.graph.addSubGraph(this._getNode('texSample', 'vec4 texSample(in sampler2D tex, in vec2 uv, out vec3 color, out float alpha) {\n vec4 samp=texture2D(tex, uv);\n color=samp.rgb;\n alpha=samp.a;\n return samp;\n}'));
755-
756-
// assumes name is unique TODO: verify?
757-
var graphVar = this.graph.addInput('sampler2D', name, texture);
758-
this.graph.connect(-1, graphVar.name, texSampNode, 'IN_tex');
759-
this.graph.connect(uv, 'OUT_ret', texSampNode, 'IN_uv');
760-
761-
return texSampNode;
762-
};
763-
764-
shadergraph.customNode = function (name, f, d) {
765-
var nodeIndex = this.graph.addSubGraph(this._getNode(name, f, d));
766-
return nodeIndex;
767-
};
768-
769-
Object.defineProperty(shadergraph, 'uv0', {
770-
get: function () {
771-
var nodeIndex = this.graph.addSubGraph(this._getNode('uv0', 'vec2 uv0() { return vUv0; }'));
772-
return nodeIndex;
773-
}
774-
});
775-
776-
Object.defineProperty(shadergraph, 'worldPosPS', {
777-
get: function () {
778-
var nodeIndex = this.graph.addSubGraph(this._getNode('worldPosPS', 'vec3 wpPS() { return vPosition; }'));
779-
return nodeIndex;
780-
}
781-
});
782-
783-
Object.defineProperty(shadergraph, 'worldNormPS', {
784-
get: function () {
785-
var nodeIndex = this.graph.addSubGraph(this._getNode('worldNormPS', 'vec3 wnPS() { return vNormal; }'));
786-
return nodeIndex;
787-
}
788-
});
789-
790-
Object.defineProperty(shadergraph, 'worldPosVS', {
791-
get: function () {
792-
var nodeIndex = this.graph.addSubGraph(this._getNode('worldPosVS', 'vec3 wpVS() { return getWorldPositionNM(); }'));
793-
return nodeIndex;
794-
}
795-
});
796-
797-
Object.defineProperty(shadergraph, 'worldNormVS', {
798-
get: function () {
799-
var nodeIndex = this.graph.addSubGraph(this._getNode('worldNormVS', 'vec3 wnVS() { return getWorldNormalNM(); }'));
800-
return nodeIndex;
801-
}
802-
});
803-
804-
shadergraph.param = function (type, name, value) {
805-
// assumes name is unique TODO: verify this
806-
var graphVar = this.graph.addInput(type, name, value);
807-
return graphVar;
808-
};
809-
810-
shadergraph.connectFragOut = function (nodeIndex, name) {
811-
// assumes this is only called once per graph TODO: verify this
812-
var graphVar = this.graph.addOutput('vec4', 'fragOut', [0, 0, 0, 0]);
813-
this.graph.connect(nodeIndex, (name) ? 'OUT_' + name : 'OUT_ret', -1, graphVar.name);
814-
};
815-
816-
shadergraph.connectVertexOffset = function (nodeIndex, name) {
817-
// assumes this is only called once per graph TODO: verify this
818-
var graphVar = this.graph.addOutput('vec3', 'vertOff', [0, 0, 0]);
819-
this.graph.connect(nodeIndex, (name) ? 'OUT_' + name : 'OUT_ret', -1, graphVar.name);
820-
};
821-
822-
shadergraph.connectCustom = function (destNodeIndex, destName, nodeIndex_or_param, name) {
823-
if (typeof(nodeIndex_or_param) === 'number') {
824-
var nodeIndex = nodeIndex_or_param;
825-
this.graph.connect(nodeIndex, (name) ? 'OUT_' + name : 'OUT_ret', destNodeIndex, 'IN_' + destName);
826-
} else {
827-
var graphVar = nodeIndex_or_param;
828-
this.graph.connect(-1, graphVar.name, destNodeIndex, 'IN_' + destName);
829-
}
830-
};
831-
832-
export { NodeMaterial, shadergraph };
725+
export { NodeMaterial };

0 commit comments

Comments
 (0)