An effect component - a function and information about return values
Inheritance: IComparable
Exemple #1
0
        private void addVertexShaderButton_Click(object sender, EventArgs e)
        {
            EffectComponent component = new EffectComponent();
            component.Name = "NewVertexShader";
            component.IsInline = false;

            HlslSemantic inputSemantic = Semantics.Find("POSITION", true, true);
            inputSemantic.ResourceNumber = 0;
            component.Parameters.Add(new EffectParameterDefinition(
                "Position",
                inputSemantic.Type,
                inputSemantic));
            HlslSemantic outputSemantic = Semantics.Find("POSITION", true, false);
            outputSemantic.ResourceNumber = 0;
            component.ReturnType.Add(new EffectParameterDefinition(
                "Position",
                outputSemantic.Type,
                outputSemantic));

            mEffectDefinition.VertexShaders.Add(component);

            effectEdit_vertexShaderListChanged(sender, e);

            vertexShadersList.SelectedItem = component;

            if (mEffectDefinition.VertexShaders.Count > 0) vertexShaderEditor.Enabled = true;
        }
Exemple #2
0
        private void addPixelShaderButton_Click(object sender, EventArgs e)
        {
            EffectComponent component = new EffectComponent();
            component.Name = "NewPixelShader";
            component.IsInline = false;

            HlslSemantic outputSemantic = Semantics.Find("COLOR", true, false);
            outputSemantic.ResourceNumber = 0;
            component.ReturnType.Add(new EffectParameterDefinition(
                "Color",
                outputSemantic.Type,
                outputSemantic));

            mEffectDefinition.PixelShaders.Add(component);

            effectEdit_pixelShaderListChanged(sender, e);

            pixelShadersList.SelectedItem = component;

            if (mEffectDefinition.PixelShaders.Count > 0) pixelShaderEditor.Enabled = true;
        }
