Beispiel #1
0
        /// <summary>
        /// Add a new control by passing a string parameter
        /// params is a string using the following format:<para></para>
        /// 'Control Name', 'Shader parameter name', 'Parameter Type', 'Min Val', 'Max Val', 'Parameter Sub Index'<para></para>
        /// 'Control Name' = is the string displayed for the control name on screen<para></para>
        /// 'Shader parameter name' = is the name of the variable in the shader<para></para>
        /// 'Parameter Type' = can be GPU_VERTEX, GPU_FRAGMENT<para></para>
        /// 'Min Val' = minimum value that parameter can be<para></para>
        /// 'Max Val' = maximum value that parameter can be<para></para>
        /// 'Parameter Sub Index' = index into the the float array of the parameter.  All GPU parameters are assumed to be float[4].<para></para>
        /// </summary>
        public void AddControl(string parameters)
        {
            // params is a string containing using the following format:
            //  "<Control Name>, <Shader parameter name>, <Parameter Type>, <Min Val>, <Max Val>, <Parameter Sub Index>"

            // break up long string into components
            string[] lineParams = parameters.Split(',');

            // if there are not five elements then log error and move on
            if (lineParams.Length != 6)
            {
                LogManager.Instance.Write(
                    "Incorrect number of parameters passed in params string for MaterialControls.AddControl()");
                return;
            }

            try
            {
                var newControl = new ShaderControl();
                newControl.Name         = lineParams[0].Trim();
                newControl.ParamName    = lineParams[1].Trim();
                newControl.Type         = lineParams[2].Trim() == "GPU_VERTEX" ? ShaderType.GpuVertex : ShaderType.GpuFragment;
                newControl.MinVal       = float.Parse(lineParams[3].Trim());
                newControl.MaxVal       = float.Parse(lineParams[4].Trim());
                newControl.ElementIndex = int.Parse(lineParams[5].Trim());
                this.shaderControlsContainer.Add(newControl);
            }
            catch
            {
                LogManager.Instance.Write("Error while parsing control params in MaterialControls.AddControl()");
            }
        }
		/// <summary>
		/// Add a new control by passing a string parameter
		/// params is a string using the following format:<para></para>
		/// 'Control Name', 'Shader parameter name', 'Parameter Type', 'Min Val', 'Max Val', 'Parameter Sub Index'<para></para>
		/// 'Control Name' = is the string displayed for the control name on screen<para></para>
		/// 'Shader parameter name' = is the name of the variable in the shader<para></para>
		/// 'Parameter Type' = can be GPU_VERTEX, GPU_FRAGMENT<para></para>
		/// 'Min Val' = minimum value that parameter can be<para></para>
		/// 'Max Val' = maximum value that parameter can be<para></para>
		/// 'Parameter Sub Index' = index into the the float array of the parameter.  All GPU parameters are assumed to be float[4].<para></para>
		/// </summary>
		public void AddControl( string parameters )
		{
			// params is a string containing using the following format:
			//  "<Control Name>, <Shader parameter name>, <Parameter Type>, <Min Val>, <Max Val>, <Parameter Sub Index>"

			// break up long string into components
			string[] lineParams = parameters.Split( ',' );

			// if there are not five elements then log error and move on
			if ( lineParams.Length != 6 )
			{
				LogManager.Instance.Write(
					"Incorrect number of parameters passed in params string for MaterialControls.AddControl()" );
				return;
			}

			try
			{
				var newControl = new ShaderControl();
				newControl.Name = lineParams[ 0 ].Trim();
				newControl.ParamName = lineParams[ 1 ].Trim();
				newControl.Type = lineParams[ 2 ].Trim() == "GPU_VERTEX" ? ShaderType.GpuVertex : ShaderType.GpuFragment;
				newControl.MinVal = float.Parse( lineParams[ 3 ].Trim() );
				newControl.MaxVal = float.Parse( lineParams[ 4 ].Trim() );
				newControl.ElementIndex = int.Parse( lineParams[ 5 ].Trim() );
				this.shaderControlsContainer.Add( newControl );
			}
			catch
			{
				LogManager.Instance.Write( "Error while parsing control params in MaterialControls.AddControl()" );
			}
		}
