Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        protected override bool CreateNode(INodeInfo nodeInfo, IInternalPluginHost pluginHost)
        {
            if (nodeInfo.Type != NodeType.Plugin)
            {
                return(false);
            }

            //get the code of the FXProject associated with the nodeinfos filename
            //effectHost.SetEffect(nodeInfo.Filename, project.Code);

            //compile shader

            var shader = DX11Effect.FromByteCode(nodeInfo.Filename);

            //create or update plugin
            if (pluginHost.Plugin == null)
            {
                //IPluginBase plug = this.FDotNetFactory.CreatePluginCustom(nodeInfo, pluginHost as IPluginHost2, typeof(DX11ShaderNode));
                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.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;
                shaderNode.SetShader(shader, false, nodeInfo.Filename);
            }


            return(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);
        }