Class used to define parameters for a texture effect.
Exemplo n.º 1
0
		/// <summary>
		///		Generic method for setting up texture effects.
		/// </summary>
		/// <remarks>
		///    Allows you to specify effects directly by using the TextureEffectType enumeration. The
		///    arguments that go with it depend on the effect type. Only one effect of
		///    each type can be applied to a texture layer.
		///    <p/>
		///    This method is used internally, but it is better generally for applications to use the
		///    more intuitive specialized methods such as SetEnvironmentMap and SetScroll.
		/// </remarks>
		/// <param name="effect"></param>
		public void AddEffect( TextureEffect effect )
		{
			effect.controller = null;

			// these effects must be unique, so remove any existing
			if ( effect.type == TextureEffectType.EnvironmentMap || effect.type == TextureEffectType.UVScroll ||
			     effect.type == TextureEffectType.UScroll || effect.type == TextureEffectType.VScroll ||
			     effect.type == TextureEffectType.Rotate || effect.type == TextureEffectType.ProjectiveTexture )
			{
				for ( var i = 0; i < this.effectList.Count; i++ )
				{
					if ( ( (TextureEffect)this.effectList[ i ] ).type == effect.type )
					{
						this.effectList.RemoveAt( i );
						break;
					}
				} // for
			}

			// create controller
			if ( IsLoaded )
			{
				CreateEffectController( effect );
			}

			// add to internal list
			this.effectList.Add( effect );
		}
Exemplo n.º 2
0
		/// <summary>
		///		Used internally to create a new controller for this layer given the requested effect.
		/// </summary>
		/// <param name="effect"></param>
		private void CreateEffectController( TextureEffect effect )
		{
			// get a reference to the singleton controller manager
			var cMgr = ControllerManager.Instance;

			// create an appropriate controller based on the specified animation
			switch ( effect.type )
			{
				case TextureEffectType.UVScroll:
					effect.controller = cMgr.CreateTextureUVScroller( this, effect.arg1 );
					break;

				case TextureEffectType.UScroll:
					effect.controller = cMgr.CreateTextureUScroller( this, effect.arg1 );
					break;

				case TextureEffectType.VScroll:
					effect.controller = cMgr.CreateTextureVScroller( this, effect.arg1 );
					break;

				case TextureEffectType.Rotate:
					effect.controller = cMgr.CreateTextureRotator( this, effect.arg1 );
					break;

				case TextureEffectType.Transform:
					effect.controller = cMgr.CreateTextureWaveTransformer( this, (TextureTransform)effect.subtype, effect.waveType,
					                                                       effect.baseVal, effect.frequency, effect.phase,
					                                                       effect.amplitude );

					break;

				case TextureEffectType.EnvironmentMap:
					break;
			}
		}
Exemplo n.º 3
0
		/// <summary>
		///		Sets up an animated texture rotation for this layer.
		/// </summary>
		/// <remarks>
		///    Useful for constant rotations (for varying rotations, <see cref="SetTransformAnimation"/>).
		///    <p/>
		///    This option has no effect in the programmable pipeline.
		/// </remarks>
		/// <param name="speed">The number of complete counter-clockwise revolutions per second (use -ve for clockwise)</param>
		public void SetRotateAnimation( float speed )
		{
			this.rotationSpeed = speed;
			var effect = new TextureEffect();
			effect.type = TextureEffectType.Rotate;
			effect.arg1 = speed;

			AddEffect( effect );
		}
Exemplo n.º 4
0
		/// <summary>
		///    Sets up a general time-relative texture modification effect.
		/// </summary>
		/// <remarks>
		///    This can be called multiple times for different values of <paramref name="transType"/>, but only the latest effect
		///    applies if called multiple time for the same <paramref name="transType"/>.
		///    <p/>
		///    This option has no effect in the programmable pipeline.
		/// </remarks>
		/// <param name="transType">The type of transform, either translate (scroll), scale (stretch) or rotate (spin).</param>
		/// <param name="waveType">The shape of the wave, see <see cref="WaveformType"/> enum for details</param>
		/// <param name="baseVal">The base value for the function (range of output = {base, base + amplitude}).</param>
		/// <param name="frequency">The speed of the wave in cycles per second.</param>
		/// <param name="phase">The offset of the start of the wave, e.g. 0.5 to start half-way through the wave.</param>
		/// <param name="amplitude">Scales the output so that instead of lying within [0..1] it lies within [0..(1 * amplitude)] for exaggerated effects.</param>
		public void SetTransformAnimation( TextureTransform transType, WaveformType waveType, float baseVal, float frequency,
		                                   float phase, float amplitude )
		{
			var effect = new TextureEffect();
			effect.type = TextureEffectType.Transform;
			effect.subtype = transType;
			effect.waveType = waveType;
			effect.baseVal = baseVal;
			effect.frequency = frequency;
			effect.phase = phase;
			effect.amplitude = amplitude;

			AddEffect( effect );
		}
