This utility class is used to hold the information used to generate the matrices and other information required to automatically populate GpuProgramParameters.
This class exercises a lazy-update scheme in order to avoid having to update all the information a GpuProgramParameters class could possibly want all the time. It relies on the SceneManager to update it when the base data has changed, and will calculate concatenated matrices etc only when required, passing back precalculated matrices when they are requested more than once when the underlying information has not altered.
Inheritance: DisposableObject
Exemple #1
0
			UpdateGpuProgramsParams( IRenderable rend, Pass pass, AutoParamDataSource source,
			                         Core.Collections.LightList lightList )
		{
			if ( this.reflectionPowerChanged )
			{
				GpuProgramParameters fsParams = pass.FragmentProgramParameters;

				this.reflectionPower.SetGpuParameter( this.reflectionPowerValue );
				this.reflectionPowerChanged = false;
			}
		}
Exemple #2
0
		public override void UpdateGpuProgramsParams( IRenderable rend, Pass pass, AutoParamDataSource source,
		                                              Core.Collections.LightList lightList )
		{
			if ( this.fogMode == FogMode.None )
			{
				return;
			}

			FogMode fMode;
			ColorEx newFogColor;
			Real newFogStart, newFogEnd, newFogDensity;

			if ( this.passOverrideParams )
			{
				fMode = pass.FogMode;
				newFogColor = pass.FogColor;
				newFogStart = pass.FogStart;
				newFogEnd = pass.FogEnd;
				newFogDensity = pass.FogDensity;
			}
			else
			{
				var sceneMgr = ShaderGenerator.Instance.ActiveSceneManager;

				fMode = sceneMgr.FogMode;
				newFogColor = sceneMgr.FogColor;
				newFogStart = sceneMgr.FogStart;
				newFogEnd = sceneMgr.FogEnd;
				newFogDensity = sceneMgr.FogDensity;
			}

			SetFogProperties( fMode, newFogColor, newFogStart, newFogEnd, newFogDensity );

			//Per pixel fog
			if ( this.calcMode == CalcMode.PerPixel )
			{
				this.fogParams.SetGpuParameter( this.fogParamsValue );
			}

				//per vertex fog
			else
			{
				this.fogParams.SetGpuParameter( this.fogParamsValue );
			}

			this.fogColor.SetGpuParameter( this.fogColorValue );
		}
Exemple #3
0
		public override void UpdateGpuProgramsParams( IRenderable rend, Pass pass, AutoParamDataSource source,
		                                              Core.Collections.LightList lightList )
		{
			for ( int i = 0; i < this.textureUnitParamsList.Count; i++ )
			{
				TextureUnitParams curParams = this.textureUnitParamsList[ i ];

				if ( curParams.TextureProjector != null && curParams.TextureViewProjImageMatrix != null )
				{
					Matrix4 matTexViewProjImage;

					matTexViewProjImage = Matrix4.ClipSpace2DToImageSpace*
					                      curParams.TextureProjector.ProjectionMatrixRSDepth*
					                      curParams.TextureProjector.ViewMatrix;

					curParams.TextureViewProjImageMatrix.SetGpuParameter( matTexViewProjImage );
				}
			}
		}
