Пример #1
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;
                }
            }
        }