private void HandleConfigDefinesChangeOnStartup(IDiffSpread <string> spread) { if (FConfigShader[0] != "" && !configWritten) { DX11ShaderInclude FIncludeHandler = new DX11ShaderInclude(); List <ShaderMacro> sms = new List <ShaderMacro>(); if (FConfigDefines[0] != "") { string[] defines = FConfigDefines[0].Split(",".ToCharArray()); for (int i = 0; i < defines.Length; i++) { try { string[] s = defines[i].Split("=".ToCharArray()); if (s.Length == 2) { ShaderMacro sm = new ShaderMacro(); sm.Name = s[0]; sm.Value = s[1]; sms.Add(sm); } } catch { } } } FShader = DX11Effect.FromString(FConfigShader[0], FIncludeHandler, sms.ToArray()); this.SetShader(FShader, !ShaderCreatedByConfig); ShaderCreatedByConfig = true; } }
void shadernode_WantRecompile(object sender, EventArgs e) { IDX11ShaderNodeWrapper wrp = (IDX11ShaderNodeWrapper)sender; FIncludeHandler.ParentPath = Path.GetDirectoryName(wrp.Source.Filename); string code = File.ReadAllText(wrp.Source.Filename); var shader = DX11Effect.FromString(code, FIncludeHandler,wrp.Macros); wrp.SetShader(shader, false); }
private void HandleConfigShaderChangeOnStartup(IDiffSpread <string> spread) { if (FConfigShader[0] != "" && !configWritten) { DX11ShaderInclude FIncludeHandler = new DX11ShaderInclude(); List <ShaderMacro> sms = new List <ShaderMacro>(); FShader = DX11Effect.FromString(FConfigShader[0], FIncludeHandler, sms.ToArray()); this.SetShader(FShader, true); ShaderCreatedByConfig = true; } }
protected override bool CreateNode(INodeInfo nodeInfo, IInternalPluginHost pluginHost) { if (nodeInfo.Type != NodeType.Dynamic) { return(false); } var project = nodeInfo.UserData as FXProject; /*if (!project.IsLoaded) * project.Load();*/ //compile shader FIncludeHandler.ParentPath = Path.GetDirectoryName(nodeInfo.Filename); string code = File.ReadAllText(nodeInfo.Filename); DX11Effect shader; //create or update plugin if (pluginHost.Plugin == null) { nodeInfo.AutoEvaluate = false; nodeInfo.Arguments = typeof(T).ToString(); var pluginContainer = new PluginContainer(pluginHost, FIORegistry, FParentContainer, FNodeInfoFactory, FDotNetFactory, typeof(T), nodeInfo); pluginHost.Plugin = pluginContainer; FPluginContainers[pluginContainer.PluginBase] = pluginContainer; IDX11ShaderNodeWrapper shaderNode = pluginContainer.PluginBase as IDX11ShaderNodeWrapper; shaderNode.Source = nodeInfo; shaderNode.WantRecompile += new EventHandler(shadernode_WantRecompile); shader = DX11Effect.FromString(code, FIncludeHandler, shaderNode.Macros); shaderNode.SetShader(shader, true, nodeInfo.Filename); if (this.PluginCreated != null) { this.PluginCreated(pluginContainer, pluginHost); } } else { PluginContainer container = pluginHost.Plugin as PluginContainer; var shaderNode = container.PluginBase as IDX11ShaderNodeWrapper; shader = DX11Effect.FromString(code, FIncludeHandler, shaderNode.Macros); shaderNode.SetShader(shader, false, nodeInfo.Filename); } //now the effect is compiled in vvvv and we can access the errors string e = shader.ErrorMessage;//effectHost.GetErrors(); if (string.IsNullOrEmpty(e)) { e = ""; } this.ParseErrors(e, project, shader); //and the input pins string f = "";// effectHost.GetParameterDescription(); if (string.IsNullOrEmpty(f)) { f = ""; } project.ParameterDescription = f; return(true); }
public void Evaluate(int SpreadMax) { this.shaderupdated = false; this.spmax = this.CalculateSpreadMax(); if (FShaderCode.IsChanged || FFileName.IsChanged || FInDefines.IsChanged) { List <ShaderMacro> sms = new List <ShaderMacro>(); for (int i = 0; i < this.FInDefines.SliceCount; i++) { try { string[] s = this.FInDefines[i].Split("=".ToCharArray()); if (s.Length == 2) { ShaderMacro sm = new ShaderMacro(); sm.Name = s[0]; sm.Value = s[1]; sms.Add(sm); } } catch { } } DX11ShaderInclude FIncludeHandler = new DX11ShaderInclude(); FIncludeHandler.ParentPath = Path.GetDirectoryName(FFileName[0]); FShader = DX11Effect.FromString(FShaderCode[0], FIncludeHandler, sms.ToArray()); if (init && !ShaderCreatedByConfig) { this.SetShader(FShader, true); init = false; } else { this.SetShader(FShader, false); } // Write Shadercode & Defines into config -> needed to restore dynamic pins if (HasDynamicPins(FShader)) { configWritten = true; if (FConfigShader[0] != FShaderCode[0]) { FConfigShader[0] = FShaderCode[0]; FConfigDefines[0] = ""; for (int i = 0; i < FInDefines.SliceCount; i++) { if (i != 0) { FConfigDefines[0] += ","; } FConfigDefines[0] += this.FInDefines[i]; } } } else { if (FConfigShader[0] != "") { FConfigShader[0] = ""; FConfigDefines[0] = ""; } } } if (FShader.TechniqueNames != null && this.FInTechnique.IsChanged && FInTechnique.SliceCount > 0) { this.techniqueindex = Array.IndexOf(FShader.TechniqueNames, FInTechnique[0].Name); this.techniquechanged = true; } float *src; //Cache world pointer this.FInWorld.GetMatrixPointer(out this.mworldcount, out src); this.mworld = (Matrix *)src; this.FOutLayer.SliceCount = 1; if (this.FOutLayer[0] == null) { this.FOutLayer[0] = new DX11Resource <DX11Layer>(); } if (this.FInvalidate) { if (this.FShader.IsCompiled) { this.FOutCompiled[0] = true; this.FOutTechniqueValid.SliceCount = this.FShader.TechniqueValids.Length; for (int i = 0; i < this.FShader.TechniqueValids.Length; i++) { this.FOutTechniqueValid[i] = this.FShader.TechniqueValids[i]; } } else { this.FOutCompiled[0] = false; this.FOutTechniqueValid.SliceCount = 0; } this.FInvalidate = false; } if (this.FOutQueryable[0] == null) { this.FOutQueryable[0] = this; } }
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, ""); }