Exemplo n.º 5
0
		/// <summary>
		///		Sets up an animated scroll for the texture layer.
		/// </summary>
		/// <remarks>
		///    Useful for creating constant scrolling effects on a texture layer (for varying scrolls, <see cref="SetTransformAnimation"/>).
		///    <p/>
		///    This option has no effect in the programmable pipeline.
		/// </remarks>
		/// <param name="uSpeed">The number of horizontal loops per second (+ve=moving right, -ve = moving left).</param>
		/// <param name="vSpeed">The number of vertical loops per second (+ve=moving up, -ve= moving down).</param>
		public void SetScrollAnimation( float uSpeed, float vSpeed )
		{
			RemoveEffect( TextureEffectType.UVScroll );
			RemoveEffect( TextureEffectType.UScroll );
			RemoveEffect( TextureEffectType.VScroll );

			// don't create an effect if both Speeds are 0
			if ( uSpeed == 0 && vSpeed == 0 )
			{
				return;
			}

			// Create new effect
			TextureEffect effect;
			if ( uSpeed == vSpeed )
			{
				effect = new TextureEffect();
				effect.type = TextureEffectType.UVScroll;
				effect.arg1 = uSpeed;
				AddEffect( effect );
			}
			else
			{
				if ( uSpeed != 0 )
				{
					effect = new TextureEffect();
					effect.type = TextureEffectType.UScroll;
					effect.arg1 = uSpeed;
					AddEffect( effect );
				}
				if ( vSpeed != 0 )
				{
					effect = new TextureEffect();
					effect.type = TextureEffectType.VScroll;
					effect.arg1 = vSpeed;
					AddEffect( effect );
				}
			}
		}
Exemplo n.º 6
0
		/// <summary>
		///    Turns on/off texture coordinate effect that makes this layer an environment map.
		/// </summary>
		/// <remarks>
		///    Environment maps make an object look reflective by using the object's vertex normals relative
		///    to the camera view to generate texture coordinates.
		///    <p/>
		///    The vectors generated can either be used to address a single 2D texture which
		///    is a 'fish-eye' lens view of a scene, or a 3D cubic environment map which requires 6 textures
		///    for each side of the inside of a cube. The type depends on what texture you set up - if you use the
		///    setTextureName method then a 2D fisheye lens texture is required, whereas if you used setCubicTextureName
		///    then a cubic environemnt map will be used.
		///    <p/>
		///    This effect works best if the object has lots of gradually changing normals. The texture also
		///    has to be designed for this effect - see the example spheremap.png included with the sample
		///    application for a 2D environment map; a cubic map can be generated by rendering 6 views of a
		///    scene to each of the cube faces with orthoganal views.
		///    <p/>
		///    Enabling this disables any other texture coordinate generation effects.
		///    However it can be combined with texture coordinate modification functions, which then operate on the
		///    generated coordinates rather than static model texture coordinates.
		///    <p/>
		///    This option has no effect in the programmable pipeline.
		/// </remarks>
		/// <param name="enable">True to enable, false to disable.</param>
		/// <param name="envMap">
		///    If set to true, instead of being based on normals the environment effect is based on
		///    vertex positions. This is good for planar surfaces.
		/// </param>
		public void SetEnvironmentMap( bool enable, EnvironmentMap envMap )
		{
			this.environMap = envMap;
			this.envMapEnabled = enable;
			if ( enable )
			{
				var effect = new TextureEffect();
				effect.type = TextureEffectType.EnvironmentMap;
				effect.subtype = envMap;
				AddEffect( effect );
			}
			else
			{
				// remove it from the list
				RemoveEffect( TextureEffectType.EnvironmentMap );
			}
		}
Exemplo n.º 7
0
		/// <summary>
		///    Removes the specified effect from the list of effects being applied during this
		///    texture stage.
		/// </summary>
		/// <param name="effect">Effect to remove.</param>
		public void RemoveEffect( TextureEffect effect )
		{
			this.effectList.Remove( effect );
		}
Exemplo n.º 8
0
		/// <summary>
		///    Enables or disables projective texturing on this texture unit.
		/// </summary>
		/// <remarks>
		///	   <p>
		///	   Projective texturing allows you to generate texture coordinates 
		///	   based on a Frustum, which gives the impression that a texture is
		///	   being projected onto the surface. Note that once you have called
		///	   this method, the texture unit continues to monitor the Frustum you 
		///	   passed in and the projection will change if you can alter it. It also
		///	   means that the Frustum object you pass remains in existence for as long
		///	   as this TextureUnitState does.
		///	   </p>
		///    <p>
		///	   This effect cannot be combined with other texture generation effects, 
		///	   such as environment mapping. It also has no effect on passes which 
		///	   have a vertex program enabled - projective texturing has to be done
		///	   in the vertex program instead.
		///    </p>
		/// </remarks>
		/// <param name="enable">
		///    Whether to enable / disable
		/// </param>
		/// <param name="projectionSettings">
		///    The Frustum which will be used to derive the projection parameters.
		/// </param>
		public void SetProjectiveTexturing( bool enable, Frustum projectionSettings )
		{
			if ( enable )
			{
				var effect = new TextureEffect();
				effect.type = TextureEffectType.ProjectiveTexture;
				effect.frustum = projectionSettings;
				AddEffect( effect );
			}
			else
			{
				RemoveEffect( TextureEffectType.ProjectiveTexture );
			}
		}
        /// <summary>
        ///		Sets up an animated scroll for the texture layer.
        /// </summary>
        /// <remarks>
        ///    Useful for creating constant scrolling effects on a texture layer (for varying scrolls, <see cref="SetTransformAnimation"/>).
        ///    <p/>
        ///    This option has no effect in the programmable pipeline.
        /// </remarks>
        /// <param name="uSpeed">The number of horizontal loops per second (+ve=moving right, -ve = moving left).</param>
        /// <param name="vSpeed">The number of vertical loops per second (+ve=moving up, -ve= moving down).</param>
        public void SetScrollAnimation(float uSpeed, float vSpeed)
        {
            TextureEffect effect = new TextureEffect();
            effect.type = TextureEffectType.Scroll;
            effect.arg1 = uSpeed;
            effect.arg2 = vSpeed;

            // add this effect to the list of effects for this texture stage.
            AddEffect(effect);
        }