Exemple #3
0
 private void newComponentToolStripMenuItem_Click(object sender, EventArgs e)
 {
     EffectComponent component = new EffectComponent();
     component.Name = "NewComponent";
     componentEditor.SetComponent(component);
 }
        /// <summary>
        /// Sets a new component on this editor - and updates parameters
        /// </summary>
        /// <param name="component">The component to set</param>
        #endregion
        public void SetComponent(EffectComponent component)
        {
            if (Component != component)
            {
                Component = component;

                componentNameBox.Text = Component.Name;
                vertexShaderCheckbox.Checked = Component.AvailableToVertexShader;
                pixelShaderCheckbox.Checked = Component.AvailableToPixelShader;
                vertexShaderProfileSelector.Text = Component.MinimumVertexShaderProfile;
                pixelShaderProfileSelector.Text = Component.MinimumPixelShaderProfile;
                componentParameterInputs.Parameters = Component.Parameters;
                componentParameterOutputs.Parameters = Component.ReturnType;
                componentFunctionCode.Text = Component.Code;

                if (!AllowShaderSelection)
                {
                    UpdateShaderProfiles();
                }

                UpdateComponent(false);
            }
        }
        public ComponentEditor()
        {
            InitializeComponent();

            // Populate Vertex and Pixel Shader profiles
            this.SuspendLayout();
            mShaderProfileNames = Enum.GetNames(typeof(Microsoft.Xna.Framework.Graphics.ShaderProfile));
            vertexShaderProfileSelector.Items.Clear();
            pixelShaderProfileSelector.Items.Clear();
            for (int i = 0; i < mShaderProfileNames.Length; i++)
            {
                if (mShaderProfileNames[i].Contains("VS"))
                {
                    vertexShaderProfileSelector.Items.Add(mShaderProfileNames[i]);
                }
                if (mShaderProfileNames[i].Contains("PS"))
                {
                    pixelShaderProfileSelector.Items.Add(mShaderProfileNames[i]);
                }
            }
            this.ResumeLayout(true);

            // Create a new component
            EffectComponent newComponent = new EffectComponent();
            newComponent.Name = "NewComponent";

            SetComponent(newComponent);
        }
        public string GetEffectCode()
        {
            String effectCode = String.Empty;

            #region Parameters

            // Output effect parameters
            foreach (EffectParameterDefinition param in Parameters)
            {
                effectCode += param.ToString() + @";" + Environment.NewLine;

                if (param.Type.Type == HlslType.Texture)
                {
                    // output a sampler as well
                    effectCode += @"sampler " + param.Name + @"Sampler = sampler_state" + Environment.NewLine;
                    effectCode += @"{" + Environment.NewLine;
                    effectCode += @"    Texture = (" + param.Name + @");" + Environment.NewLine;
                    effectCode += @"};" + Environment.NewLine;
                }
            }

            effectCode += Environment.NewLine;

            #endregion

            #region Components / shaders

            // Load components
            EffectComponent[] components = new EffectComponent[Components.Count];
            for (int i = 0; i < Components.Count; i++)
            {
                components[i] = EffectComponent.FromFile(Components[i]);
            }

            // Structs
            for (int i = 0; i < components.Length; i++)
            {
                effectCode += components[i].OutputStruct() + Environment.NewLine + Environment.NewLine;
            }

            for (int i = 0; i < VertexShaders.Count; i++)
            {
                effectCode += VertexShaders[i].OutputStruct() + Environment.NewLine + Environment.NewLine;
            }

            for (int i = 0; i < PixelShaders.Count; i++)
            {
                effectCode += PixelShaders[i].OutputStruct() + Environment.NewLine + Environment.NewLine;
            }

            // Functions
            for (int i = 0; i < components.Length; i++)
            {
                effectCode += components[i].FunctionString() + Environment.NewLine + Environment.NewLine;
            }

            for (int i = 0; i < VertexShaders.Count; i++)
            {
                effectCode += VertexShaders[i].FunctionString() + Environment.NewLine + Environment.NewLine;
            }

            for (int i = 0; i < PixelShaders.Count; i++)
            {
                effectCode += PixelShaders[i].FunctionString() + Environment.NewLine + Environment.NewLine;
            }

            #endregion

            #region Techniques

            foreach (EffectTechniqueDefinition technique in Techniques)
            {
                effectCode += technique.GetTechniqueString() + Environment.NewLine;
            }

            #endregion

            return(effectCode);
        }
        public string GetEffectCode()
        {
            String effectCode = String.Empty;

            #region Parameters

            // Output effect parameters
            foreach (EffectParameterDefinition param in Parameters)
            {
                effectCode += param.ToString() + @";" + Environment.NewLine;

                if (param.Type.Type == HlslType.Texture)
                {
                    // output a sampler as well
                    effectCode += @"sampler " + param.Name + @"Sampler = sampler_state" + Environment.NewLine;
                    effectCode += @"{" + Environment.NewLine;
                    effectCode += @"    Texture = (" + param.Name + @");" + Environment.NewLine;
                    effectCode += @"};" + Environment.NewLine;
                }
            }

            effectCode += Environment.NewLine;

            #endregion

            #region Components / shaders

            // Load components
            EffectComponent[] components = new EffectComponent[Components.Count];
            for (int i = 0; i < Components.Count; i++)
            {
                components[i] = EffectComponent.FromFile(Components[i]);
            }

            // Structs
            for (int i = 0; i < components.Length; i++)
            {
                effectCode += components[i].OutputStruct() + Environment.NewLine + Environment.NewLine;
            }

            for (int i = 0; i < VertexShaders.Count; i++)
            {
                effectCode += VertexShaders[i].OutputStruct() + Environment.NewLine + Environment.NewLine;
            }

            for (int i = 0; i < PixelShaders.Count; i++)
            {
                effectCode += PixelShaders[i].OutputStruct() + Environment.NewLine + Environment.NewLine;
            }

            // Functions
            for (int i = 0; i < components.Length; i++)
            {
                effectCode += components[i].FunctionString() + Environment.NewLine + Environment.NewLine;
            }

            for (int i = 0; i < VertexShaders.Count; i++)
            {
                effectCode += VertexShaders[i].FunctionString() + Environment.NewLine + Environment.NewLine;
            }

            for (int i = 0; i < PixelShaders.Count; i++)
            {
                effectCode += PixelShaders[i].FunctionString() + Environment.NewLine + Environment.NewLine;
            }

            #endregion

            #region Techniques

            foreach (EffectTechniqueDefinition technique in Techniques)
            {
                effectCode += technique.GetTechniqueString() + Environment.NewLine;
            }

            #endregion

            return effectCode;
        }