static ShaderTraverseResult Traverse(this IGlobalVarNode node, ShaderTraverseResult result = null) { if (result.GlobalVars.ContainsKey(node)) { return(result); } var globalVar = node.GetGlobalVar(result.GlobalVars.Values.Select(gv => gv.Identifier).ToArray()); result.GlobalVars[node] = globalVar; result.Pins[globalVar.Identifier] = new ShaderGraphPin(node); return(result); }
public static ShaderTraverseResult Traverse(this IShaderNode node, ShaderTraverseResult result = null) { if (result == null) { result = new ShaderTraverseResult(); } if (node != null) { return(Traverse((dynamic)node, result)); } return(result); }
static ShaderTraverseResult Traverse(this IFunctionNode node, ShaderTraverseResult result = null) { if (result.LocalDeclarations.ContainsKey(node)) { return(result); } foreach (var arg in node.NodeArguments) { arg.Traverse(result); } result.FunctionDeclarations[node.Name] = node.Code; var args = node.NodeArguments.Select(a => result.GetPhrase(a)); result.LocalDeclarations[node] = node.CreateShaderCallAssignment($"var{result.LocalDeclarations.Count}", args); return(result); }
public static ShaderTraverseResult Traverse(this IMadeUpShaderNode node, ShaderTraverseResult result = null) => result;
public void RecalcShader(bool isNew) { var declarations = ""; var pscode = @" float4 col = float4(1, 1, 1, 1); return col;"; if (FShaderProvider.SliceCount > 0 && FShaderProvider[0] != null) { this.traverseResult = FShaderProvider[0].Traverse(); declarations = string.Join(@" ", traverseResult.GlobalVars.Select(gv => gv.Value.ToString()).Concat(traverseResult.FunctionDeclarations.Values)); pscode = string.Join(@" ", traverseResult.LocalDeclarations.Values) + $@" return {traverseResult.LocalDeclarations[FShaderProvider[0]].Identifier};"; ; } var effectText = declarations + @" SamplerState linearSampler: IMMUTABLE { Filter = MIN_MAG_MIP_LINEAR; AddressU = Clamp; AddressV = Clamp; }; cbuffer cbPerDraw : register(b0) { float4x4 tVP : LAYERVIEWPROJECTION; }; cbuffer cbPerObj : register(b1) { float4x4 tW : WORLD; }; struct VS_IN { float4 PosO : POSITION; float4 TexCd : TEXCOORD0; }; struct vs2ps { float4 PosWVP: SV_Position; float2 TexCd: TEXCOORD0; }; vs2ps VS(VS_IN input) { vs2ps output; output.PosWVP = mul(input.PosO, mul(tW, tVP)); output.TexCd = input.TexCd.xy; return output; } float4 PS(vs2ps In): SV_Target { " + pscode + @" } technique10 Patched { pass P0 { SetVertexShader(CompileShader(vs_4_0, VS())); SetPixelShader(CompileShader(ps_4_0, PS())); } }"; FCode.SliceCount = 1; FCode[0] = effectText; SetShader(DX11Effect.FromString(effectText), isNew, ""); }