Exemple #4
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="disposeManagedResources"></param>
		protected override void dispose( bool disposeManagedResources )
		{
			if ( !this.IsDisposed )
			{
				if ( disposeManagedResources )
				{
					this.ClearScene();
					this.RemoveAllCameras();

					if ( op != null )
					{
						if ( !op.IsDisposed )
							op.Dispose();

						op = null;
					}

					if ( this.autoParamDataSource != null )
					{
						if ( !this.autoParamDataSource.IsDisposed )
							this.autoParamDataSource.Dispose();

						this.autoParamDataSource = null;
					}

					if ( this.rootSceneNode != null )
					{
						if ( !this.rootSceneNode.IsDisposed )
							this.rootSceneNode.Dispose();

						this.rootSceneNode = null;
					}
				}
			}

			base.dispose( disposeManagedResources );
		}
		public void UpdateAutoParams( AutoParamDataSource source, GpuParamVariability mask )
		{
			// abort early if no autos
			if ( !HasAutoConstantType )
			{
				return;
			}

			if ( ( mask & this._combinedVariability ) == 0 )
			{
				return;
			}

			this.activePassIterationIndex = int.MaxValue;

			Matrix3 m3;
			Vector4 vec4;
			Vector3 vec3;

			// loop through and update all constants based on their type
			foreach ( var entry in this.autoConstants )
			{
				// Only update needed slots
				if ( ( entry.Variability & mask ) == 0 )
				{
					continue;
				}

				switch ( entry.Type )
				{
					case AutoConstantType.ViewMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.ViewMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseViewMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseViewMatrix, entry.ElementCount );
						break;

					case AutoConstantType.TransposeViewMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.TransposeViewMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseTransposeViewMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseTransposeViewMatrix, entry.ElementCount );
						break;

					case AutoConstantType.ProjectionMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.ProjectionMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseProjectionMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseProjectionMatrix, entry.ElementCount );
						break;

					case AutoConstantType.TransposeProjectionMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.TransposeProjectionMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseTransposeProjectionMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseTransposeProjectionMatrix, entry.ElementCount );
						break;

					case AutoConstantType.ViewProjMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.ViewProjectionMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseViewProjMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseViewProjMatrix, entry.ElementCount );
						break;

					case AutoConstantType.TransposeViewProjMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.TransposeViewProjMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseTransposeViewProjMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseTransposeViewProjMatrix, entry.ElementCount );
						break;

					case AutoConstantType.RenderTargetFlipping:
						WriteRawConstant( entry.PhysicalIndex, source.CurrentRenderTarget.RequiresTextureFlipping ? -1.0f : 1.0f );
						break;

					case AutoConstantType.VertexWinding:
					{
						var rsys = Root.Instance.RenderSystem;
						WriteRawConstant( entry.PhysicalIndex, rsys.InvertVertexWinding ? -1.0f : 1.0f );
						break;
					}

						// NB ambient light still here because it's not related to a specific light
					case AutoConstantType.AmbientLightColor:
						WriteRawConstant( entry.PhysicalIndex, source.AmbientLight, entry.ElementCount );
						break;

					case AutoConstantType.DerivedAmbientLightColor:
						WriteRawConstant( entry.PhysicalIndex, source.DerivedAmbient, entry.ElementCount );
						break;

					case AutoConstantType.DerivedSceneColor:
						WriteRawConstant( entry.PhysicalIndex, source.DerivedSceneColor, entry.ElementCount );
						break;

					case AutoConstantType.FogColor:
						WriteRawConstant( entry.PhysicalIndex, source.FogColor );
						break;

					case AutoConstantType.FogParams:
						WriteRawConstant( entry.PhysicalIndex, source.FogParams, entry.ElementCount );
						break;

					case AutoConstantType.SurfaceAmbientColor:
						WriteRawConstant( entry.PhysicalIndex, source.SurfaceAmbient, entry.ElementCount );
						break;

					case AutoConstantType.SurfaceDiffuseColor:
						WriteRawConstant( entry.PhysicalIndex, source.SurfaceDiffuse, entry.ElementCount );
						break;

					case AutoConstantType.SurfaceSpecularColor:
						WriteRawConstant( entry.PhysicalIndex, source.SurfaceSpecular, entry.ElementCount );
						break;

					case AutoConstantType.SurfaceEmissiveColor:
						WriteRawConstant( entry.PhysicalIndex, source.SurfaceEmissive, entry.ElementCount );
						break;

					case AutoConstantType.SurfaceShininess:
						WriteRawConstant( entry.PhysicalIndex, source.SurfaceShininess );
						break;

					case AutoConstantType.CameraPosition:
						WriteRawConstant( entry.PhysicalIndex, source.CameraPosition, entry.ElementCount );
						break;

					case AutoConstantType.Time:
						WriteRawConstant( entry.PhysicalIndex, source.Time*entry.FData );
						break;

					case AutoConstantType.Time_0_X:
						WriteRawConstant( entry.PhysicalIndex, source.GetTime_0_X( entry.FData ) );
						break;

					case AutoConstantType.CosTime_0_X:
						WriteRawConstant( entry.PhysicalIndex, source.GetCosTime_0_X( entry.FData ) );
						break;

					case AutoConstantType.SinTime_0_X:
						WriteRawConstant( entry.PhysicalIndex, source.GetSinTime_0_X( entry.FData ) );
						break;

					case AutoConstantType.TanTime_0_X:
						WriteRawConstant( entry.PhysicalIndex, source.GetTanTime_0_X( entry.FData ) );
						break;

					case AutoConstantType.Time_0_X_Packed:
						WriteRawConstant( entry.PhysicalIndex, source.GetTime_0_X_Packed( entry.FData ), entry.ElementCount );
						break;

					case AutoConstantType.Time_0_1:
						WriteRawConstant( entry.PhysicalIndex, source.GetTime_0_1( entry.FData ) );
						break;

					case AutoConstantType.CosTime_0_1:
						WriteRawConstant( entry.PhysicalIndex, source.GetCosTime_0_1( entry.FData ) );
						break;

					case AutoConstantType.SinTime_0_1:
						WriteRawConstant( entry.PhysicalIndex, source.GetSinTime_0_1( entry.FData ) );
						break;

					case AutoConstantType.TanTime_0_1:
						WriteRawConstant( entry.PhysicalIndex, source.GetTanTime_0_1( entry.FData ) );
						break;

					case AutoConstantType.Time_0_1_Packed:
						WriteRawConstant( entry.PhysicalIndex, source.GetTime_0_1_Packed( entry.FData ), entry.ElementCount );
						break;

					case AutoConstantType.Time_0_2PI:
						WriteRawConstant( entry.PhysicalIndex, source.GetTime_0_2Pi( entry.FData ) );
						break;

					case AutoConstantType.CosTime_0_2PI:
						WriteRawConstant( entry.PhysicalIndex, source.GetCosTime_0_2Pi( entry.FData ) );
						break;

					case AutoConstantType.SinTime_0_2PI:
						WriteRawConstant( entry.PhysicalIndex, source.GetSinTime_0_2Pi( entry.FData ) );
						break;

					case AutoConstantType.TanTime_0_2PI:
						WriteRawConstant( entry.PhysicalIndex, source.GetTanTime_0_2Pi( entry.FData ) );
						break;

					case AutoConstantType.Time_0_2PI_Packed:
						WriteRawConstant( entry.PhysicalIndex, source.GetTime_0_2Pi_Packed( entry.FData ), entry.ElementCount );
						break;

					case AutoConstantType.FrameTime:
						WriteRawConstant( entry.PhysicalIndex, source.FrameTime*entry.FData );
						break;

					case AutoConstantType.FPS:
						WriteRawConstant( entry.PhysicalIndex, source.FPS );
						break;

					case AutoConstantType.ViewportWidth:
						WriteRawConstant( entry.PhysicalIndex, source.ViewportWidth );
						break;

					case AutoConstantType.ViewportHeight:
						WriteRawConstant( entry.PhysicalIndex, source.ViewportHeight );
						break;

					case AutoConstantType.InverseViewportWidth:
						WriteRawConstant( entry.PhysicalIndex, source.InverseViewportWidth );
						break;

					case AutoConstantType.InverseViewportHeight:
						WriteRawConstant( entry.PhysicalIndex, source.InverseViewportHeight );
						break;

					case AutoConstantType.ViewportSize:
					{
						WriteRawConstant( entry.PhysicalIndex,
						                  new Vector4( source.ViewportWidth, source.ViewportHeight, source.InverseViewportWidth,
						                               source.InverseViewportHeight ), entry.ElementCount );
					}
						break;

					case AutoConstantType.TexelOffsets:
					{
						var rsys = Root.Instance.RenderSystem;
						WriteRawConstant( entry.PhysicalIndex,
						                  new Vector4( rsys.HorizontalTexelOffset, rsys.VerticalTexelOffset,
						                               rsys.HorizontalTexelOffset*source.InverseViewportWidth,
						                               rsys.VerticalTexelOffset*source.InverseViewportHeight ), entry.ElementCount );
					}
						break;

					case AutoConstantType.TextureSize:
						WriteRawConstant( entry.PhysicalIndex, source.GetTextureSize( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.InverseTextureSize:
						WriteRawConstant( entry.PhysicalIndex, source.GetInverseTextureSize( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.PackedTextureSize:
						WriteRawConstant( entry.PhysicalIndex, source.GetPackedTextureSize( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.SceneDepthRange:
						WriteRawConstant( entry.PhysicalIndex, source.SceneDepthRange, entry.ElementCount );
						break;

					case AutoConstantType.ViewDirection:
						WriteRawConstant( entry.PhysicalIndex, source.ViewDirection );
						break;

					case AutoConstantType.ViewSideVector:
						WriteRawConstant( entry.PhysicalIndex, source.ViewSideVector );
						break;

					case AutoConstantType.ViewUpVector:
						WriteRawConstant( entry.PhysicalIndex, source.ViewUpVector );
						break;

					case AutoConstantType.FOV:
						WriteRawConstant( entry.PhysicalIndex, source.FOV );
						break;

					case AutoConstantType.NearClipDistance:
						WriteRawConstant( entry.PhysicalIndex, source.NearClipDistance );
						break;

					case AutoConstantType.FarClipDistance:
						WriteRawConstant( entry.PhysicalIndex, source.FarClipDistance );
						break;

					case AutoConstantType.PassNumber:
						WriteRawConstant( entry.PhysicalIndex, (float)source.PassNumber );
						break;

					case AutoConstantType.PassIterationNumber:
					{
						// this is actually just an initial set-up, it's bound separately, so still global
						WriteRawConstant( entry.PhysicalIndex, 0.0f );
						this.activePassIterationIndex = entry.PhysicalIndex;
					}
						break;

					case AutoConstantType.TextureMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.GetTextureTransformMatrix( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.LODCameraPosition:
						WriteRawConstant( entry.PhysicalIndex, source.LodCameraPosition, entry.ElementCount );
						break;

					case AutoConstantType.TextureWorldViewProjMatrix:
						// can also be updated in lights
						WriteRawConstant( entry.PhysicalIndex, source.GetTextureWorldViewProjMatrix( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.TextureWorldViewProjMatrixArray:
						for ( var l = 0; l < entry.Data; ++l )
						{
							// can also be updated in lights
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, source.GetTextureWorldViewProjMatrix( l ),
							                  entry.ElementCount );
						}
						break;

					case AutoConstantType.SpotLightWorldViewProjMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.GetSpotlightWorldViewProjMatrix( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.LightPositionObjectSpace:
					{
						vec4 = source.GetLightAs4DVector( entry.Data );
						vec3 = new Vector3( vec4.x, vec4.y, vec4.z );
						if ( vec4.w > 0.0f )
						{
							// point light
							vec3 = source.InverseWorldMatrix.TransformAffine( vec3 );
						}
						else
						{
							// directional light
							// We need the inverse of the inverse transpose 
							source.InverseTransposeWorldMatrix.Inverse().Extract3x3Matrix( out m3 );
							vec3 = ( m3*vec3 ).ToNormalized();
						}
						WriteRawConstant( entry.PhysicalIndex, new Vector4( vec3.x, vec3.y, vec3.z, vec4.w ), entry.ElementCount );
					}
						break;

					case AutoConstantType.LightDirectionObjectSpace:
					{
						// We need the inverse of the inverse transpose 
						source.InverseTransposeWorldMatrix.Inverse().Extract3x3Matrix( out m3 );
						vec3 = m3*source.GetLightDirection( entry.Data );
						vec3.Normalize();
						// Set as 4D vector for compatibility
						WriteRawConstant( entry.PhysicalIndex, new Vector4( vec3.x, vec3.y, vec3.z, 0.0f ), entry.ElementCount );
					}
						break;

					case AutoConstantType.LightDistanceObjectSpace:
					{
						vec3 = source.InverseWorldMatrix.TransformAffine( source.GetLightPosition( entry.Data ) );
						WriteRawConstant( entry.PhysicalIndex, vec3.Length );
					}
						break;

					case AutoConstantType.LightPositionObjectSpaceArray:
					{
						// We need the inverse of the inverse transpose 
						source.InverseTransposeWorldMatrix.Inverse().Extract3x3Matrix( out m3 );
						for ( var l = 0; l < entry.Data; ++l )
						{
							vec4 = source.GetLightAs4DVector( l );
							vec3 = new Vector3( vec4.x, vec4.y, vec4.z );
							if ( vec4.w > 0.0f )
							{
								// point light
								vec3 = source.InverseWorldMatrix.TransformAffine( vec3 );
							}
							else
							{
								// directional light
								vec3 = ( m3*vec3 ).ToNormalized();
							}
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, new Vector4( vec3.x, vec3.y, vec3.z, vec4.w ),
							                  entry.ElementCount );
						}
					}
						break;

					case AutoConstantType.LightDirectionObjectSpaceArray:
					{
						// We need the inverse of the inverse transpose 
						source.InverseTransposeWorldMatrix.Inverse().Extract3x3Matrix( out m3 );
						for ( var l = 0; l < entry.Data; ++l )
						{
							vec3 = m3*source.GetLightDirection( l );
							vec3.Normalize();
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, new Vector4( vec3.x, vec3.y, vec3.z, 0.0f ),
							                  entry.ElementCount );
						}
					}
						break;

					case AutoConstantType.LightDistanceObjectSpaceArray:
						for ( var l = 0; l < entry.Data; ++l )
						{
							vec3 = source.InverseWorldMatrix.TransformAffine( source.GetLightPosition( l ) );
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, vec3.Length );
						}
						break;

					case AutoConstantType.WorldMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.WorldMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseWorldMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseWorldMatrix, entry.ElementCount );
						break;

					case AutoConstantType.TransposeWorldMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.TransposeWorldMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseTransposeWorldMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseTransposeWorldMatrix, entry.ElementCount );
						break;

					case AutoConstantType.WorldMatrixArray3x4:
					{
						// Loop over matrices
						var pMatrix = source.WorldMatrixArray;
						var numMatrices = source.WorldMatrixCount;
						var index = entry.PhysicalIndex;
						var floatArray = new float[16];
						for ( var m = 0; m < numMatrices; ++m )
						{
							pMatrix[ m ].MakeFloatArray( floatArray );
							_writeRawConstants( index, floatArray, 12 );
							index += 12;
						}
					}
						break;

					case AutoConstantType.WorldMatrixArray:
						WriteRawConstant( entry.PhysicalIndex, source.WorldMatrixArray, source.WorldMatrixCount );
						break;

					case AutoConstantType.WorldViewMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.WorldViewMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseWorldViewMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseWorldViewMatrix, entry.ElementCount );
						break;

					case AutoConstantType.TransposeWorldViewMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.TransposeWorldViewMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseTransposeWorldViewMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseTransposeWorldViewMatrix, entry.ElementCount );
						break;

					case AutoConstantType.WorldViewProjMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.WorldViewProjMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseWorldViewProjMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseWorldViewProjMatrix, entry.ElementCount );
						break;

					case AutoConstantType.TransposeWorldViewProjMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.TransposeWorldViewProjMatrix, entry.ElementCount );
						break;

					case AutoConstantType.InverseTransposeWorldViewProjMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.InverseTransposeWorldViewProjMatrix, entry.ElementCount );
						break;

					case AutoConstantType.CameraPositionObjectSpace:
						WriteRawConstant( entry.PhysicalIndex, source.CameraPositionObjectSpace, entry.ElementCount );
						break;

					case AutoConstantType.LODCameraPositionObjectSpace:
						WriteRawConstant( entry.PhysicalIndex, source.LodCameraPositionObjectSpace, entry.ElementCount );
						break;

					case AutoConstantType.Custom:
					case AutoConstantType.AnimationParametric:
						source.CurrentRenderable.UpdateCustomGpuParameter( entry, this );
						break;

					case AutoConstantType.LightCustom:
						source.UpdateLightCustomGpuParameter( entry, this );
						break;

					case AutoConstantType.LightCount:
						WriteRawConstant( entry.PhysicalIndex, source.LightCount );
						break;

					case AutoConstantType.LightDiffuseColor:
						WriteRawConstant( entry.PhysicalIndex, source.GetLightDiffuse( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.LightSpecularColor:
						WriteRawConstant( entry.PhysicalIndex, source.GetLightSpecular( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.LightPosition:
					{
						// Get as 4D vector, works for directional lights too
						// Use element count in case uniform slot is smaller
						WriteRawConstant( entry.PhysicalIndex, source.GetLightAs4DVector( entry.Data ), entry.ElementCount );
					}
						break;

					case AutoConstantType.LightDirection:
					{
						vec3 = source.GetLightDirection( entry.Data );
						// Set as 4D vector for compatibility
						// Use element count in case uniform slot is smaller
						WriteRawConstant( entry.PhysicalIndex, new Vector4( vec3.x, vec3.y, vec3.z, 1.0f ), entry.ElementCount );
					}
						break;

					case AutoConstantType.LightPositionViewSpace:
					{
						vec4 = source.GetLightAs4DVector( entry.Data );
						WriteRawConstant( entry.PhysicalIndex, source.ViewMatrix.TransformAffine( vec4 ), entry.ElementCount );
					}
						break;

					case AutoConstantType.LightDirectionViewSpace:
					{
						source.InverseTransposeViewMatrix.Extract3x3Matrix( out m3 );
						// inverse transpose in case of scaling
						vec3 = m3*source.GetLightDirection( entry.Data );
						vec3.Normalize();
						// Set as 4D vector for compatibility
						WriteRawConstant( entry.PhysicalIndex, new Vector4( vec3.x, vec3.y, vec3.z, 0.0f ), entry.ElementCount );
					}
						break;

					case AutoConstantType.ShadowExtrusionDistance:
					{
						// extrusion is in object-space, so we have to rescale by the inverse
						// of the world scaling to deal with scaled objects
						source.WorldMatrix.Extract3x3Matrix( out m3 );
						WriteRawConstant( entry.PhysicalIndex,
						                  source.ShadowExtrusionDistance/
						                  Utility.Sqrt(
						                  	Utility.Max( Utility.Max( m3.GetColumn( 0 ).LengthSquared, m3.GetColumn( 1 ).LengthSquared ),
						                  	             m3.GetColumn( 2 ).LengthSquared ) ) );
					}
						break;

					case AutoConstantType.ShadowSceneDepthRange:
						WriteRawConstant( entry.PhysicalIndex, source.GetShadowSceneDepthRange( entry.Data ) );
						break;

					case AutoConstantType.ShadowColor:
						WriteRawConstant( entry.PhysicalIndex, source.ShadowColor, entry.ElementCount );
						break;

					case AutoConstantType.LightPowerScale:
						WriteRawConstant( entry.PhysicalIndex, source.GetLightPowerScale( entry.Data ) );
						break;

					case AutoConstantType.LightDiffuseColorPowerScaled:
						WriteRawConstant( entry.PhysicalIndex, source.GetLightDiffuseColorWithPower( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.LightSpecularColorPowerScaled:
						WriteRawConstant( entry.PhysicalIndex, source.GetLightSpecularColorWithPower( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.LightNumber:
						WriteRawConstant( entry.PhysicalIndex, source.GetLightNumber( entry.Data ) );
						break;

					case AutoConstantType.LightCastsShadows:
						WriteRawConstant( entry.PhysicalIndex, source.GetLightCastsShadows( entry.Data ) );
						break;

					case AutoConstantType.LightAttenuation:
						WriteRawConstant( entry.PhysicalIndex, source.GetLightAttenuation( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.SpotLightParams:
						WriteRawConstant( entry.PhysicalIndex, source.GetSpotlightParams( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.LightDiffuseColorArray:
						for ( var l = 0; l < entry.Data; ++l )
						{
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, source.GetLightDiffuse( l ), entry.ElementCount );
						}
						break;

					case AutoConstantType.LightSpecularColorArray:
					{
						for ( var l = 0; l < entry.Data; ++l )
						{
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, source.GetLightSpecular( l ), entry.ElementCount );
						}
					}
						break;

					case AutoConstantType.LightDiffuseColorPowerScaledArray:
					{
						for ( var l = 0; l < entry.Data; ++l )
						{
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, source.GetLightDiffuseColorWithPower( l ),
							                  entry.ElementCount );
						}
					}
						break;

					case AutoConstantType.LightSpecularColorPowerScaledArray:
					{
						for ( var l = 0; l < entry.Data; ++l )
						{
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, source.GetLightSpecularColorWithPower( l ),
							                  entry.ElementCount );
						}
					}
						break;

					case AutoConstantType.LightPositionArray:
					{
						// Get as 4D vector, works for directional lights too
						for ( var l = 0; l < entry.Data; ++l )
						{
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, source.GetLightAs4DVector( l ), entry.ElementCount );
						}
					}
						break;

					case AutoConstantType.LightDirectionArray:
						for ( var l = 0; l < entry.Data; ++l )
						{
							vec3 = source.GetLightDirection( l );
							// Set as 4D vector for compatibility
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, new Vector4( vec3.x, vec3.y, vec3.z, 0.0f ),
							                  entry.ElementCount );
						}
						break;

					case AutoConstantType.LightPositionViewSpaceArray:
						for ( var l = 0; l < entry.Data; ++l )
						{
							vec4 = source.GetLightAs4DVector( l );
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, source.ViewMatrix.TransformAffine( vec4 ),
							                  entry.ElementCount );
						}
						break;

					case AutoConstantType.LightDirectionViewSpaceArray:
					{
						source.InverseTransposeViewMatrix.Extract3x3Matrix( out m3 );
						for ( var l = 0; l < entry.Data; ++l )
						{
							vec3 = m3*source.GetLightDirection( l );
							vec3.Normalize();
							// Set as 4D vector for compatibility
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, new Vector4( vec3.x, vec3.y, vec3.z, 0.0f ),
							                  entry.ElementCount );
						}
					}
						break;

					case AutoConstantType.LightPowerScaleArray:
						for ( var l = 0; l < entry.Data; ++l )
						{
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, source.GetLightPowerScale( l ) );
						}
						break;

					case AutoConstantType.LightAttenuationArray:
						for ( var l = 0; l < entry.Data; ++l )
						{
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, source.GetLightAttenuation( l ), entry.ElementCount );
						}
						break;

					case AutoConstantType.SpotLightParamsArray:
						for ( var l = 0; l < entry.Data; ++l )
						{
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, source.GetSpotlightParams( l ), entry.ElementCount );
						}
						break;

					case AutoConstantType.DerivedLightDiffuseColor:
					{
						WriteRawConstant( entry.PhysicalIndex, source.GetLightDiffuseColorWithPower( entry.Data )*source.SurfaceDiffuse,
						                  entry.ElementCount );
					}
						break;

					case AutoConstantType.DerivedLightSpecularColor:
						WriteRawConstant( entry.PhysicalIndex, source.GetLightSpecularColorWithPower( entry.Data )*source.SurfaceSpecular,
						                  entry.ElementCount );
						break;

					case AutoConstantType.DerivedLightDiffuseColorArray:
						for ( var l = 0; l < entry.Data; ++l )
						{
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount,
							                  source.GetLightDiffuseColorWithPower( l )*source.SurfaceDiffuse, entry.ElementCount );
						}
						break;

					case AutoConstantType.DerivedLightSpecularColorArray:
						for ( var l = 0; l < entry.Data; ++l )
						{
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount,
							                  source.GetLightSpecularColorWithPower( l )*source.SurfaceSpecular, entry.ElementCount );
						}
						break;

					case AutoConstantType.TextureViewProjMatrix:
						// can also be updated in lights
						WriteRawConstant( entry.PhysicalIndex, source.GetTextureViewProjectionMatrix( entry.Data ), entry.ElementCount );
						break;

					case AutoConstantType.TextureViewProjMatrixArray:
						for ( var l = 0; l < entry.Data; ++l )
						{
							// can also be updated in lights
							WriteRawConstant( entry.PhysicalIndex + l*entry.ElementCount, source.GetTextureViewProjectionMatrix( l ),
							                  entry.ElementCount );
						}
						break;

					case AutoConstantType.SpotLightViewProjMatrix:
						WriteRawConstant( entry.PhysicalIndex, source.GetSpotlightViewProjMatrix( entry.Data ), entry.ElementCount );
						break;

					default:
						break;
				}
			}
		}
