123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- package hrt.shgraph;
- using hxsl.Ast;
- class NodeVar {
- public var node : ShaderNode;
- public var keyOutput : String;
- public function new ( n : ShaderNode, key : String ) {
- node = n;
- keyOutput = key;
- }
- public function getKey() : String {
- return keyOutput;
- }
- public function getTVar() {
- return node.getOutput(keyOutput);
- }
- public function getType() : Type {
- return node.getOutputType(keyOutput);
- }
- public function isEmpty() {
- return node.getOutputTExpr(keyOutput) == null;
- }
- public function getVar(?type: Type) : TExpr {
- var currentType = getType();
- if (type == null || currentType == type) {
- return node.getOutputTExpr(keyOutput);
- }
- switch(currentType) {
- case TBool:
- var tExprBool = node.getOutputTExpr(keyOutput);
- switch(type) {
- case TVec(size, VBool):
- if (size == 2) {
- return {
- e: TCall({
- e: TGlobal(Vec2),
- p: null,
- t: TFun([
- {
- ret: type,
- args: [
- { name: "u", type : TBool },
- { name: "v", type : TBool }]
- }
- ])
- }, [tExprBool,
- tExprBool]),
- p: null,
- t: type
- };
- } else if (size == 3) {
- return {
- e: TCall({
- e: TGlobal(Vec3),
- p: null,
- t: TFun([
- {
- ret: type,
- args: [
- { name: "x", type : TBool },
- { name: "y", type : TBool },
- { name: "z", type : TBool }]
- }
- ])
- }, [tExprBool,
- tExprBool,
- tExprBool]),
- p: null,
- t: type
- };
- } else {
- return {
- e: TCall({
- e: TGlobal(Vec4),
- p: null,
- t: TFun([
- {
- ret: type,
- args: [
- { name: "r", type : TBool },
- { name: "g", type : TBool },
- { name: "b", type : TBool },
- { name: "a", type : TBool }]
- }
- ])
- }, [tExprBool,
- tExprBool,
- tExprBool,
- tExprBool]),
- p: null,
- t: type
- };
- }
- default:
- };
- case TFloat:
- var tExprFloat = node.getOutputTExpr(keyOutput);
- switch(type) {
- case TVec(size, VFloat):
- if (size == 2) {
- return {
- e: TCall({
- e: TGlobal(Vec2),
- p: null,
- t: TFun([
- {
- ret: type,
- args: [
- { name: "u", type : TFloat },
- { name: "v", type : TFloat }]
- }
- ])
- }, [tExprFloat,
- tExprFloat]),
- p: null,
- t: type
- };
- } else if (size == 3) {
- return {
- e: TCall({
- e: TGlobal(Vec3),
- p: null,
- t: TFun([
- {
- ret: type,
- args: [
- { name: "x", type : TFloat },
- { name: "y", type : TFloat },
- { name: "z", type : TFloat }]
- }
- ])
- }, [tExprFloat,
- tExprFloat,
- tExprFloat]),
- p: null,
- t: type
- };
- } else {
- return {
- e: TCall({
- e: TGlobal(Vec4),
- p: null,
- t: TFun([
- {
- ret: type,
- args: [
- { name: "r", type : TFloat },
- { name: "g", type : TFloat },
- { name: "b", type : TFloat },
- { name: "a", type : TFloat }]
- }
- ])
- }, [tExprFloat,
- tExprFloat,
- tExprFloat,
- {
- e: TConst(CFloat(1.0)),
- p: null,
- t: TFloat
- }]),
- p: null,
- t: type
- };
- }
- default:
- };
- case TVec(sizeCurrentType, VFloat):
- var tExprFloat = node.getOutputTExpr(keyOutput);
- if (sizeCurrentType == 2) {
- switch(type) {
- case TVec(size, VFloat):
- if (size == 3) {
- return {
- e: TCall({
- e: TGlobal(Vec3),
- p: null,
- t: TFun([
- {
- ret: type,
- args: [
- { name: "x", type : TFloat },
- { name: "y", type : TFloat },
- { name: "z", type : TFloat }]
- }
- ])
- }, [{
- e: TSwiz(tExprFloat, [X]),
- p: null,
- t: TVec(1, VFloat)
- },
- {
- e: TSwiz(tExprFloat, [Y]),
- p: null,
- t: TVec(1, VFloat)
- },
- {
- e: TConst(CFloat(0.0)),
- p: null,
- t: TFloat
- }]),
- p: null,
- t: type
- };
- } else if (size == 4) {
- return {
- e: TCall({
- e: TGlobal(Vec4),
- p: null,
- t: TFun([
- {
- ret: type,
- args: [
- { name: "r", type : TFloat },
- { name: "g", type : TFloat },
- { name: "b", type : TFloat },
- { name: "a", type : TFloat }]
- }
- ])
- }, [{
- e: TSwiz(tExprFloat, [X]),
- p: null,
- t: TVec(1, VFloat)
- },
- {
- e: TSwiz(tExprFloat, [Y]),
- p: null,
- t: TVec(1, VFloat)
- },
- {
- e: TConst(CFloat(0.0)),
- p: null,
- t: TFloat
- },
- {
- e: TConst(CFloat(0.0)),
- p: null,
- t: TFloat
- }]),
- p: null,
- t: type
- };
- }
- default:
- };
- } else if (sizeCurrentType == 3) {
- switch(type) {
- case TVec(size, VFloat):
- if (size == 4) {
- return {
- e: TCall({
- e: TGlobal(Vec4),
- p: null,
- t: TFun([
- {
- ret: type,
- args: [
- { name: "r", type : TFloat },
- { name: "g", type : TFloat },
- { name: "b", type : TFloat },
- { name: "a", type : TFloat }]
- }
- ])
- }, [{
- e: TSwiz(tExprFloat, [X]),
- p: null,
- t: TVec(1, VFloat)
- },
- {
- e: TSwiz(tExprFloat, [Y]),
- p: null,
- t: TVec(1, VFloat)
- },
- {
- e: TSwiz(tExprFloat, [Z]),
- p: null,
- t: TVec(1, VFloat)
- },
- {
- e: TConst(CFloat(0.0)),
- p: null,
- t: TFloat
- }]),
- p: null,
- t: type
- };
- }
- default:
- };
- }
- default:
- }
- return node.getOutputTExpr(keyOutput);
- }
- public function getExpr() : Array<TExpr> {
- if (node.outputCompiled.get(keyOutput) != null)
- return [];
- node.outputCompiled.set(keyOutput, true);
- var res = [];
- var nodeBuild = node.build(keyOutput);
- var tvar = getTVar();
- if (tvar != null && tvar.kind == Local && ShaderInput.availableInputs.indexOf(tvar) < 0)
- res.push({ e : TVarDecl(getTVar()), t : getType(), p : null });
- if (nodeBuild != null)
- res.push(nodeBuild);
- return res;
- }
- }
|