CreateTechnique() public method

Creates a new Technique for this Material.
A Technique is a single way of rendering geometry in order to achieve the effect you are intending in a material. There are many reason why you would want more than one - the main one being to handle variable graphics card abilities; you might have one technique which is impressive but only runs on 4th-generation graphics cards, for example. In this case you will want to create at least one fallback Technique. The engine will work out which Techniques a card can support and pick the best one.

If multiple Techniques are available, the order in which they are created is important - the engine will consider lower-indexed Techniques to be preferable to higher-indexed Techniques, ie when asked for the 'best' technique it will return the first one in the technique list which is supported by the hardware.

public CreateTechnique ( ) : Technique
return Technique
Ejemplo n.º 1
0
        /// <summary>
        ///		Copies the details of this material into another, preserving the target's handle and name
        ///		(unlike operator=) but copying everything else.
        /// </summary>
        /// <param name="target">Material which will receive this material's settings.</param>
        public void CopyTo(Material target, bool copyUniqueInfo)
        {
            if (copyUniqueInfo)
            {
                target.name     = name;
                target.handle   = handle;
                target.isLoaded = isLoaded;
                target.isManual = isManual;
            }
            // copy basic data
            target.size                     = size;
            target.lastAccessed             = lastAccessed;
            target.receiveShadows           = receiveShadows;
            target.transparencyCastsShadows = transparencyCastsShadows;

            target.RemoveAllTechniques();

            // clone a copy of all the techniques
            for (int i = 0; i < techniques.Count; i++)
            {
                Technique technique    = (Technique)techniques[i];
                Technique newTechnique = target.CreateTechnique();
                technique.CopyTo(newTechnique);

                // only add this technique to supported techniques if its...well....supported :-)
                if (newTechnique.IsSupported)
                {
                    target.InsertSupportedTechnique(newTechnique);
                }
            }

            // clear LOD distances
            target.lodDistances.Clear();

            // copy LOD distances
            for (int i = 0; i < lodDistances.Count; i++)
            {
                target.lodDistances.Add(lodDistances[i]);
            }

            target.compilationRequired = compilationRequired;
        }
			/// <summary>
			/// 
			/// </summary>
			/// <param name="mat"></param>
			/// <param name="terrain"></param>
			/// <param name="tt"></param>
			protected void AddTechnique( Material mat, Terrain terrain, TechniqueType tt )
			{
				string ttStr = string.Empty;
				switch ( tt )
				{
					case TechniqueType.HighLod:
						ttStr += "hl";
						break;
					case TechniqueType.LowLod:
						ttStr += "ll";
						break;
					case TechniqueType.RenderCompositeMap:
						ttStr += "rc";
						break;
				}
				LogManager.Instance.Write( "AddTechique:" + ttStr, null );

				Technique tech = mat.CreateTechnique();

				//only supporting one pass
				Pass pass = tech.CreatePass();

				GpuProgramManager gmgr = GpuProgramManager.Instance;
				HighLevelGpuProgramManager hmgr = HighLevelGpuProgramManager.Instance;

				if ( this.mShaderGen == null )
				{
					bool check2x = this.mLayerNormalMappingEnabled || this.mLayerParallaxMappingEnabled;

					/* if (hmgr.IsLanguageSupported("cg") &&
                         (check2x && (gmgr.IsSyntaxSupported("fp40") || gmgr.IsSyntaxSupported("ps_2_x"))) ||
                         (gmgr.IsSyntaxSupported("ps_2_0")))
                         mShaderGen = new ShaderHelperCG();
                     else*/
					if ( hmgr.IsLanguageSupported( "hlsl" ) )
					{
						this.mShaderGen = new ShaderHelperHLSL();
					}
					else if ( hmgr.IsLanguageSupported( "glsl" ) )
					{
						this.mShaderGen = new ShaderHelperGLSL();
					}
					else
					{
						//TODO
					}
				}
				HighLevelGpuProgram vprog = this.mShaderGen.GenerateVertexProgram( this, terrain, tt );
				HighLevelGpuProgram fprog = this.mShaderGen.GenerateFragmentProgram( this, terrain, tt );

				pass.SetVertexProgram( vprog.Name );
				pass.SetFragmentProgram( fprog.Name );

				if ( tt == TechniqueType.HighLod || tt == TechniqueType.RenderCompositeMap )
				{
					//global normal map
					TextureUnitState tu = pass.CreateTextureUnitState();
					tu.SetTextureName( terrain.TerrainNormalMap.Name );
					tu.SetTextureAddressingMode( TextureAddressing.Clamp );

					//global color map
					if ( terrain.IsGlobalColorMapEnabled && IsGlobalColorMapEnabled )
					{
						tu = pass.CreateTextureUnitState( terrain.GlobalColorMap.Name );
						tu.SetTextureAddressingMode( TextureAddressing.Clamp );
					}

					//light map
					if ( IsLightMapEnabled )
					{
						tu = pass.CreateTextureUnitState( terrain.LightMap.Name );
						tu.SetTextureAddressingMode( TextureAddressing.Clamp );
					}

					//blend maps
					uint maxLayers = GetMaxLayers( terrain );

					uint numBlendTextures = Utility.Min( terrain.GetBlendTextureCount( (byte)maxLayers ),
					                                     terrain.GetBlendTextureCount() );
					uint numLayers = Utility.Min( maxLayers, (uint)terrain.LayerCount );
					for ( uint i = 0; i < numBlendTextures; ++i )
					{
						tu = pass.CreateTextureUnitState( terrain.GetBlendTextureName( (byte)i ) );
						tu.SetTextureAddressingMode( TextureAddressing.Clamp );
					}

					//layer textures
					for ( uint i = 0; i < numLayers; ++i )
					{
						//diffuse / specular
						string name = terrain.GetLayerTextureName( (byte)i, 0 );
						tu = pass.CreateTextureUnitState( terrain.GetLayerTextureName( (byte)i, 0 ) );
						//normal / height
						tu = pass.CreateTextureUnitState( terrain.GetLayerTextureName( (byte)i, 1 ) );
					}
				} //end if
				else if ( this.mCompositeMapEnabled )
				{
					// LOW_LOD textures
					// composite map
					TextureUnitState tu = pass.CreateTextureUnitState();
					tu.SetTextureName( terrain.CompositeMap.Name );
					tu.SetTextureAddressingMode( TextureAddressing.Clamp );


					// That's it!
				}
			}
