protected void ChangePage( int pageNum )
{
if ( materialControlsContainer.Count == 0 )
return;
currentPage = ( pageNum == -1 ) ? ( currentPage + 1 ) % numPages : pageNum;
string pageText = string.Format( "Parameters {0} / {1}", currentPage + 1, numPages );
( (Button)TrayManager.GetWidget( "PageButtonControl" ) ).Caption = pageText;
if ( activeMaterial != null && activeMaterial.SupportedTechniques.Count > 0 )
{
Technique currentTechnique = activeMaterial.SupportedTechniques[ 0 ];
if ( currentTechnique != null )
{
activePass = currentTechnique.GetPass( 0 );
if ( activePass != null )
{
if ( activePass.HasFragmentProgram )
{
activeFragmentProgram = activePass.FragmentProgram;
activeFragmentParameters = activePass.FragmentProgramParameters;
}
if ( activePass.HasVertexProgram )
{
activeVertexProgram = activePass.VertexProgram;
activeVertexParameters = activePass.VertexProgramParameters;
}
int activeControlCount = materialControlsContainer[ currentMaterial ].ShaderControlsCount;
int startControlIndex = currentPage * ControlsPerPage;
int numControls = activeControlCount - startControlIndex;
if ( numControls <= 0 )
{
currentPage = 0;
startControlIndex = 0;
numControls = activeControlCount;
}
for ( int i = 0; i < ControlsPerPage; i++ )
{
Slider shaderControlSlider = shaderControls[ i ];
if ( i < numControls )
{
shaderControlSlider.Show();
int controlIndex = startControlIndex + i;
ShaderControl activeShaderDef = materialControlsContainer[ 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 ) ?
activeVertexParameters : activeFragmentParameters;
if ( activeParameters != null )
{
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 = 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 = 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 = 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 = activePass.Shininess;
}
break;
}
shaderControlSlider.Value = uniformVal;
}
}
}
}
}
}