Beispiel #3
0
        private void shaderControlSlider_SliderMoved(object sender, Slider slider)
        {
            int sliderIndex = -1;

            for (int i = 0; i < ControlsPerPage; i++)
            {
                if (this.shaderControls[i] == slider)
                {
                    sliderIndex = i;
                    break;
                }
            }

            Utilities.Contract.Requires(sliderIndex != -1);
            int           index           = this.currentPage * ControlsPerPage + sliderIndex;
            ShaderControl activeShaderDef = this.materialControlsContainer[this.currentMaterial].GetShaderControl(index);

            float val = slider.Value;

            if (this.activePass != null)
            {
                switch (activeShaderDef.Type)
                {
                case ShaderType.GpuVertex:
                case ShaderType.GpuFragment:
                {
                    GpuProgramParameters activeParameters = (activeShaderDef.Type == ShaderType.GpuVertex)
                                                                                                ? this.activeVertexParameters
                                                                                                : this.activeFragmentParameters;

                    if (activeParameters != null)
                    {
                        activeParameters.WriteRawConstant(activeShaderDef.PhysicalIndex + activeShaderDef.ElementIndex, val);
                    }
                }
                break;

                case ShaderType.MatSpecular:
                {
                    //// get the specular values from the material pass
                    ColorEx oldSpec = this.activePass.Specular;
                    switch (activeShaderDef.ElementIndex)
                    {
                    case 0:
                        oldSpec.r = val;
                        break;

                    case 1:
                        oldSpec.g = val;
                        break;

                    case 2:
                        oldSpec.b = val;
                        break;

                    case 3:
                        oldSpec.a = val;
                        break;
                    }
                    this.activePass.Specular = oldSpec;
                }
                break;

                case ShaderType.MatDiffuse:
                {
                    //// get the specular values from the material pass
                    ColorEx oldSpec = this.activePass.Diffuse;
                    switch (activeShaderDef.ElementIndex)
                    {
                    case 0:
                        oldSpec.r = val;
                        break;

                    case 1:
                        oldSpec.g = val;
                        break;

                    case 2:
                        oldSpec.b = val;
                        break;

                    case 3:
                        oldSpec.a = val;
                        break;
                    }
                    this.activePass.Diffuse = oldSpec;
                }
                break;

                case ShaderType.MatAmbient:
                {
                    //// get the specular values from the material pass
                    ColorEx oldSpec = this.activePass.Ambient;
                    switch (activeShaderDef.ElementIndex)
                    {
                    case 0:
                        oldSpec.r = val;
                        break;

                    case 1:
                        oldSpec.g = val;
                        break;

                    case 2:
                        oldSpec.b = val;
                        break;

                    case 3:
                        oldSpec.a = val;
                        break;
                    }
                    this.activePass.Ambient = oldSpec;
                }
                break;

                case ShaderType.MatShininess:
                {
                    //// get the specular values from the material pass
                    this.activePass.Shininess = val;
                }
                break;
                }
            }
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pageNum"></param>
        protected void ChangePage(int pageNum)
        {
            if (this.materialControlsContainer.Count == 0)
            {
                return;
            }

            this.currentPage = (pageNum == -1) ? (this.currentPage + 1) % this.numPages : pageNum;

            string pageText = string.Format("Parameters {0} / {1}", this.currentPage + 1, this.numPages);

            ((Button)TrayManager.GetWidget("PageButtonControl")).Caption = pageText;

            if (this.activeMaterial != null && this.activeMaterial.SupportedTechniques.Count > 0)
            {
                Technique currentTechnique = this.activeMaterial.SupportedTechniques[0];
                if (currentTechnique != null)
                {
                    this.activePass = currentTechnique.GetPass(0);
                    if (this.activePass != null)
                    {
                        if (this.activePass.HasFragmentProgram)
                        {
                            this.activeFragmentProgram    = this.activePass.FragmentProgram;
                            this.activeFragmentParameters = this.activePass.FragmentProgramParameters;
                        }
                        if (this.activePass.HasVertexProgram)
                        {
                            this.activeVertexProgram    = this.activePass.VertexProgram;
                            this.activeVertexParameters = this.activePass.VertexProgramParameters;
                        }

                        int activeControlCount = this.materialControlsContainer[this.currentMaterial].ShaderControlsCount;

                        int startControlIndex = this.currentPage * ControlsPerPage;
                        int numControls       = activeControlCount - startControlIndex;
                        if (numControls <= 0)
                        {
                            this.currentPage  = 0;
                            startControlIndex = 0;
                            numControls       = activeControlCount;
                        }

                        for (int i = 0; i < ControlsPerPage; i++)
                        {
                            Slider shaderControlSlider = this.shaderControls[i];
                            if (i < numControls)
                            {
                                shaderControlSlider.Show();

                                int           controlIndex    = startControlIndex + i;
                                ShaderControl activeShaderDef =
                                    this.materialControlsContainer[this.currentMaterial].GetShaderControl(controlIndex);
                                shaderControlSlider.SetRange(activeShaderDef.MinVal, activeShaderDef.MaxVal, 50, false);
                                shaderControlSlider.Caption      = activeShaderDef.Name;
                                shaderControlSlider.SliderMoved += new SliderMovedHandler(shaderControlSlider_SliderMoved);
                                float uniformVal = 0.0f;
                                switch (activeShaderDef.Type)
                                {
                                case ShaderType.GpuVertex:
                                case ShaderType.GpuFragment:
                                {
                                    GpuProgramParameters activeParameters = (activeShaderDef.Type == ShaderType.GpuVertex)
                                                                                                                                ? this.activeVertexParameters
                                                                                                                                : this.activeFragmentParameters;

                                    if (activeParameters != null)
                                    {
                                        throw new NotImplementedException("Fix this");
                                        //int idx = activeParameters.GetParamIndex( activeShaderDef.ParamName );
                                        //activeShaderDef.PhysicalIndex = idx;

                                        //uniformVal = activeParameters.GetNamedFloatConstant( activeShaderDef.ParamName ).val[ activeShaderDef.ElementIndex ];
                                    }
                                }
                                break;

                                case ShaderType.MatSpecular:
                                {
                                    // get the specular values from the material pass
                                    ColorEx oldSpec = this.activePass.Specular;
                                    int     x       = activeShaderDef.ElementIndex;
                                    uniformVal = x == 0 ? oldSpec.r : x == 1 ? oldSpec.g : x == 2 ? oldSpec.b : x == 3 ? oldSpec.a : 0;
                                }
                                break;

                                case ShaderType.MatDiffuse:
                                {
                                    // get the specular values from the material pass
                                    ColorEx oldSpec = this.activePass.Diffuse;
                                    int     x       = activeShaderDef.ElementIndex;
                                    uniformVal = x == 0 ? oldSpec.r : x == 1 ? oldSpec.g : x == 2 ? oldSpec.b : x == 3 ? oldSpec.a : 0;
                                }
                                break;

                                case ShaderType.MatAmbient:
                                {
                                    // get the specular values from the material pass
                                    ColorEx oldSpec = this.activePass.Ambient;
                                    int     x       = activeShaderDef.ElementIndex;
                                    uniformVal = x == 0 ? oldSpec.r : x == 1 ? oldSpec.g : x == 2 ? oldSpec.b : x == 3 ? oldSpec.a : 0;
                                }
                                break;

                                case ShaderType.MatShininess:
                                {
                                    // get the specular values from the material pass
                                    uniformVal = this.activePass.Shininess;
                                }
                                break;
                                }
                                shaderControlSlider.Value = uniformVal;
                            }
                        }
                    }
                }
            }
        }