Ejemplo n.º 3
0
        /// <summary>
        ///		Copies the details of this material into another, preserving the target's handle and name
        ///		(unlike operator=) but copying everything else.
        /// </summary>
        /// <param name="target">Material which will receive this material's settings.</param>
        public void CopyTo(Material target, bool copyUniqueInfo)
        {
            if(copyUniqueInfo) {
                target.name = name;
                target.handle = handle;
                target.isLoaded = isLoaded;
                target.isManual = isManual;
            }
            // copy basic data
            target.size = size;
            target.lastAccessed = lastAccessed;
            target.receiveShadows = receiveShadows;
            target.transparencyCastsShadows = transparencyCastsShadows;

            target.RemoveAllTechniques();

            // clone a copy of all the techniques
            for(int i = 0; i < techniques.Count; i++) {
                Technique technique = (Technique)techniques[i];
                Technique newTechnique = target.CreateTechnique();
                technique.CopyTo(newTechnique);

                // only add this technique to supported techniques if its...well....supported :-)
                if(newTechnique.IsSupported)
                    target.InsertSupportedTechnique(newTechnique);
            }

            // clear LOD distances
            target.lodDistances.Clear();

            // copy LOD distances
            for(int i = 0; i < lodDistances.Count; i++) {
                target.lodDistances.Add(lodDistances[i]);
            }

            target.compilationRequired = compilationRequired;
        }
Ejemplo n.º 4
0
		/// <param name="target"></param>
		/// <param name="copyUniqueInfo">preserves the target's handle, group, name, and loading properties (unlike operator=) but copying everything else.</param>
		public void CopyTo( Material target, bool copyUniqueInfo )
		{
			if ( copyUniqueInfo )
			{
				target.Name = this.Name;
				target.Handle = this.Handle;
				target.Group = this.Group;
				target.IsManuallyLoaded = this.IsManuallyLoaded;
				target.loader = this.loader;
			}

			// copy basic data
			target.Size = this.Size;
			target.LastAccessed = this.LastAccessed;
			target.ReceiveShadows = this.ReceiveShadows;
			target.TransparencyCastsShadows = this.TransparencyCastsShadows;

			target.RemoveAllTechniques();

			// clone a copy of all the techniques
			for ( int i = 0; i < this.techniques.Count; i++ )
			{
				Technique technique = this.techniques[ i ];
				Technique newTechnique = target.CreateTechnique();
				technique.CopyTo( newTechnique );

				// only add this technique to supported techniques if its...well....supported :-)
				if ( newTechnique.IsSupported )
				{
					target.InsertSupportedTechnique( newTechnique );
				}
			}

			// clear LOD distances
			target._lodValues.Clear();
			target.UserLodValues.Clear();

			// copy LOD distances
			target._lodValues.AddRange( this._lodValues );
			target.UserLodValues.AddRange( this.UserLodValues );

			target.LodStrategy = this.LodStrategy;

			target.compilationRequired = this.compilationRequired;
		}