Exemple #6
0
	    public void UpdateAutoParams( AutoParamDataSource source, GpuProgramParameters.GpuParamVariability mask )
	    {
            if (HasVertexProgram)
            {
                // Update vertex program auto params
                _vertexProgramUsage.Params.UpdateAutoParams( source, mask );
            }

            if (HasGeometryProgram)
            {
                // Update geometry program auto params
                _geometryProgramUsage.Params.UpdateAutoParams(source, mask);
            }

            if (HasFragmentProgram)
            {
                // Update fragment program auto params
                _fragmentProgramUsage.Params.UpdateAutoParams(source, mask);
            }
	    }
Exemple #7
0
		/// <summary>
		///    Update any automatic parameters (except lights) on this pass.
		/// </summary>
		public void UpdateAutoParamsNoLights( AutoParamDataSource source )
		{
			// auto update vertex program parameters
			if ( this.HasVertexProgram )
			{
				_vertexProgramUsage.Params.UpdateAutoParamsNoLights( source );
			}

			// auto update fragment program parameters
			if ( this.HasFragmentProgram )
			{
				_fragmentProgramUsage.Params.UpdateAutoParamsNoLights( source );
			}
		}
        public void UpdateAutoParams(AutoParamDataSource source, GpuParamVariability mask)
        {
            // abort early if no autos
            if (!HasAutoConstantType)
            {
                return;
            }

            if ((mask & this._combinedVariability) == 0)
            {
                return;
            }

            this.activePassIterationIndex = int.MaxValue;

            Matrix3 m3;
            Vector4 vec4;
            Vector3 vec3;

            // loop through and update all constants based on their type
            foreach (var entry in this.autoConstants)
            {
                // Only update needed slots
                if ((entry.Variability & mask) == 0)
                {
                    continue;
                }

                switch (entry.Type)
                {
                case AutoConstantType.ViewMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.ViewMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseViewMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseViewMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.TransposeViewMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.TransposeViewMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseTransposeViewMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseTransposeViewMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.ProjectionMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.ProjectionMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseProjectionMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseProjectionMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.TransposeProjectionMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.TransposeProjectionMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseTransposeProjectionMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseTransposeProjectionMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.ViewProjMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.ViewProjectionMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseViewProjMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseViewProjMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.TransposeViewProjMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.TransposeViewProjMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseTransposeViewProjMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseTransposeViewProjMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.RenderTargetFlipping:
                    WriteRawConstant(entry.PhysicalIndex, source.CurrentRenderTarget.RequiresTextureFlipping ? -1.0f : 1.0f);
                    break;

                case AutoConstantType.VertexWinding:
                {
                    var rsys = Root.Instance.RenderSystem;
                    WriteRawConstant(entry.PhysicalIndex, rsys.InvertVertexWinding ? -1.0f : 1.0f);
                    break;
                }

                // NB ambient light still here because it's not related to a specific light
                case AutoConstantType.AmbientLightColor:
                    WriteRawConstant(entry.PhysicalIndex, source.AmbientLight, entry.ElementCount);
                    break;

                case AutoConstantType.DerivedAmbientLightColor:
                    WriteRawConstant(entry.PhysicalIndex, source.DerivedAmbient, entry.ElementCount);
                    break;

                case AutoConstantType.DerivedSceneColor:
                    WriteRawConstant(entry.PhysicalIndex, source.DerivedSceneColor, entry.ElementCount);
                    break;

                case AutoConstantType.FogColor:
                    WriteRawConstant(entry.PhysicalIndex, source.FogColor);
                    break;

                case AutoConstantType.FogParams:
                    WriteRawConstant(entry.PhysicalIndex, source.FogParams, entry.ElementCount);
                    break;

                case AutoConstantType.SurfaceAmbientColor:
                    WriteRawConstant(entry.PhysicalIndex, source.SurfaceAmbient, entry.ElementCount);
                    break;

                case AutoConstantType.SurfaceDiffuseColor:
                    WriteRawConstant(entry.PhysicalIndex, source.SurfaceDiffuse, entry.ElementCount);
                    break;

                case AutoConstantType.SurfaceSpecularColor:
                    WriteRawConstant(entry.PhysicalIndex, source.SurfaceSpecular, entry.ElementCount);
                    break;

                case AutoConstantType.SurfaceEmissiveColor:
                    WriteRawConstant(entry.PhysicalIndex, source.SurfaceEmissive, entry.ElementCount);
                    break;

                case AutoConstantType.SurfaceShininess:
                    WriteRawConstant(entry.PhysicalIndex, source.SurfaceShininess);
                    break;

                case AutoConstantType.CameraPosition:
                    WriteRawConstant(entry.PhysicalIndex, source.CameraPosition, entry.ElementCount);
                    break;

                case AutoConstantType.Time:
                    WriteRawConstant(entry.PhysicalIndex, source.Time * entry.FData);
                    break;

                case AutoConstantType.Time_0_X:
                    WriteRawConstant(entry.PhysicalIndex, source.GetTime_0_X(entry.FData));
                    break;

                case AutoConstantType.CosTime_0_X:
                    WriteRawConstant(entry.PhysicalIndex, source.GetCosTime_0_X(entry.FData));
                    break;

                case AutoConstantType.SinTime_0_X:
                    WriteRawConstant(entry.PhysicalIndex, source.GetSinTime_0_X(entry.FData));
                    break;

                case AutoConstantType.TanTime_0_X:
                    WriteRawConstant(entry.PhysicalIndex, source.GetTanTime_0_X(entry.FData));
                    break;

                case AutoConstantType.Time_0_X_Packed:
                    WriteRawConstant(entry.PhysicalIndex, source.GetTime_0_X_Packed(entry.FData), entry.ElementCount);
                    break;

                case AutoConstantType.Time_0_1:
                    WriteRawConstant(entry.PhysicalIndex, source.GetTime_0_1(entry.FData));
                    break;

                case AutoConstantType.CosTime_0_1:
                    WriteRawConstant(entry.PhysicalIndex, source.GetCosTime_0_1(entry.FData));
                    break;

                case AutoConstantType.SinTime_0_1:
                    WriteRawConstant(entry.PhysicalIndex, source.GetSinTime_0_1(entry.FData));
                    break;

                case AutoConstantType.TanTime_0_1:
                    WriteRawConstant(entry.PhysicalIndex, source.GetTanTime_0_1(entry.FData));
                    break;

                case AutoConstantType.Time_0_1_Packed:
                    WriteRawConstant(entry.PhysicalIndex, source.GetTime_0_1_Packed(entry.FData), entry.ElementCount);
                    break;

                case AutoConstantType.Time_0_2PI:
                    WriteRawConstant(entry.PhysicalIndex, source.GetTime_0_2Pi(entry.FData));
                    break;

                case AutoConstantType.CosTime_0_2PI:
                    WriteRawConstant(entry.PhysicalIndex, source.GetCosTime_0_2Pi(entry.FData));
                    break;

                case AutoConstantType.SinTime_0_2PI:
                    WriteRawConstant(entry.PhysicalIndex, source.GetSinTime_0_2Pi(entry.FData));
                    break;

                case AutoConstantType.TanTime_0_2PI:
                    WriteRawConstant(entry.PhysicalIndex, source.GetTanTime_0_2Pi(entry.FData));
                    break;

                case AutoConstantType.Time_0_2PI_Packed:
                    WriteRawConstant(entry.PhysicalIndex, source.GetTime_0_2Pi_Packed(entry.FData), entry.ElementCount);
                    break;

                case AutoConstantType.FrameTime:
                    WriteRawConstant(entry.PhysicalIndex, source.FrameTime * entry.FData);
                    break;

                case AutoConstantType.FPS:
                    WriteRawConstant(entry.PhysicalIndex, source.FPS);
                    break;

                case AutoConstantType.ViewportWidth:
                    WriteRawConstant(entry.PhysicalIndex, source.ViewportWidth);
                    break;

                case AutoConstantType.ViewportHeight:
                    WriteRawConstant(entry.PhysicalIndex, source.ViewportHeight);
                    break;

                case AutoConstantType.InverseViewportWidth:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseViewportWidth);
                    break;

                case AutoConstantType.InverseViewportHeight:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseViewportHeight);
                    break;

                case AutoConstantType.ViewportSize:
                {
                    WriteRawConstant(entry.PhysicalIndex,
                                     new Vector4(source.ViewportWidth, source.ViewportHeight, source.InverseViewportWidth,
                                                 source.InverseViewportHeight), entry.ElementCount);
                }
                break;

                case AutoConstantType.TexelOffsets:
                {
                    var rsys = Root.Instance.RenderSystem;
                    WriteRawConstant(entry.PhysicalIndex,
                                     new Vector4(rsys.HorizontalTexelOffset, rsys.VerticalTexelOffset,
                                                 rsys.HorizontalTexelOffset * source.InverseViewportWidth,
                                                 rsys.VerticalTexelOffset * source.InverseViewportHeight), entry.ElementCount);
                }
                break;

                case AutoConstantType.TextureSize:
                    WriteRawConstant(entry.PhysicalIndex, source.GetTextureSize(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.InverseTextureSize:
                    WriteRawConstant(entry.PhysicalIndex, source.GetInverseTextureSize(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.PackedTextureSize:
                    WriteRawConstant(entry.PhysicalIndex, source.GetPackedTextureSize(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.SceneDepthRange:
                    WriteRawConstant(entry.PhysicalIndex, source.SceneDepthRange, entry.ElementCount);
                    break;

                case AutoConstantType.ViewDirection:
                    WriteRawConstant(entry.PhysicalIndex, source.ViewDirection);
                    break;

                case AutoConstantType.ViewSideVector:
                    WriteRawConstant(entry.PhysicalIndex, source.ViewSideVector);
                    break;

                case AutoConstantType.ViewUpVector:
                    WriteRawConstant(entry.PhysicalIndex, source.ViewUpVector);
                    break;

                case AutoConstantType.FOV:
                    WriteRawConstant(entry.PhysicalIndex, source.FOV);
                    break;

                case AutoConstantType.NearClipDistance:
                    WriteRawConstant(entry.PhysicalIndex, source.NearClipDistance);
                    break;

                case AutoConstantType.FarClipDistance:
                    WriteRawConstant(entry.PhysicalIndex, source.FarClipDistance);
                    break;

                case AutoConstantType.PassNumber:
                    WriteRawConstant(entry.PhysicalIndex, (float)source.PassNumber);
                    break;

                case AutoConstantType.PassIterationNumber:
                {
                    // this is actually just an initial set-up, it's bound separately, so still global
                    WriteRawConstant(entry.PhysicalIndex, 0.0f);
                    this.activePassIterationIndex = entry.PhysicalIndex;
                }
                break;

                case AutoConstantType.TextureMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.GetTextureTransformMatrix(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.LODCameraPosition:
                    WriteRawConstant(entry.PhysicalIndex, source.LodCameraPosition, entry.ElementCount);
                    break;

                case AutoConstantType.TextureWorldViewProjMatrix:
                    // can also be updated in lights
                    WriteRawConstant(entry.PhysicalIndex, source.GetTextureWorldViewProjMatrix(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.TextureWorldViewProjMatrixArray:
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        // can also be updated in lights
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, source.GetTextureWorldViewProjMatrix(l),
                                         entry.ElementCount);
                    }
                    break;

                case AutoConstantType.SpotLightWorldViewProjMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.GetSpotlightWorldViewProjMatrix(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.LightPositionObjectSpace:
                {
                    vec4 = source.GetLightAs4DVector(entry.Data);
                    vec3 = new Vector3(vec4.x, vec4.y, vec4.z);
                    if (vec4.w > 0.0f)
                    {
                        // point light
                        vec3 = source.InverseWorldMatrix.TransformAffine(vec3);
                    }
                    else
                    {
                        // directional light
                        // We need the inverse of the inverse transpose
                        source.InverseTransposeWorldMatrix.Inverse().Extract3x3Matrix(out m3);
                        vec3 = (m3 * vec3).ToNormalized();
                    }
                    WriteRawConstant(entry.PhysicalIndex, new Vector4(vec3.x, vec3.y, vec3.z, vec4.w), entry.ElementCount);
                }
                break;

                case AutoConstantType.LightDirectionObjectSpace:
                {
                    // We need the inverse of the inverse transpose
                    source.InverseTransposeWorldMatrix.Inverse().Extract3x3Matrix(out m3);
                    vec3 = m3 * source.GetLightDirection(entry.Data);
                    vec3.Normalize();
                    // Set as 4D vector for compatibility
                    WriteRawConstant(entry.PhysicalIndex, new Vector4(vec3.x, vec3.y, vec3.z, 0.0f), entry.ElementCount);
                }
                break;

                case AutoConstantType.LightDistanceObjectSpace:
                {
                    vec3 = source.InverseWorldMatrix.TransformAffine(source.GetLightPosition(entry.Data));
                    WriteRawConstant(entry.PhysicalIndex, vec3.Length);
                }
                break;

                case AutoConstantType.LightPositionObjectSpaceArray:
                {
                    // We need the inverse of the inverse transpose
                    source.InverseTransposeWorldMatrix.Inverse().Extract3x3Matrix(out m3);
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        vec4 = source.GetLightAs4DVector(l);
                        vec3 = new Vector3(vec4.x, vec4.y, vec4.z);
                        if (vec4.w > 0.0f)
                        {
                            // point light
                            vec3 = source.InverseWorldMatrix.TransformAffine(vec3);
                        }
                        else
                        {
                            // directional light
                            vec3 = (m3 * vec3).ToNormalized();
                        }
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, new Vector4(vec3.x, vec3.y, vec3.z, vec4.w),
                                         entry.ElementCount);
                    }
                }
                break;

                case AutoConstantType.LightDirectionObjectSpaceArray:
                {
                    // We need the inverse of the inverse transpose
                    source.InverseTransposeWorldMatrix.Inverse().Extract3x3Matrix(out m3);
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        vec3 = m3 * source.GetLightDirection(l);
                        vec3.Normalize();
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, new Vector4(vec3.x, vec3.y, vec3.z, 0.0f),
                                         entry.ElementCount);
                    }
                }
                break;

                case AutoConstantType.LightDistanceObjectSpaceArray:
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        vec3 = source.InverseWorldMatrix.TransformAffine(source.GetLightPosition(l));
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, vec3.Length);
                    }
                    break;

                case AutoConstantType.WorldMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.WorldMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseWorldMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseWorldMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.TransposeWorldMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.TransposeWorldMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseTransposeWorldMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseTransposeWorldMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.WorldMatrixArray3x4:
                {
                    // Loop over matrices
                    var pMatrix     = source.WorldMatrixArray;
                    var numMatrices = source.WorldMatrixCount;
                    var index       = entry.PhysicalIndex;
                    var floatArray  = new float[16];
                    for (var m = 0; m < numMatrices; ++m)
                    {
                        pMatrix[m].MakeFloatArray(floatArray);
                        _writeRawConstants(index, floatArray, 12);
                        index += 12;
                    }
                }
                break;

                case AutoConstantType.WorldMatrixArray:
                    WriteRawConstant(entry.PhysicalIndex, source.WorldMatrixArray, source.WorldMatrixCount);
                    break;

                case AutoConstantType.WorldViewMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.WorldViewMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseWorldViewMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseWorldViewMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.TransposeWorldViewMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.TransposeWorldViewMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseTransposeWorldViewMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseTransposeWorldViewMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.WorldViewProjMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.WorldViewProjMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseWorldViewProjMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseWorldViewProjMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.TransposeWorldViewProjMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.TransposeWorldViewProjMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.InverseTransposeWorldViewProjMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.InverseTransposeWorldViewProjMatrix, entry.ElementCount);
                    break;

                case AutoConstantType.CameraPositionObjectSpace:
                    WriteRawConstant(entry.PhysicalIndex, source.CameraPositionObjectSpace, entry.ElementCount);
                    break;

                case AutoConstantType.LODCameraPositionObjectSpace:
                    WriteRawConstant(entry.PhysicalIndex, source.LodCameraPositionObjectSpace, entry.ElementCount);
                    break;

                case AutoConstantType.Custom:
                case AutoConstantType.AnimationParametric:
                    source.CurrentRenderable.UpdateCustomGpuParameter(entry, this);
                    break;

                case AutoConstantType.LightCustom:
                    source.UpdateLightCustomGpuParameter(entry, this);
                    break;

                case AutoConstantType.LightCount:
                    WriteRawConstant(entry.PhysicalIndex, source.LightCount);
                    break;

                case AutoConstantType.LightDiffuseColor:
                    WriteRawConstant(entry.PhysicalIndex, source.GetLightDiffuse(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.LightSpecularColor:
                    WriteRawConstant(entry.PhysicalIndex, source.GetLightSpecular(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.LightPosition:
                {
                    // Get as 4D vector, works for directional lights too
                    // Use element count in case uniform slot is smaller
                    WriteRawConstant(entry.PhysicalIndex, source.GetLightAs4DVector(entry.Data), entry.ElementCount);
                }
                break;

                case AutoConstantType.LightDirection:
                {
                    vec3 = source.GetLightDirection(entry.Data);
                    // Set as 4D vector for compatibility
                    // Use element count in case uniform slot is smaller
                    WriteRawConstant(entry.PhysicalIndex, new Vector4(vec3.x, vec3.y, vec3.z, 1.0f), entry.ElementCount);
                }
                break;

                case AutoConstantType.LightPositionViewSpace:
                {
                    vec4 = source.GetLightAs4DVector(entry.Data);
                    WriteRawConstant(entry.PhysicalIndex, source.ViewMatrix.TransformAffine(vec4), entry.ElementCount);
                }
                break;

                case AutoConstantType.LightDirectionViewSpace:
                {
                    source.InverseTransposeViewMatrix.Extract3x3Matrix(out m3);
                    // inverse transpose in case of scaling
                    vec3 = m3 * source.GetLightDirection(entry.Data);
                    vec3.Normalize();
                    // Set as 4D vector for compatibility
                    WriteRawConstant(entry.PhysicalIndex, new Vector4(vec3.x, vec3.y, vec3.z, 0.0f), entry.ElementCount);
                }
                break;

                case AutoConstantType.ShadowExtrusionDistance:
                {
                    // extrusion is in object-space, so we have to rescale by the inverse
                    // of the world scaling to deal with scaled objects
                    source.WorldMatrix.Extract3x3Matrix(out m3);
                    WriteRawConstant(entry.PhysicalIndex,
                                     source.ShadowExtrusionDistance /
                                     Sqrt(
                                         Max(Max(m3.GetColumn(0).LengthSquared, m3.GetColumn(1).LengthSquared),
                                             m3.GetColumn(2).LengthSquared)));
                }
                break;

                case AutoConstantType.ShadowSceneDepthRange:
                    WriteRawConstant(entry.PhysicalIndex, source.GetShadowSceneDepthRange(entry.Data));
                    break;

                case AutoConstantType.ShadowColor:
                    WriteRawConstant(entry.PhysicalIndex, source.ShadowColor, entry.ElementCount);
                    break;

                case AutoConstantType.LightPowerScale:
                    WriteRawConstant(entry.PhysicalIndex, source.GetLightPowerScale(entry.Data));
                    break;

                case AutoConstantType.LightDiffuseColorPowerScaled:
                    WriteRawConstant(entry.PhysicalIndex, source.GetLightDiffuseColorWithPower(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.LightSpecularColorPowerScaled:
                    WriteRawConstant(entry.PhysicalIndex, source.GetLightSpecularColorWithPower(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.LightNumber:
                    WriteRawConstant(entry.PhysicalIndex, source.GetLightNumber(entry.Data));
                    break;

                case AutoConstantType.LightCastsShadows:
                    WriteRawConstant(entry.PhysicalIndex, source.GetLightCastsShadows(entry.Data));
                    break;

                case AutoConstantType.LightAttenuation:
                    WriteRawConstant(entry.PhysicalIndex, source.GetLightAttenuation(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.SpotLightParams:
                    WriteRawConstant(entry.PhysicalIndex, source.GetSpotlightParams(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.LightDiffuseColorArray:
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, source.GetLightDiffuse(l), entry.ElementCount);
                    }
                    break;

                case AutoConstantType.LightSpecularColorArray:
                {
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, source.GetLightSpecular(l), entry.ElementCount);
                    }
                }
                break;

                case AutoConstantType.LightDiffuseColorPowerScaledArray:
                {
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, source.GetLightDiffuseColorWithPower(l),
                                         entry.ElementCount);
                    }
                }
                break;

                case AutoConstantType.LightSpecularColorPowerScaledArray:
                {
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, source.GetLightSpecularColorWithPower(l),
                                         entry.ElementCount);
                    }
                }
                break;

                case AutoConstantType.LightPositionArray:
                {
                    // Get as 4D vector, works for directional lights too
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, source.GetLightAs4DVector(l), entry.ElementCount);
                    }
                }
                break;

                case AutoConstantType.LightDirectionArray:
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        vec3 = source.GetLightDirection(l);
                        // Set as 4D vector for compatibility
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, new Vector4(vec3.x, vec3.y, vec3.z, 0.0f),
                                         entry.ElementCount);
                    }
                    break;

                case AutoConstantType.LightPositionViewSpaceArray:
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        vec4 = source.GetLightAs4DVector(l);
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, source.ViewMatrix.TransformAffine(vec4),
                                         entry.ElementCount);
                    }
                    break;

                case AutoConstantType.LightDirectionViewSpaceArray:
                {
                    source.InverseTransposeViewMatrix.Extract3x3Matrix(out m3);
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        vec3 = m3 * source.GetLightDirection(l);
                        vec3.Normalize();
                        // Set as 4D vector for compatibility
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, new Vector4(vec3.x, vec3.y, vec3.z, 0.0f),
                                         entry.ElementCount);
                    }
                }
                break;

                case AutoConstantType.LightPowerScaleArray:
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, source.GetLightPowerScale(l));
                    }
                    break;

                case AutoConstantType.LightAttenuationArray:
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, source.GetLightAttenuation(l), entry.ElementCount);
                    }
                    break;

                case AutoConstantType.SpotLightParamsArray:
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, source.GetSpotlightParams(l), entry.ElementCount);
                    }
                    break;

                case AutoConstantType.DerivedLightDiffuseColor:
                {
                    WriteRawConstant(entry.PhysicalIndex, source.GetLightDiffuseColorWithPower(entry.Data) * source.SurfaceDiffuse,
                                     entry.ElementCount);
                }
                break;

                case AutoConstantType.DerivedLightSpecularColor:
                    WriteRawConstant(entry.PhysicalIndex, source.GetLightSpecularColorWithPower(entry.Data) * source.SurfaceSpecular,
                                     entry.ElementCount);
                    break;

                case AutoConstantType.DerivedLightDiffuseColorArray:
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount,
                                         source.GetLightDiffuseColorWithPower(l) * source.SurfaceDiffuse, entry.ElementCount);
                    }
                    break;

                case AutoConstantType.DerivedLightSpecularColorArray:
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount,
                                         source.GetLightSpecularColorWithPower(l) * source.SurfaceSpecular, entry.ElementCount);
                    }
                    break;

                case AutoConstantType.TextureViewProjMatrix:
                    // can also be updated in lights
                    WriteRawConstant(entry.PhysicalIndex, source.GetTextureViewProjectionMatrix(entry.Data), entry.ElementCount);
                    break;

                case AutoConstantType.TextureViewProjMatrixArray:
                    for (var l = 0; l < entry.Data; ++l)
                    {
                        // can also be updated in lights
                        WriteRawConstant(entry.PhysicalIndex + l * entry.ElementCount, source.GetTextureViewProjectionMatrix(l),
                                         entry.ElementCount);
                    }
                    break;

                case AutoConstantType.SpotLightViewProjMatrix:
                    WriteRawConstant(entry.PhysicalIndex, source.GetSpotlightViewProjMatrix(entry.Data), entry.ElementCount);
                    break;

                default:
                    break;
                }
            }
        }
		/// <summary>
		///    Updates the automatic light parameters based on the details provided.
		/// </summary>
		/// <param name="source">
		///    A source containing all the updated data to be made available for auto updating
		///    the GPU program constants.
		/// </param>
		public void UpdateAutoParamsLightsOnly( AutoParamDataSource source )
		{
			// return if no constants
			if ( !this.HasAutoConstantType )
			{
				return;
			}

            PassIterationNumberIndex = int.MaxValue;

			// loop through and update all constants based on their type
			for ( int i = 0; i < autoConstantList.Count; i++ )
			{
				AutoConstantEntry entry = autoConstantList[ i ];

				Vector3 vec3;

				switch ( entry.Type )
				{
					case AutoConstantType.LightDiffuseColor:
						SetConstant( entry.PhysicalIndex, source.GetLight( entry.Data ).Diffuse );
						break;

					case AutoConstantType.LightSpecularColor:
						SetConstant( entry.PhysicalIndex, source.GetLight( entry.Data ).Specular );
						break;

					case AutoConstantType.LightPosition:
						// Fix from Multiverse to enable Normal Mapping Sample Material from OGRE
						SetConstant( entry.PhysicalIndex, source.GetLight( entry.Data ).GetAs4DVector() );
						break;

					case AutoConstantType.LightDirection:
						vec3 = source.GetLight( 1 ).DerivedDirection;
						SetConstant( entry.PhysicalIndex, vec3.x, vec3.y, vec3.z, 1.0f );
						break;

					case AutoConstantType.LightPositionObjectSpace:
						SetConstant( entry.PhysicalIndex, source.InverseWorldMatrix * source.GetLight( entry.Data ).GetAs4DVector() );
						break;

					case AutoConstantType.LightDirectionObjectSpace:
						vec3 = source.InverseWorldMatrix * source.GetLight( entry.Data ).DerivedDirection;
						vec3.Normalize();
						SetConstant( entry.PhysicalIndex, vec3.x, vec3.y, vec3.z, 1.0f );
						break;

					case AutoConstantType.LightDistanceObjectSpace:
						vec3 = source.InverseWorldMatrix * source.GetLight( entry.Data ).DerivedPosition;
						SetConstant( entry.PhysicalIndex, vec3.Length, 0f, 0f, 0f );
						break;

					case AutoConstantType.ShadowExtrusionDistance:
						SetConstant( entry.PhysicalIndex, source.ShadowExtrusionDistance, 0f, 0f, 0f );
						break;

					case AutoConstantType.LightAttenuation:
						Light light = source.GetLight( entry.Data );
						SetConstant( entry.PhysicalIndex, light.AttenuationRange, light.AttenuationConstant, light.AttenuationLinear, light.AttenuationQuadratic );
						break;
					case AutoConstantType.LightPowerScale:
						SetConstant( entry.PhysicalIndex, source.GetLightPowerScale( entry.Data ) );
						break;
					case AutoConstantType.WorldMatrix:
						SetConstant( entry.PhysicalIndex, source.WorldMatrix );
						break;
					//case AutoConstantType.ViewProjMatrix:
					//    SetConstant( entry.PhysicalIndex, source.ViewProjectionMatrix );
					//    break;
                    case AutoConstantType.PassIterationNumber:
                        SetConstant(entry.PhysicalIndex, 0.0f);
                        PassIterationNumberIndex = entry.PhysicalIndex;
				        break;
				}
			}
		}
		/// <summary>
		///    Updates the automatic parameters (except lights) based on the details provided.
		/// </summary>
		/// <param name="source">
		///    A source containing all the updated data to be made available for auto updating
		///    the GPU program constants.
		/// </param>
		public void UpdateAutoParamsNoLights( AutoParamDataSource source )
		{
			// return if no constants
			if ( !this.HasAutoConstantType )
			{
				return;
			}

            PassIterationNumberIndex = int.MaxValue;

			// loop through and update all constants based on their type
			for ( int i = 0; i < autoConstantList.Count; i++ )
			{
				AutoConstantEntry entry = autoConstantList[ i ];

				Matrix4[] matrices = null;
				int numMatrices = 0;
				int index = 0;

				switch ( entry.Type )
				{
					case AutoConstantType.WorldMatrix:
						SetConstant( entry.PhysicalIndex, source.WorldMatrix );
						break;

					case AutoConstantType.WorldMatrixArray:
						SetConstant( entry.PhysicalIndex, source.WorldMatrixArray, source.WorldMatrixCount );
						break;

					case AutoConstantType.WorldMatrixArray3x4:
						matrices = source.WorldMatrixArray;
						numMatrices = source.WorldMatrixCount;
						index = entry.PhysicalIndex;

						for ( int j = 0; j < numMatrices; j++ )
						{
							Matrix4 m = matrices[ j ];
							SetConstant( index++, m.m00, m.m01, m.m02, m.m03 );
							SetConstant( index++, m.m10, m.m11, m.m12, m.m13 );
							SetConstant( index++, m.m20, m.m21, m.m22, m.m23 );
						}

						break;

					case AutoConstantType.ViewMatrix:
						SetConstant( entry.PhysicalIndex, source.ViewMatrix );
						break;

					case AutoConstantType.ProjectionMatrix:
						SetConstant( entry.PhysicalIndex, source.ProjectionMatrix );
						break;

					case AutoConstantType.ViewProjMatrix:
						SetConstant( entry.PhysicalIndex, source.ViewProjectionMatrix );
						break;

					case AutoConstantType.WorldViewMatrix:
						SetConstant( entry.PhysicalIndex, source.WorldViewMatrix );
						break;

					case AutoConstantType.WorldViewProjMatrix:
						SetConstant( entry.PhysicalIndex, source.WorldViewProjMatrix );
						break;

					case AutoConstantType.InverseWorldMatrix:
						SetConstant( entry.PhysicalIndex, source.InverseWorldMatrix );
						break;

					case AutoConstantType.InverseViewMatrix:
						SetConstant( entry.PhysicalIndex, source.InverseViewMatrix );
						break;

					case AutoConstantType.InverseTransposeViewMatrix:
						SetConstant( entry.PhysicalIndex, source.InverseTransposeViewMatrix );
						break;

					case AutoConstantType.InverseWorldViewMatrix:
						SetConstant( entry.PhysicalIndex, source.InverseWorldViewMatrix );
						break;

					case AutoConstantType.InverseTransposeWorldViewMatrix:
						SetConstant( entry.PhysicalIndex, source.InverseTransposeWorldViewMatrix );
						break;

					case AutoConstantType.AmbientLightColor:
						SetConstant( entry.PhysicalIndex, source.AmbientLight );
						break;

					case AutoConstantType.CameraPositionObjectSpace:
						SetConstant( entry.PhysicalIndex, source.CameraPositionObjectSpace );
						break;

					case AutoConstantType.CameraPosition:
						SetConstant( entry.PhysicalIndex, source.CameraPosition );
						break;

					case AutoConstantType.TextureViewProjMatrix:
						SetConstant( entry.PhysicalIndex, source.TextureViewProjectionMatrix );
						break;

					case AutoConstantType.Custom:
					case AutoConstantType.AnimationParametric:
						source.Renderable.UpdateCustomGpuParameter( entry, this );
						break;
					case AutoConstantType.FogParams:
						SetConstant( entry.PhysicalIndex, source.FogParams );
						break;
					case AutoConstantType.ViewDirection:
						SetConstant( entry.PhysicalIndex, source.ViewDirection );
						break;
					case AutoConstantType.ViewSideVector:
						SetConstant( entry.PhysicalIndex, source.ViewSideVector );
						break;
					case AutoConstantType.ViewUpVector:
						SetConstant( entry.PhysicalIndex, source.ViewUpVector );
						break;
					case AutoConstantType.NearClipDistance:
						SetConstant( entry.PhysicalIndex, source.NearClipDistance, 0f, 0f, 0f );
						break;
					case AutoConstantType.FarClipDistance:
						SetConstant( entry.PhysicalIndex, source.FarClipDistance, 0f, 0f, 0f );
						break;
					case AutoConstantType.MVShadowTechnique:
						SetConstant( entry.PhysicalIndex, source.MVShadowTechnique );
						break;
					case AutoConstantType.Time:
						SetConstant( entry.PhysicalIndex, source.Time * entry.FData, 0f, 0f, 0f );
						break;
					case AutoConstantType.Time_0_X:
						SetConstant( entry.PhysicalIndex, source.Time % entry.FData, 0f, 0f, 0f );
						break;
					case AutoConstantType.SinTime_0_X:
						SetConstant( entry.PhysicalIndex, Utility.Sin( source.Time % entry.FData ), 0f, 0f, 0f );
						break;
					case AutoConstantType.Time_0_1:
						SetConstant( entry.PhysicalIndex, (float)( source.Time % 1 ), 0f, 0f, 0f );
						break;
					case AutoConstantType.RenderTargetFlipping:
						SetIntConstant( entry.PhysicalIndex, source.RenderTarget.RequiresTextureFlipping ? -1 : 1 );
						break;
					case AutoConstantType.PassNumber:
						SetIntConstant( entry.PhysicalIndex, source.PassNumber );
						break;
                    case AutoConstantType.PassIterationNumber:
                        SetConstant(entry.PhysicalIndex, 0.0f);
                        PassIterationNumberIndex = entry.PhysicalIndex;
				        break;
				}
			}
		}
        /// <summary>
        /// Update automatic parameters.
        /// </summary>
        /// <param name="source">The source of the parameters</param>
        /// <param name="mask">A mask of GpuParamVariability which identifies which autos will need updating</param>
	    public void UpdateAutoParams( AutoParamDataSource source, GpuParamVariability mask )
	    {
            // abort early if no autos
            if (!HasAutoConstantType)
                return;

            // Axiom TODO: implement this early out opt
            // abort early if variability doesn't match any param
            //if (!(mask & _combinedVariability))
            //    return; 

            PassIterationNumberIndex = int.MaxValue;

            // loop through and update all constants based on their type
            foreach ( var entry in autoConstantList )
            {
                // Only update needed slots
                if ((entry.Variability & mask) == 0)
                    continue;

                Matrix4[] matrices;
                int numMatrices;
                int index;

                switch (entry.Type)
                {
                    case AutoConstantType.ViewMatrix:
                        SetConstant(entry.PhysicalIndex, source.ViewMatrix);
                        break;
                    case AutoConstantType.InverseViewMatrix:
                        SetConstant(entry.PhysicalIndex, source.InverseViewMatrix);
                        break;
                    case AutoConstantType.InverseTransposeViewMatrix:
                        SetConstant(entry.PhysicalIndex, source.InverseTransposeViewMatrix);
                        break;

                    case AutoConstantType.ProjectionMatrix:
                        SetConstant(entry.PhysicalIndex, source.ProjectionMatrix);
                        break;

                    case AutoConstantType.ViewProjMatrix:
                        SetConstant(entry.PhysicalIndex, source.ViewProjectionMatrix);
                        break;

                    case AutoConstantType.RenderTargetFlipping:
                        SetIntConstant(entry.PhysicalIndex, source.RenderTarget.RequiresTextureFlipping ? -1 : 1);
                        break;

                    case AutoConstantType.VertexWinding:
                    {
                        var rsys = Root.Instance.RenderSystem;
                        SetIntConstant(entry.PhysicalIndex, rsys.InvertVertexWinding ? -1 : 1);
                        break;
                    }

                    case AutoConstantType.AmbientLightColor:
                        SetConstant( entry.PhysicalIndex, source.AmbientLight );
                        break;

                    case AutoConstantType.WorldMatrix:
                        SetConstant(entry.PhysicalIndex, source.WorldMatrix);
                        break;

                    case AutoConstantType.WorldMatrixArray:
                        SetConstant(entry.PhysicalIndex, source.WorldMatrixArray, source.WorldMatrixCount);
                        break;

                    case AutoConstantType.WorldMatrixArray3x4:
                        matrices = source.WorldMatrixArray;
                        numMatrices = source.WorldMatrixCount;
                        index = entry.PhysicalIndex;

                        for (int j = 0; j < numMatrices; j++)
                        {
                            Matrix4 m = matrices[j];
                            SetConstant(index++, m.m00, m.m01, m.m02, m.m03);
                            SetConstant(index++, m.m10, m.m11, m.m12, m.m13);
                            SetConstant(index++, m.m20, m.m21, m.m22, m.m23);
                        }

                        break;

                    case AutoConstantType.WorldViewMatrix:
                        SetConstant(entry.PhysicalIndex, source.WorldViewMatrix);
                        break;

                    case AutoConstantType.WorldViewProjMatrix:
                        SetConstant(entry.PhysicalIndex, source.WorldViewProjMatrix);
                        break;

                    case AutoConstantType.InverseWorldMatrix:
                        SetConstant(entry.PhysicalIndex, source.InverseWorldMatrix);
                        break;

                    case AutoConstantType.InverseWorldViewMatrix:
                        SetConstant(entry.PhysicalIndex, source.InverseWorldViewMatrix);
                        break;

                    case AutoConstantType.InverseTransposeWorldViewMatrix:
                        SetConstant(entry.PhysicalIndex, source.InverseTransposeWorldViewMatrix);
                        break;   

                    case AutoConstantType.CameraPositionObjectSpace:
                        SetConstant(entry.PhysicalIndex, source.CameraPositionObjectSpace);
                        break;

                    case AutoConstantType.CameraPosition:
                        SetConstant(entry.PhysicalIndex, source.CameraPosition);
                        break;

                    case AutoConstantType.TextureViewProjMatrix:
                        SetConstant(entry.PhysicalIndex, source.TextureViewProjectionMatrix);
                        break;

                    case AutoConstantType.Custom:
                    case AutoConstantType.AnimationParametric:
                        source.Renderable.UpdateCustomGpuParameter(entry, this);
                        break;
                    case AutoConstantType.FogParams:
                        SetConstant(entry.PhysicalIndex, source.FogParams);
                        break;
                    case AutoConstantType.ViewDirection:
                        SetConstant(entry.PhysicalIndex, source.ViewDirection);
                        break;
                    case AutoConstantType.ViewSideVector:
                        SetConstant(entry.PhysicalIndex, source.ViewSideVector);
                        break;
                    case AutoConstantType.ViewUpVector:
                        SetConstant(entry.PhysicalIndex, source.ViewUpVector);
                        break;
                    case AutoConstantType.NearClipDistance:
                        SetConstant(entry.PhysicalIndex, source.NearClipDistance, 0f, 0f, 0f);
                        break;
                    case AutoConstantType.FarClipDistance:
                        SetConstant(entry.PhysicalIndex, source.FarClipDistance, 0f, 0f, 0f);
                        break;
                    case AutoConstantType.MVShadowTechnique:
                        SetConstant(entry.PhysicalIndex, source.MVShadowTechnique);
                        break;
                    case AutoConstantType.Time:
                        SetConstant(entry.PhysicalIndex, source.Time * entry.FData, 0f, 0f, 0f);
                        break;
                    case AutoConstantType.Time_0_X:
                        SetConstant(entry.PhysicalIndex, source.Time % entry.FData, 0f, 0f, 0f);
                        break;
                    case AutoConstantType.SinTime_0_X:
                        SetConstant(entry.PhysicalIndex, Utility.Sin(source.Time % entry.FData), 0f, 0f, 0f);
                        break;
                    case AutoConstantType.Time_0_1:
                        SetConstant(entry.PhysicalIndex, (float)(source.Time % 1), 0f, 0f, 0f);
                        break;
                    
                    case AutoConstantType.PassNumber:
                        SetIntConstant(entry.PhysicalIndex, source.PassNumber);
                        break;
                    case AutoConstantType.PassIterationNumber:
                        SetConstant(entry.PhysicalIndex, 0.0f);
                        PassIterationNumberIndex = entry.PhysicalIndex;
                        break;
                    default:
                        throw new NotImplementedException();
                }
            }
	    }
Exemple #12
0
		protected override void dispose( bool disposeManagedResources )
		{
			if ( !IsDisposed )
			{
				if ( disposeManagedResources )
				{
					if ( SceneManagerDestroyed != null )
					{
						SceneManagerDestroyed( this );
					}

					ClearScene();
					RemoveAllCameras();

					if ( op != null )
					{
						if ( !op.IsDisposed )
						{
							op.Dispose();
						}

						op = null;
					}

					if ( this.autoParamDataSource != null )
					{
						if ( !this.autoParamDataSource.IsDisposed )
						{
							this.autoParamDataSource.Dispose();
						}

						this.autoParamDataSource = null;
					}

					if ( this.rootSceneNode != null )
					{
						if ( !this.rootSceneNode.IsDisposed )
						{
							this.rootSceneNode.Dispose();
						}

						this.rootSceneNode = null;
					}
				}
			}

			base.dispose( disposeManagedResources );
		}
		public override void UpdateGpuProgramsParams( IRenderable rend, Pass pass, AutoParamDataSource source,
		                                              Core.Collections.LightList lightList )
		{
			if ( this.lightParamsList.Count == 0 )
			{
				return;
			}

			var curLightType = LightType.Directional;
			int curSearchLightIndex = 0;
			Matrix4 matWorld = source.WorldMatrix;
			Matrix3 matWorldInvRotation;

			var vRow0 = new Vector3( matWorld[ 0, 0 ], matWorld[ 0, 1 ], matWorld[ 0, 2 ] );
			var vRow1 = new Vector3( matWorld[ 1, 0 ], matWorld[ 1, 1 ], matWorld[ 1, 2 ] );
			var vRow2 = new Vector3( matWorld[ 2, 0 ], matWorld[ 2, 1 ], matWorld[ 2, 2 ] );

			vRow0.Normalize();
			vRow1.Normalize();
			vRow2.Normalize();

			matWorldInvRotation = new Matrix3( vRow0, vRow1, vRow2 );
			//update inverse rotation parameter
			if ( this.worldInvRotMatrix != null )
			{
				this.worldInvRotMatrix.SetGpuParameter( matWorldInvRotation );
			}

			//update per light parameters
			for ( int i = 0; i < this.lightParamsList.Count; i++ )
			{
				LightParams curParams = this.lightParamsList[ i ];

				if ( curLightType != curParams.Type )
				{
					curLightType = curParams.Type;
					curSearchLightIndex = 0;
				}

				Light srcLight = null;
				Vector4 vParameter;
				ColorEx color;

				//Search a matching light from the current sorted lights of the given renderable
				for ( int j = 0; j < lightList.Count; j++ )
				{
					if ( lightList[ j ].Type == curLightType )
					{
						srcLight = lightList[ j ];
						curSearchLightIndex = j + 1;
						break;
					}
				}

				//No matching light found -> use a blank dummy light for parameter update
				if ( srcLight == null )
				{
					srcLight = blankLight;
				}

				switch ( curParams.Type )
				{
					case LightType.Directional:
					{
						Vector3 vec3;

						//Update light direction (object space)
						vec3 = matWorldInvRotation*srcLight.DerivedDirection;
						vec3.Normalize();

						vParameter.x = -vec3.x;
						vParameter.y = -vec3.y;
						vParameter.z = -vec3.z;
						vParameter.w = 0.0;
						curParams.Direction.SetGpuParameter( vParameter );
					}
						break;
					case LightType.Point:
						//update light position (world space)
						vParameter = srcLight.GetAs4DVector( true );
						curParams.Position.SetGpuParameter( vParameter );

						//Update light attenuation parameters.
						vParameter.x = srcLight.AttenuationRange;
						vParameter.y = srcLight.AttenuationConstant;
						vParameter.z = srcLight.AttenuationLinear;
						vParameter.w = srcLight.AttenuationQuadratic;
						curParams.AttenuatParams.SetGpuParameter( vParameter );

						break;
					case LightType.Spotlight:
					{
						Vector3 vec3;

						//Update light position (world space)
						vParameter = srcLight.GetAs4DVector( true );
						curParams.Position.SetGpuParameter( vParameter );

						//Update light direction (object space)
						vec3 = matWorldInvRotation*srcLight.DerivedDirection;
						vec3.Normalize();

						vParameter.x = -vec3.x;
						vParameter.y = -vec3.y;
						vParameter.z = -vec3.z;
						vParameter.w = 0.0;

						curParams.Direction.SetGpuParameter( vParameter );

						//Update light attenuation parameters.
						vParameter.x = srcLight.AttenuationRange;
						vParameter.y = srcLight.AttenuationConstant;
						vParameter.z = srcLight.AttenuationLinear;
						vParameter.w = srcLight.AttenuationQuadratic;
						curParams.AttenuatParams.SetGpuParameter( vParameter );

						//Update spotlight parameters
						Real phi = System.Math.Cos( (double)srcLight.SpotlightOuterAngle*0.5f );
						Real theta = System.Math.Cos( (double)srcLight.SpotlightInnerAngle*0.5f );

						vec3.x = theta;
						vec3.y = phi;
						vec3.z = srcLight.SpotlightFalloff;

						curParams.SpotParams.SetGpuParameter( vec3 );
					}
						break;
				}

				//Update diffuse color
				if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 )
				{
					color = srcLight.Diffuse*pass.Diffuse;
					curParams.DiffuseColor.SetGpuParameter( color );
				}
				else
				{
					color = srcLight.Diffuse;
					curParams.DiffuseColor.SetGpuParameter( color );
				}

				//Update specular color if need to
				if ( this.specularEnabled )
				{
					//Update diffuse color
					if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 )
					{
						color = srcLight.Specular*pass.Specular;
						curParams.SpecularColor.SetGpuParameter( color );
					}
					else
					{
						color = srcLight.Specular;
						curParams.SpecularColor.SetGpuParameter( color );
					}
				}
			}
		}
        /// <summary>
        ///    Updates the automatic light parameters based on the details provided.
        /// </summary>
        /// <param name="source">
        ///    A source containing all the updated data to be made available for auto updating
        ///    the GPU program constants.
        /// </param>
        public void UpdateAutoParamsLightsOnly(AutoParamDataSource source)
        {
            // return if no constants
            if(!this.HasAutoConstants) {
                return;
            }

            // loop through and update all constants based on their type
            for(int constantIndex = 0; constantIndex < autoConstantList.Count; constantIndex++) {
                AutoConstantEntry entry = (AutoConstantEntry)autoConstantList[constantIndex];

                Vector3 vec3;
                Light light;
                int i;

                switch(entry.type) {
                    case AutoConstants.LightDiffuseColor:
                        SetConstant(entry.index, source.GetLight(entry.data).Diffuse);
                        break;

                    case AutoConstants.LightSpecularColor:
                        SetConstant(entry.index, source.GetLight(entry.data).Specular);
                        break;

                    case AutoConstants.LightPosition:
                        SetConstant(entry.index, source.GetLight(entry.data).DerivedPosition);
                        break;

                    case AutoConstants.LightDirection:
                        vec3 = source.GetLight(entry.data).DerivedDirection;
                        SetConstant(entry.index, vec3.x, vec3.y, vec3.z, 1.0f);
                        break;

                    case AutoConstants.LightPositionObjectSpace:
                        SetConstant(entry.index, source.InverseWorldMatrix * source.GetLight(entry.data).GetAs4DVector());
                        break;

                    case AutoConstants.LightDirectionObjectSpace:
                        vec3 = source.InverseWorldMatrix * source.GetLight(entry.data).DerivedDirection;
                        vec3.Normalize();
                        SetConstant(entry.index, vec3.x, vec3.y, vec3.z, 1.0f);
                        break;

                    case AutoConstants.LightPositionViewSpace:
                        SetConstant(entry.index, source.ViewMatrix.TransformAffine(source.GetLight(entry.data).GetAs4DVector()));
                        break;

                    case AutoConstants.LightDirectionViewSpace:
                        vec3 = source.InverseViewMatrix.Transpose() * source.GetLight(entry.data).DerivedDirection;
                        vec3.Normalize();
                        SetConstant(entry.index, vec3.x, vec3.y, vec3.z, 1.0f);
                        break;

                    case AutoConstants.LightDistanceObjectSpace:
                        vec3 = source.InverseWorldMatrix * source.GetLight(entry.data).DerivedPosition;
                        SetConstant(entry.index, vec3.Length);
                        break;

                    case AutoConstants.ShadowExtrusionDistance:
                        SetConstant(entry.index, source.ShadowExtrusionDistance);
                        break;

                    case AutoConstants.ShadowSceneDepthRange:
                        SetConstant(entry.index, source.GetShadowSceneDepthRange(entry.data));
                        break;

                    case AutoConstants.LightPower:
                        SetConstant(entry.index, source.GetLight(entry.data).PowerScale);
                        break;

                    case AutoConstants.LightAttenuation:
                        light = source.GetLight(entry.data);
                        SetConstant(entry.index, light.AttenuationRange, light.AttenuationConstant, light.AttenuationLinear, light.AttenuationQuadratic);
                        break;

                    case AutoConstants.SpotlightParams:
                        light = source.GetLight(entry.data);
                        if (light.Type == LightType.Spotlight)
                            SetConstant(entry.index,
                                (float)Math.Cos(MathUtil.DegreesToRadians(light.SpotlightInnerAngle) * 0.5),
                                (float)Math.Cos(MathUtil.DegreesToRadians(light.SpotlightOuterAngle) * 0.5),
                                light.SpotlightFalloff,
                                1.0f);
                        else
                            SetConstant(entry.index, 1f, 0f, 0f, 1f);
                        break;

                    case AutoConstants.LightDiffuseColorArray:
                        for (i=0; i<entry.data; i++)
                            SetConstant(entry.index + i, source.GetLight(i).Diffuse);
                        break;

                    case AutoConstants.LightSpecularColorArray:
                        for (i=0; i<entry.data; i++)
                            SetConstant(entry.index + i, source.GetLight(i).Specular);
                        break;

                    case AutoConstants.LightPositionArray:
                        for (i=0; i<entry.data; i++)
                            SetConstant(entry.index + i, source.GetLight(i).DerivedPosition);
                        break;

                    case AutoConstants.LightDirectionArray:
                        for (i=0; i<entry.data; i++) {
                            vec3 = source.GetLight(i).DerivedDirection;
                            SetConstant(entry.index + i, vec3.x, vec3.y, vec3.z, 1.0f);
                        }
                        break;

                    case AutoConstants.LightPositionObjectSpaceArray:
                        for (i=0; i<entry.data; i++)
                            SetConstant(entry.index + i, source.ViewMatrix.TransformAffine(source.GetLight(i).GetAs4DVector()));
                        break;

                    case AutoConstants.LightDirectionObjectSpaceArray:
                        for (i=0; i<entry.data; i++) {
                            vec3 = source.InverseWorldMatrix.TransformAffine(source.GetLight(i).DerivedDirection);
                            SetConstant(entry.index + i, vec3.x, vec3.y, vec3.z, 1.0f);
                        }
                        break;

                    case AutoConstants.LightPositionViewSpaceArray:
                        for (i=0; i<entry.data; i++)
             						    SetConstant(entry.index + i, source.ViewMatrix.TransformAffine(source.GetLight(i).GetAs4DVector()));
                        break;

                    case AutoConstants.LightDirectionViewSpaceArray:
                        for (i=0; i<entry.data; i++) {
                            vec3 = source.InverseViewMatrix.Transpose() * source.GetLight(i).DerivedDirection;
                            vec3.Normalize();
                            SetConstant(entry.index + i, vec3.x, vec3.y, vec3.z, 1.0f);
                        }
                        break;

                    case AutoConstants.LightDistanceObjectSpaceArray:
                        for (i=0; i<entry.data; i++) {
                            vec3 = source.InverseWorldMatrix * source.GetLight(i).DerivedPosition;
                            SetConstant(entry.index + i, vec3.Length);
                        }
                        break;

                    case AutoConstants.LightPowerArray:
                        for (i=0; i<entry.data; i++)
                            SetConstant(entry.index + i, source.GetLight(i).PowerScale);
                        break;

                    case AutoConstants.LightAttenuationArray:
                        for (i=0; i<entry.data; i++) {
                            light = source.GetLight(i);
                            SetConstant(entry.index + i, light.AttenuationRange, light.AttenuationConstant, light.AttenuationLinear, light.AttenuationQuadratic);
                        }
                        break;

                    case AutoConstants.SpotlightParamsArray:
                        for (i=0; i<entry.data; i++) {
                            light = source.GetLight(i);
                            if (light.Type == LightType.Spotlight)
                                SetConstant(entry.index + 1,
                                    (float)Math.Cos(MathUtil.DegreesToRadians(light.SpotlightInnerAngle) * 0.5),
                                    (float)Math.Cos(MathUtil.DegreesToRadians(light.SpotlightOuterAngle) * 0.5),
                                    light.SpotlightFalloff,
                                    1.0f);
                            else
                                SetConstant(entry.index + i, 1f, 0f, 0f, 1f);
                        }
                        break;

                    case AutoConstants.DerivedLightDiffuseColor:
                        SetConstant(entry.index, source.GetLight(entry.data).Diffuse * source.CurrentPass.Diffuse);
                        break;

                    case AutoConstants.DerivedLightSpecularColor:
                        SetConstant(entry.index, source.GetLight(entry.data).Diffuse * source.CurrentPass.Specular);
                        break;

                    case AutoConstants.DerivedLightDiffuseColorArray:
                        for (i=0; i<entry.data; i++) {
                            light = source.GetLight(i);
                            SetConstant(entry.index + i, light.Diffuse * source.CurrentPass.Diffuse);
                        }
                        break;

                    case AutoConstants.DerivedLightSpecularColorArray:
                        for (i=0; i<entry.data; i++) {
                            light = source.GetLight(i);
                            SetConstant(entry.index + i, light.Specular * source.CurrentPass.Diffuse);
                        }
                        break;

                    case AutoConstants.TextureViewProjMatrix:
                        SetConstant(entry.index, source.GetTextureViewProjectionMatrix(entry.data));
                        break;

                    default:
                        // do nothing
                        break;
                }
            }
        }
        /// <summary>
        ///    Updates the automatic parameters (except lights) based on the details provided.
        /// </summary>
        /// <param name="source">
        ///    A source containing all the updated data to be made available for auto updating
        ///    the GPU program constants.
        /// </param>
        public void UpdateAutoParamsNoLights(AutoParamDataSource source)
        {
            // return if no constants
            if(!this.HasAutoConstants) {
                return;
            }

            // loop through and update all constants based on their type
            for(int i = 0; i < autoConstantList.Count; i++) {
                AutoConstantEntry entry = (AutoConstantEntry)autoConstantList[i];

                Matrix4[] matrices = null;
                int numMatrices = 0;
                int index = 0;
                float t;

                switch(entry.type) {
                    case AutoConstants.WorldMatrix:
                        SetConstant(entry.index, source.WorldMatrix);
                        break;

                    case AutoConstants.InverseWorldMatrix:
                        SetConstant(entry.index, source.InverseWorldMatrix);
                        break;

                    case AutoConstants.TransposeWorldMatrix:
                        SetConstant(entry.index, source.WorldMatrix.Transpose());
                        break;

                    case AutoConstants.InverseTransposeWorldMatrix:
                        SetConstant(entry.index, source.InverseWorldMatrix.Transpose());
                        break;

                    case AutoConstants.WorldMatrixArray3x4:
                        matrices = source.WorldMatrixArray;
                        numMatrices = source.WorldMatrixCount;
                        index = entry.index;

                        for(int j = 0; j < numMatrices; j++) {
                            Matrix4 m = matrices[j];
                            SetConstant(index++, m.m00, m.m01, m.m02, m.m03);
                            SetConstant(index++, m.m10, m.m11, m.m12, m.m13);
                            SetConstant(index++, m.m20, m.m21, m.m22, m.m23);
                        }

                        break;

                    case AutoConstants.WorldMatrixArray:
                        SetConstant(entry.index, source.WorldMatrixArray, source.WorldMatrixCount);
                        break;

                    case AutoConstants.ViewMatrix:
                        SetConstant(entry.index, source.ViewMatrix);
                        break;

                    case AutoConstants.InverseViewMatrix:
                        SetConstant(entry.index, source.InverseViewMatrix);
                        break;

                    case AutoConstants.TransposeViewMatrix:
                        SetConstant(entry.index, source.ViewMatrix.Transpose());
                        break;

                    case AutoConstants.InverseTransposeViewMatrix:
                        SetConstant(entry.index, source.InverseViewMatrix.Transpose());
                        break;

                    case AutoConstants.ProjectionMatrix:
                        SetConstant(entry.index, source.ProjectionMatrix);
                        break;

                    case AutoConstants.InverseProjectionMatrix:
                        SetConstant(entry.index, source.InverseProjectionMatrix);
                        break;

                    case AutoConstants.InverseTransposeProjectionMatrix:
                        SetConstant(entry.index, source.InverseProjectionMatrix.Transpose());
                        break;

                    case AutoConstants.ViewProjMatrix:
                        SetConstant(entry.index, source.ViewProjectionMatrix);
                        break;

                    case AutoConstants.InverseViewProjMatrix:
                        SetConstant(entry.index, source.InverseViewProjMatrix);
                        break;

                    case AutoConstants.TransposeViewProjMatrix:
                        SetConstant(entry.index, source.ViewProjectionMatrix.Transpose());
                        break;

                    case AutoConstants.InverseTransposeViewProjMatrix:
                        SetConstant(entry.index, source.InverseViewProjMatrix.Transpose());
                        break;

                    case AutoConstants.WorldViewMatrix:
                        SetConstant(entry.index, source.WorldViewMatrix);
                        break;

                    case AutoConstants.InverseWorldViewMatrix:
                        SetConstant(entry.index, source.InverseWorldViewMatrix);
                        break;

                    case AutoConstants.TransposeWorldViewMatrix:
                        SetConstant(entry.index, source.WorldViewMatrix.Transpose());
                        break;

                    case AutoConstants.InverseTransposeWorldViewMatrix:
                        SetConstant(entry.index, source.InverseWorldViewMatrix.Transpose());
                        break;

                    case AutoConstants.RenderTargetFlipping:
                        SetIntConstant(entry.index, source.RenderTarget.RequiresTextureFlipping ? -1 : 1);
                        break;

                    case AutoConstants.AmbientLightColor:
                        SetConstant(entry.index, source.AmbientLight);
                        break;

                    case AutoConstants.DerivedAmbientLightColor:
                        SetConstant(entry.index, source.DerivedAmbientLight);
                        break;

                    case AutoConstants.DerivedSceneColor:
                        ColorEx result = source.DerivedAmbientLight + source.CurrentPass.Emissive;
                        result.a = source.CurrentPass.Diffuse.a;
                        SetConstant(entry.index, result);
                        break;

                    case AutoConstants.FogColor:
                        SetConstant(entry.index, source.FogColor);
                        break;

                    case AutoConstants.FogParams:
                        SetConstant(entry.index, source.FogParams);
                        break;

                    case AutoConstants.SurfaceAmbientColor:
                        SetConstant(entry.index, source.CurrentPass.Ambient);
                        break;

                    case AutoConstants.SurfaceDiffuseColor:
                        SetConstant(entry.index, source.CurrentPass.Diffuse);
                        break;

                    case AutoConstants.SurfaceSpecularColor:
                        SetConstant(entry.index, source.CurrentPass.Specular);
                        break;

                    case AutoConstants.SurfaceEmissiveColor:
                        SetConstant(entry.index, source.CurrentPass.Emissive);
                        break;

                    case AutoConstants.SurfaceShininess:
                        SetConstant(entry.index, source.CurrentPass.Shininess);
                        break;

                    case AutoConstants.CameraPosition:
                        SetConstant(entry.index, source.CameraPosition);
                        break;

                    case AutoConstants.CameraPositionObjectSpace:
                        SetConstant(entry.index, source.CameraPositionObjectSpace);
                        break;

                    case AutoConstants.Time:
                        SetFloatConstant(entry.index, source.Time * entry.fdata);
                        break;

                    case AutoConstants.Time_0_X:
                        SetFloatConstant(entry.index, source.GetTime_0_X(entry.fdata));
                        break;

                    case AutoConstants.CosTime_0_X:
                        SetFloatConstant(entry.index, (float)Math.Cos(source.GetTime_0_X(entry.fdata)));
                        break;

                    case AutoConstants.SinTime_0_X:
                        SetFloatConstant(entry.index, (float)Math.Sin(source.GetTime_0_X(entry.fdata)));
                        break;

                    case AutoConstants.TanTime_0_X:
                        SetFloatConstant(entry.index, (float)Math.Tan(source.GetTime_0_X(entry.fdata)));
                        break;

                    case AutoConstants.Time_0_X_Packed:
                        t = source.Time;
                        SetConstant(entry.index, t, (float)Math.Sin(t), (float)Math.Cos(t), (float)Math.Tan(t));
                        break;

                    case AutoConstants.Time_0_1:
                        SetFloatConstant(entry.index, source.GetTime_0_1(entry.fdata));
                        break;

                    case AutoConstants.CosTime_0_1:
                        SetFloatConstant(entry.index, (float)Math.Cos(source.GetTime_0_1(entry.fdata)));
                        break;

                    case AutoConstants.SinTime_0_1:
                        SetFloatConstant(entry.index, (float)Math.Sin(source.GetTime_0_1(entry.fdata)));
                        break;

                    case AutoConstants.TanTime_0_1:
                        SetFloatConstant(entry.index, (float)Math.Tan(source.GetTime_0_1(entry.fdata)));
                        break;

                    case AutoConstants.Time_0_1_Packed:
                        t = source.GetTime_0_1(entry.fdata);
                        SetConstant(entry.index, t, (float)Math.Sin(t), (float)Math.Cos(t), (float)Math.Tan(t));
                        break;

                    case AutoConstants.Time_0_2PI:
                        SetFloatConstant(entry.index, source.GetTime_0_2PI(entry.fdata));
                        break;

                    case AutoConstants.CosTime_0_2PI:
                        SetFloatConstant(entry.index, (float)Math.Cos(source.GetTime_0_2PI(entry.fdata)));
                        break;

                    case AutoConstants.SinTime_0_2PI:
                        SetFloatConstant(entry.index, (float)Math.Sin(source.GetTime_0_2PI(entry.fdata)));
                        break;

                    case AutoConstants.TanTime_0_2PI:
                        SetFloatConstant(entry.index, (float)Math.Tan(source.GetTime_0_2PI(entry.fdata)));
                        break;

                    case AutoConstants.Time_0_2PI_Packed:
                        t = source.GetTime_0_2PI(entry.fdata);
                        SetConstant(entry.index, t, (float)Math.Sin(t), (float)Math.Cos(t), (float)Math.Tan(t));
                        break;

                    case AutoConstants.FrameTime:
                        SetConstant(entry.index, (1.0f / Root.Instance.AverageFPS));
                        break;

                    case AutoConstants.FPS:
                        SetConstant(entry.index, Root.Instance.AverageFPS);
                        break;

                    case AutoConstants.ViewportWidth:
                        SetConstant(entry.index, source.Viewport.ActualWidth);
                        break;

                    case AutoConstants.ViewportHeight:
                        SetConstant(entry.index, source.Viewport.ActualHeight);
                        break;

                    case AutoConstants.ViewportSize:
                        SetConstant(entry.index,
                                    new Vector4(source.Viewport.ActualWidth,
                                                source.Viewport.ActualHeight,
                                                1.0f / source.Viewport.ActualWidth,
                                                1.0f / source.Viewport.ActualHeight));
                        break;

                    case AutoConstants.TexelOffsets:
                        RenderSystem rsys = Root.Instance.RenderSystem;
                        SetConstant(entry.index,
                            new Vector4(rsys.HorizontalTexelOffset,
                                        rsys.VerticalTexelOffset,
                                        rsys.HorizontalTexelOffset / source.Viewport.ActualWidth,
                                        rsys.VerticalTexelOffset / source.Viewport.ActualHeight));
                        break;

                    case AutoConstants.TextureSize:
                        SetConstant(entry.index, source.GetTextureSize(entry.data));
                        break;

                    case AutoConstants.InverseTextureSize:
                        SetConstant(entry.index, 1.0f / source.GetTextureSize(entry.data));
                        break;

                    case AutoConstants.SceneDepthRange:
                        SetConstant(entry.index, source.SceneDepthRange);
                        break;

                    case AutoConstants.ViewDirection:
                        SetConstant(entry.index, source.ViewDirection);
                        break;

                    case AutoConstants.ViewSideVector:
                        SetConstant(entry.index, source.ViewSideVector);
                        break;

                    case AutoConstants.WorldViewProjMatrix:
                        SetConstant(entry.index, source.WorldViewProjMatrix);
                        break;

                    case AutoConstants.ViewUpVector:
                        SetConstant(entry.index, source.ViewUpVector);
                        break;

                    case AutoConstants.FOV:
                        SetConstant(entry.index, MathUtil.DegreesToRadians(source.Camera.FOVy));
                        break;

                    case AutoConstants.NearClipDistance:
                        SetConstant(entry.index, source.NearClipDistance);
                        break;

                    case AutoConstants.FarClipDistance:
                        SetConstant(entry.index, source.FarClipDistance);
                        break;

                    case AutoConstants.PassNumber:
                        SetIntConstant(entry.index, source.PassNumber);
                        break;

                    case AutoConstants.PassIterationNumber:
                        // TODO: This isn't right, and doesn't match
                        // what Ogre does.  I can't figure out what
                        // Ogre does.
                        SetIntConstant(entry.index, source.PassIterationNumber);
                        break;

                    case AutoConstants.TextureViewProjMatrix:
                        SetConstant(entry.index, source.GetTextureViewProjectionMatrix(entry.data));
                        break;

                    case AutoConstants.Custom:
                    case AutoConstants.AnimationParametric:
                        source.Renderable.UpdateCustomGpuParameter(entry, this);
                        break;

                    case AutoConstants.MVShadowTechnique:
                        SetConstant(entry.index, source.MVShadowTechnique);
                        break;

                    case AutoConstants.ShadowFadeParams:
                        SetConstant(entry.index, source.ShadowFadeParams);
                        break;
                }
            }
        }