Class representing an approach to rendering a particular Material.
The engine will attempt to use the best technique supported by the active hardware, unless you specifically request a lower detail technique (say for distant rendering)
Beispiel #1
0
        /// <summary>
        ///		Add a renderable to this group.
        /// </summary>
        /// <param name="renderable">Renderable to add to the queue.</param>
        /// <param name="technique"></param>
        public void AddRenderable(IRenderable renderable, Technique technique)
        {
            // Transparent and depth/colour settings mean depth sorting is required?
            // Note: colour write disabled with depth check/write enabled means
            //       setup depth buffer for other passes use.

            if (technique.IsTransparent && (!technique.DepthWrite || !technique.DepthCheck || technique.ColorWriteEnabled))
            {
                AddTransparentRenderable(technique, renderable);
            }
            else
            {
                if (this.splitNoShadowPasses && this._parent.ShadowsEnabled &&
                    (!technique.Parent.ReceiveShadows || renderable.CastsShadows && this.shadowCastersCannotBeReceivers))
                {
                    // Add solid renderable and add passes to no-shadow group
                    AddSolidRenderable(technique, renderable, true);
                }
                else
                {
                    if (this.splitPassesByLightingType && this._parent.ShadowsEnabled)
                    {
                        AddSolidRenderableSplitByLightType(technique, renderable);
                    }
                    else
                    {
                        AddSolidRenderable(technique, renderable, false);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///		Internal method for adding a solid renderable
        /// </summary>
        /// <param name="technique">Technique to use for this renderable.</param>
        /// <param name="renderable">Renderable to add to the queue.</param>
        /// <param name="noShadows">True to add to the no shadow group, false otherwise.</param>
        protected void AddSolidRenderable(Technique technique, IRenderable renderable, bool noShadows)
        {
            SortedList passMap = null;

            if (noShadows)
            {
                passMap = this.solidPassesNoShadow;
            }
            else
            {
                passMap = this.solidPasses;
            }

            for (var i = 0; i < technique.PassCount; i++)
            {
                var pass = technique.GetPass(i);

                if (passMap[pass] == null)
                {
                    // add a new list to hold renderables for this pass
                    passMap.Add(pass, new RenderableList());
                }

                // add to solid list for this pass
                var solidList = (RenderableList)passMap[pass];

                solidList.Add(renderable);
            }
        }
 /// <summary>
 ///		Internal method for adding a transparent renderable.
 /// </summary>
 /// <param name="technique">Technique to use for this renderable.</param>
 /// <param name="renderable">Renderable to add to the queue.</param>
 protected void AddTransparentRenderable(Technique technique, IRenderable renderable)
 {
     for (int i = 0; i < technique.NumPasses; i++)
     {
         // add to transparent list
         transparentPasses.Add(new RenderablePass(renderable, technique.GetPass(i)));
     }
 }
        /// <summary>
        ///    Clones this Technique.
        /// </summary>
        /// <param name="parent">Material that will own this technique.</param>
        /// <returns></returns>
        public Technique Clone(Material parent)
        {
            Technique newTechnique = new Technique(parent);

            CopyTo(newTechnique);

            return(newTechnique);
        }
        /// <summary>
        ///    Creates a new Technique for this Material.
        /// </summary>
        /// <remarks>
        ///    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.
        ///    <p/>
        ///    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.
        /// </remarks>
        /// <returns></returns>
        public Technique CreateTechnique()
        {
            Technique t = new Technique(this);

            techniques.Add(t);
            compilationRequired = true;
            return(t);
        }
 public void SetDepthBias(float constantBias, float slopeScaleBias)
 {
     for (int i = 0; i < techniques.Count; i++)
     {
         Technique technique = (Technique)techniques[i];
         technique.SetDepthBias(constantBias, slopeScaleBias);
     }
 }
Beispiel #7
0
 /// <summary>
 ///		Internal method for adding a transparent renderable.
 /// </summary>
 /// <param name="technique">Technique to use for this renderable.</param>
 /// <param name="renderable">Renderable to add to the queue.</param>
 protected void AddTransparentRenderable(Technique technique, IRenderable renderable)
 {
     for (var i = 0; i < technique.PassCount; i++)
     {
         // add to transparent list
         this.transparentPasses.Add(new RenderablePass(renderable, technique.GetPass(i)));
     }
 }
        /// <summary>
        ///    Removes the specified Technique from this material.
        /// </summary>
        /// <param name="t">A reference to the technique to remove</param>
        public void RemoveTechnique(Technique t)
        {
            Debug.Assert(t != null, "t != null");

            // remove from the list, and force a rebuild of supported techniques
            techniques.Remove(t);
            supportedTechniques.Clear();
            bestTechniquesByScheme.Clear();
            compilationRequired = true;
        }
Beispiel #9
0
 public RSQuadOperation(CompositorInstance instance, uint pass_id, Material mat)
 {
     this.mat      = mat;
     this.instance = instance;
     this.pass_id  = pass_id;
     mat.Load();
     instance.FireNotifyMaterialSetup(pass_id, mat);
     technique = mat.GetTechnique(0);
     Debug.Assert(technique != null);
 }
        public BspGeometry()
        {
            geometryMat = MaterialManager.Instance.GetByName("Axiom/BspGeometryMaterial");

            if (geometryMat == null)
            {
                geometryMat = (Material) MaterialManager.Instance.Create("Axiom/BspGeometryMaterial");
                geometryMat.ReceiveShadows = true;
                technique = geometryMat.GetTechnique(0);
            }
        }
 /// <summary>
 ///    Searches for the named technique.
 ///    Returns null  if technique with name is not found
 /// </summary>
 public Technique GetTechnique(string name)
 {
     for (int i = 0; i < techniques.Count; i++)
     {
         Technique t = (Technique)techniques[i];
         if (t.Name == name)
         {
             return(t);
         }
     }
     return(null);
 }
Beispiel #12
0
		public BspGeometry()
		{
			this.geometryMat = (Material)MaterialManager.Instance.GetByName( "Axiom/BspGeometryMaterial" );

			if ( this.geometryMat == null )
			{
				this.geometryMat =
					(Material)
					MaterialManager.Instance.Create( "Axiom/BspGeometryMaterial", ResourceGroupManager.Instance.WorldResourceGroupName );
				this.geometryMat.ReceiveShadows = true;
				this.technique = this.geometryMat.GetTechnique( 0 );
			}
		}
        /// <summary>
        ///		Applies texture names to Texture Unit State with matching texture name aliases.
        ///		All techniques, passes, and Texture Unit States within the material are checked.
        ///		If matching texture aliases are found then true is returned.
        /// </summary>
        /// <param name="aliasList">A map container of texture alias, texture name pairs.</param>
        /// <param name="apply">Set to true to apply the texture aliases else just test to see if texture alias matches are found.</param>
        /// <returns>True if matching texture aliases were found in the material.</returns>
        public bool ApplyTextureAliases(Dictionary <string, string> aliasList, bool apply)
        {
            bool testResult = false;

            // iterate through all techniques and apply texture aliases
            for (int i = 0; i < techniques.Count; i++)
            {
                Technique technique = (Technique)techniques[i];
                if (technique.ApplyTextureAliases(aliasList, apply))
                {
                    testResult = true;
                }
            }
            return(testResult);
        }
        /// <summary>
        ///		Insert a supported technique into the local
        ///     collections, if it's not already present. */
        /// </summary>
        protected void InsertSupportedTechnique(Technique t)
        {
            supportedTechniques.Add(t);
            // get scheme
            int schemeIndex = t.SchemeIndex;
            Dictionary <int, Technique> lodTechniques;

            if (!bestTechniquesByScheme.TryGetValue(schemeIndex, out lodTechniques))
            {
                lodTechniques = new Dictionary <int, Technique>();
                bestTechniquesByScheme[schemeIndex] = lodTechniques;
            }
            if (!lodTechniques.ContainsKey(t.LodIndex))
            {
                lodTechniques[t.LodIndex] = t;
            }
        }
        /// <summary>
        ///    'Compiles' this Material.
        /// </summary>
        /// <remarks>
        ///    Compiling a material involves determining which Techniques are supported on the
        ///    card on which the engine is currently running, and for fixed-function Passes within those
        ///    Techniques, splitting the passes down where they contain more TextureUnitState
        ///    instances than the curren card has texture units.
        ///    <p/>
        ///    This process is automatically done when the Material is loaded, but may be
        ///    repeated if you make some procedural changes.
        ///    <p/>
        ///    This method should be safe for use on threads other than the main render thread.
        /// </remarks>
        /// <param name="autoManageTextureUnits">
        ///    If true, when a fixed function pass has too many TextureUnitState
        ///    entries than the card has texture units, the Pass in question will be split into
        ///    more than one Pass in order to emulate the Pass. If you set this to false and
        ///    this situation arises, an Exception will be thrown.
        /// </param>
        public void Compile(bool autoManageTextureUnits)
        {
            // clear current list of supported techniques
            supportedTechniques.Clear();
            bestTechniquesByScheme.Clear();
            unsupportedReasons = "";
            string compileMessages = "";

            // compile each technique, adding supported ones to the list of supported techniques
            for (int i = 0; i < techniques.Count; i++)
            {
                Technique t = (Technique)techniques[i];

                // compile the technique, splitting texture passes if required
                compileMessages = t.Compile(autoManageTextureUnits);

                // if supported, add it to the list
                if (t.IsSupported)
                {
                    InsertSupportedTechnique(t);
                }
                else
                {
                    string s = "Material " + name + " Technique " + i;
                    if (t.Name != "")
                    {
                        s += " (" + t.Name + ")";
                    }
                    s += " is not supported.  " + compileMessages;
                    LogManager.Instance.Write(s);
                    unsupportedReasons = compileMessages;
                }
            }

            // TODO: Order best techniques

            compilationRequired = false;

            // Did we find any?
            if (supportedTechniques.Count == 0)
            {
                LogManager.Instance.Write("Warning: Material '{0}' has no supportable Techniques on this hardware.  Will be rendered blank.  Explanation: {1}",
                                          name, compileMessages);
            }
        }
        /// <summary>
        ///		Add a renderable to this group.
        /// </summary>
        /// <param name="renderable">Renderable to add to the queue.</param>
        public void AddRenderable(IRenderable renderable)
        {
            Technique t = null;

            // Check material & technique supplied (the former since the default implementation
            // of Technique is based on it for backwards compatibility
            if (renderable.Material == null || renderable.Technique == null)
            {
                // use default if not found
                t = MaterialManager.Instance.GetByName("BaseWhite").GetTechnique(0);
            }
            else
            {
                t = renderable.Technique;
            }

            // Transparent and depth settings mean depth sorting is required?
            if (t.IsTransparent && !(t.DepthWrite && t.DepthCheck))
            {
                AddTransparentRenderable(t, renderable);
            }
            else
            {
                if (splitNoShadowPasses &&
                    (!t.Parent.ReceiveShadows ||
                     renderable.CastsShadows && shadowCastersCannotBeReceivers))
                {
                    // Add solid renderable and add passes to no-shadow group
                    AddSolidRenderable(t, renderable, true);
                }
                else
                {
                    if (splitPassesByLightingType)
                    {
                        AddSolidRenderableSplitByLightType(t, renderable);
                    }
                    else
                    {
                        AddSolidRenderable(t, renderable, false);
                    }
                }
            }
        }
        /// <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>
        ///		Copy the details of this Technique to another.
        /// </summary>
        /// <param name="target"></param>
        public void CopyTo(Technique target)
        {
            target.name        = name;
            target.isSupported = isSupported;
            target.lodIndex    = lodIndex;
            target.schemeIndex = schemeIndex;

            target.RemoveAllPasses();

            // clone each pass and add that to the new technique
            for (int i = 0; i < passes.Count; i++)
            {
                Pass pass    = (Pass)passes[i];
                Pass newPass = pass.Clone(target, pass.Index);
                target.passes.Add(newPass);
            }

            // Compile for categorised illumination on demand
            target.ClearIlluminationPasses();
            target.illuminationPassesCompilationPhase = IlluminationPassesState.NotCompiled;
        }
Beispiel #19
0
        /// <summary>
        /// </summary>
        public void AddRenderable(IRenderable item, Technique technique, ushort priority)
        {
            RenderPriorityGroup group = null;

            // see if there is a current queue group for this group id
            if (!PriorityGroups.ContainsKey(priority))
            {
                // create a new queue group for this group id
                group = new RenderPriorityGroup(this, this.splitPassesByLightingType, this.splitNoShadowPasses,
                                                this.splitPassesByLightingType);

                // add the new group to cached render group
                PriorityGroups.Add(priority, group);
            }
            else
            {
                // retreive the existing queue group
                group = PriorityGroups[priority];
            }

            // add the renderable to the appropriate group
            group.AddRenderable(item, technique);
        }
Beispiel #20
0
        /// <summary>
        ///		Internal method for adding a solid renderable ot the group based on lighting stage.
        /// </summary>
        /// <param name="technique">Technique to use for this renderable.</param>
        /// <param name="renderable">Renderable to add to the queue.</param>
        protected void AddSolidRenderableSplitByLightType(Technique technique, IRenderable renderable)
        {
            // Divide the passes into the 3 categories
            for (var i = 0; i < technique.IlluminationPassCount; i++)
            {
                // Insert into solid list
                var        illpass = technique.GetIlluminationPass(i);
                SortedList passMap = null;

                switch (illpass.Stage)
                {
                case IlluminationStage.Ambient:
                    passMap = this.solidPasses;
                    break;

                case IlluminationStage.PerLight:
                    passMap = this.solidPassesDiffuseSpecular;
                    break;

                case IlluminationStage.Decal:
                    passMap = this.solidPassesDecal;
                    break;
                }

                var solidList = (RenderableList)passMap[illpass.Pass];

                if (solidList == null)
                {
                    // add a new list to hold renderables for this pass
                    solidList = new RenderableList();
                    passMap.Add(illpass.Pass, solidList);
                }

                solidList.Add(renderable);
            }
        }
Beispiel #21
0
		/// <summary>
		/// </summary>
		public void AddRenderable( IRenderable item, Technique technique, ushort priority )
		{
			RenderPriorityGroup group = null;

			// see if there is a current queue group for this group id
			if ( !PriorityGroups.ContainsKey( priority ) )
			{
				// create a new queue group for this group id
				group = new RenderPriorityGroup( this, this.splitPassesByLightingType, this.splitNoShadowPasses,
				                                 this.splitPassesByLightingType );

				// add the new group to cached render group
				PriorityGroups.Add( priority, group );
			}
			else
			{
				// retreive the existing queue group
				group = PriorityGroups[ priority ];
			}

			// add the renderable to the appropriate group
			group.AddRenderable( item, technique );
		}
        /// <summary>
        ///		Internal method for adding a solid renderable
        /// </summary>
        /// <param name="technique">Technique to use for this renderable.</param>
        /// <param name="renderable">Renderable to add to the queue.</param>
        /// <param name="noShadows">True to add to the no shadow group, false otherwise.</param>
        protected void AddSolidRenderable(Technique technique, IRenderable renderable, bool noShadows)
        {
            SortedList passMap = null;

            if(noShadows)
            {
                passMap = solidPassesNoShadow;
            }
            else
            {
                passMap = solidPasses;
            }

            for(int i = 0; i < technique.NumPasses; i++)
            {
                Pass pass = technique.GetPass(i);

                if(passMap[pass] == null)
                {
                    // add a new list to hold renderables for this pass
                    passMap.Add(pass, new RenderableList());
                }

                // add to solid list for this pass
                RenderableList solidList = (RenderableList)passMap[pass];

                solidList.Add(renderable);
            }
        }
 /// <summary>
 ///		Insert a supported technique into the local
 ///     collections, if it's not already present. */
 /// </summary>
 protected void InsertSupportedTechnique(Technique t)
 {
     supportedTechniques.Add(t);
     // get scheme
     int schemeIndex = t.SchemeIndex;
     Dictionary<int, Technique> lodTechniques;
     if (!bestTechniquesByScheme.TryGetValue(schemeIndex, out lodTechniques)) {
         lodTechniques = new Dictionary<int, Technique>();
         bestTechniquesByScheme[schemeIndex] = lodTechniques;
     }
     if (!lodTechniques.ContainsKey(t.LodIndex))
         lodTechniques[t.LodIndex] = t;
 }
Beispiel #24
0
		/// <summary>
		///    Clones this Technique.
		/// </summary>
		/// <param name="parent">Material that will own this technique.</param>
		/// <returns></returns>
		public Technique Clone( Material parent )
		{
			Technique newTechnique = new Technique( parent );

			CopyTo( newTechnique );

			return newTechnique;
		}
Beispiel #25
0
		/// <summary>
		///		Copy the details of this Technique to another.
		/// </summary>
		/// <param name="target"></param>
		public void CopyTo( Technique target )
		{
			target._isSupported = _isSupported;
			target.SchemeIndex = SchemeIndex;
			target._lodIndex = _lodIndex;

			target.RemoveAllPasses();

			// clone each pass and add that to the new technique
			for ( int i = 0; i < _passes.Count; i++ )
			{
				Pass pass = _passes[ i ];
				Pass newPass = pass.Clone( target, pass.Index );
				target._passes.Add( newPass );
			}

			// Compile for categorized illumination on demand
			ClearIlluminationPasses();
			_illuminationPassesCompilationPhase = IlluminationPassesCompilationPhase.NotCompiled;

		}
 /// <summary>
 ///		Internal method for adding a transparent renderable.
 /// </summary>
 /// <param name="technique">Technique to use for this renderable.</param>
 /// <param name="renderable">Renderable to add to the queue.</param>
 protected void AddTransparentRenderable(Technique technique, IRenderable renderable)
 {
     for(int i = 0; i < technique.NumPasses; i++)
     {
         // add to transparent list
         transparentPasses.Add(new RenderablePass(renderable, technique.GetPass(i)));
     }
 }
Beispiel #27
0
 /// <summary>
 ///    Default constructor.
 /// </summary>
 /// <param name="parent">Technique that owns this Pass.</param>
 /// <param name="index">Index of this pass.</param>
 public XnaPass( Technique parent, int index )
     : base( parent, index )
 {
 }
        /// <summary>
        ///		Copy the details of this Technique to another.
        /// </summary>
        /// <param name="target"></param>
        public void CopyTo(Technique target)
        {
            target.name = name;
            target.isSupported = isSupported;
            target.lodIndex = lodIndex;
            target.schemeIndex = schemeIndex;

            target.RemoveAllPasses();

            // clone each pass and add that to the new technique
            for(int i = 0; i < passes.Count; i++) {
                Pass pass = (Pass)passes[i];
                Pass newPass = pass.Clone(target, pass.Index);
                target.passes.Add(newPass);
            }

            // Compile for categorised illumination on demand
            target.ClearIlluminationPasses();
            target.illuminationPassesCompilationPhase = IlluminationPassesState.NotCompiled;
        }
        /// <summary>
        ///    Removes the specified Technique from this material.
        /// </summary>
        /// <param name="t">A reference to the technique to remove</param>
        public void RemoveTechnique(Technique t)
        {
            Debug.Assert(t != null, "t != null");

            // remove from the list, and force a rebuild of supported techniques
            techniques.Remove(t);
            supportedTechniques.Clear();
            bestTechniquesByScheme.Clear();
            compilationRequired = true;
        }
Beispiel #30
0
		/// <summary>
		///    Removes the specified Technique from this material.
		/// </summary>
		/// <param name="t">A reference to the technique to remove</param>
		/// <ogre name="removeTechnique" />
		public void RemoveTechnique( Technique t )
		{
			Debug.Assert( t != null, "t != null" );

			// remove from the list, and force a rebuild of supported techniques
			this.techniques.Remove( t );
			this.SupportedTechniques.Clear();
			this.ClearBestTechniqueList();
			this._compilationRequired = true;
		}
Beispiel #31
0
		/// <summary>
		///    Default constructor.
		/// </summary>
		/// <param name="parent">Technique that owns this Pass.</param>
		/// <param name="index">Index of this pass.</param>
		public Pass( Technique parent, int index )
		{
			this._parent = parent;
			this._index = index;

			lock ( passLock )
			{
				this.passId = nextPassId++;
			}

			// color defaults
			_ambient = ColorEx.White;
			_diffuse = ColorEx.White;
			_specular = ColorEx.Black;
			_emissive = ColorEx.Black;

			// by default, don't override the scene's fog settings
			_fogOverride = false;
			_fogMode = FogMode.None;
			_fogColor = ColorEx.White;
			_fogStart = 0;
			_fogEnd = 1;
			_fogDensity = 0.001f;

			// default blending (overwrite)
			_sourceBlendFactor = SceneBlendFactor.One;
			_destinationBlendFactor = SceneBlendFactor.Zero;



			// depth buffer settings
			_depthCheck = true;
			_depthWrite = true;
			_colorWriteEnabled = true;
			_depthFunction = CompareFunction.LessEqual;

			// cull settings
			_cullingMode = CullingMode.Clockwise;
			_manualCullingMode = ManualCullingMode.Back;

			// light settings
			_lightingEnabled = true;
			_runOnlyForOneLightType = true;
			_onlyLightType = LightType.Point;
			_shadingMode = Shading.Gouraud;

			// Default max lights to the global max
			_maxSimultaneousLights = Config.MaxSimultaneousLights;

			_name = index.ToString();

            IterationCount = 1;

			DirtyHash();
		}
Beispiel #32
0
			/// <see cref="Translator.Translate"/>
			public override void Translate( ScriptCompiler compiler, AbstractNode node )
			{
				ObjectAbstractNode obj = (ObjectAbstractNode)node;

				// Create the technique from the material
				Material material = (Material)obj.Parent.Context;
				_technique = material.CreateTechnique();
				obj.Context = _technique;

				// Get the name of the technique
				if ( !string.IsNullOrEmpty( obj.Name ) )
					_technique.Name = obj.Name;

				// Set the properties for the technique
				foreach ( AbstractNode i in obj.Children )
				{
					if ( i is PropertyAbstractNode )
					{
						PropertyAbstractNode prop = (PropertyAbstractNode)i;

						switch ( (Keywords)prop.Id )
						{
							#region ID_SCHEME
							case Keywords.ID_SCHEME:
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
								}
								else if ( prop.Values.Count > 1 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line,
										"scheme only supports 1 argument" );
								}
								else
								{
									string scheme;
									if ( getString( prop.Values[ 0 ], out scheme ) )
										_technique.Scheme = scheme;
									else
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
											"scheme must have 1 string argument" );
								}
								break;
							#endregion ID_SCHEME

							#region ID_LOD_INDEX
							case Keywords.ID_LOD_INDEX:
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
								}
								else if ( prop.Values.Count > 1 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line,
										"lod_index only supports 1 argument" );
								}
								else
								{
									int val;
									if ( getInt( prop.Values[ 0 ], out val ) )
										_technique.LodIndex = val;
									else
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
											"lod_index cannot accept argument \"" + prop.Values[ 0 ].Value + "\"" );
								}
								break;
							#endregion ID_LOD_INDEX

							#region ID_SHADOW_CASTER_MATERIAL
							case Keywords.ID_SHADOW_CASTER_MATERIAL:
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
								}
								else if ( prop.Values.Count > 1 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line,
										"shadow_caster_material only accepts 1 argument" );
								}
								else
								{
									string matName;
									if ( getString( prop.Values[ 0 ], out matName ) )
									{
										string evtMatName = string.Empty;

										ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent(
											ProcessResourceNameScriptCompilerEvent.ResourceType.Material, matName );

										compiler._fireEvent( ref evt );
										evtMatName = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name;
										_technique.ShadowCasterMaterial = (Material)MaterialManager.Instance[ evtMatName ]; // Use the processed name
									}
									else
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
											"shadow_caster_material cannot accept argument \"" + prop.Values[ 0 ].Value + "\"" );
								}
								break;
							#endregion ID_SHADOW_CASTER_MATERIAL

							#region ID_SHADOW_RECEIVER_MATERIAL
							case Keywords.ID_SHADOW_RECEIVER_MATERIAL:
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
								}
								else if ( prop.Values.Count > 1 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line,
										"shadow_receiver_material only accepts 1 argument" );
								}
								else
								{
									AbstractNode i0 = getNodeAt( prop.Values, 0 );
									string matName = string.Empty;
									if ( getString( i0, out matName ) )
									{
										string evtName = string.Empty;

										ScriptCompilerEvent evt = new ProcessResourceNameScriptCompilerEvent(
											ProcessResourceNameScriptCompilerEvent.ResourceType.Material, matName );

										compiler._fireEvent( ref evt );
										evtName = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name;
										_technique.ShadowReceiverMaterial = (Material)MaterialManager.Instance[ evtName ];
									}
									else
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
											"shadow_receiver_material_name cannot accept argument \"" + i0.Value + "\"" );
								}
								break;
							#endregion ID_SHADOW_RECEIVER_MATERIAL

							#region ID_GPU_VENDOR_RULE
							case Keywords.ID_GPU_VENDOR_RULE:
								if ( prop.Values.Count < 2 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line,
										"gpu_vendor_rule must have 2 arguments" );
								}
								else if ( prop.Values.Count > 2 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line,
										"gpu_vendor_rule must have 2 arguments" );
								}
								else
								{
									AbstractNode i0 = getNodeAt( prop.Values, 0 );
									AbstractNode i1 = getNodeAt( prop.Values, 1 );

									Technique.GPUVendorRule rule = new Technique.GPUVendorRule();
									if ( i0 is AtomAbstractNode )
									{
										AtomAbstractNode atom0 = (AtomAbstractNode)i0;
										Keywords atom0Id = (Keywords)atom0.Id;

										if ( atom0Id == Keywords.ID_INCLUDE )
										{
											rule.Include = true;
										}
										else if ( atom0Id == Keywords.ID_EXCLUDE )
										{
											rule.Include = false;
										}
										else
										{
											compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
												"gpu_vendor_rule cannot accept \"" + i0.Value + "\" as first argument" );
										}

										string vendor = string.Empty;
										if ( !getString( i1, out vendor ) )
										{
											compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
												"gpu_vendor_rule cannot accept \"" + i1.Value + "\" as second argument" );
										}

										rule.Vendor = RenderSystemCapabilities.VendorFromString( vendor );

										if ( rule.Vendor != GPUVendor.Unknown )
										{
											_technique.AddGPUVenderRule( rule );
										}
									}
									else
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
											"gpu_vendor_rule cannot accept \"" + i0.Value + "\" as first argument" );
									}
								}
								break;
							#endregion ID_GPU_VENDOR_RULE

							#region ID_GPU_DEVICE_RULE
							case Keywords.ID_GPU_DEVICE_RULE:
								if ( prop.Values.Count < 2 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line,
										"gpu_device_rule must have at least 2 arguments" );
								}
								else if ( prop.Values.Count > 3 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line,
										"gpu_device_rule must have at most 3 arguments" );
								}
								else
								{
									AbstractNode i0 = getNodeAt( prop.Values, 0 );
									AbstractNode i1 = getNodeAt( prop.Values, 1 );

									Technique.GPUDeviceNameRule rule = new Technique.GPUDeviceNameRule();
									if ( i0 is AtomAbstractNode )
									{
										AtomAbstractNode atom0 = (AtomAbstractNode)i0;
										Keywords atom0Id = (Keywords)atom0.Id;

										if ( atom0Id == Keywords.ID_INCLUDE )
										{
											rule.Include = true;
										}
										else if ( atom0Id == Keywords.ID_EXCLUDE )
										{
											rule.Include = false;
										}
										else
										{
											compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
												"gpu_device_rule cannot accept \"" + i0.Value + "\" as first argument" );
										}

										if ( !getString( i1, out rule.DevicePattern ) )
										{
											compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
												"gpu_device_rule cannot accept \"" + i1.Value + "\" as second argument" );
										}

										if ( prop.Values.Count == 3 )
										{
											AbstractNode i2 = getNodeAt( prop.Values, 2 );
											if ( !getBoolean( i2, out rule.CaseSensitive ) )
											{
												compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
													"gpu_device_rule third argument must be \"true\", \"false\", \"yes\", \"no\", \"on\", or \"off\"" );
											}
										}

										_technique.AddGPUDeviceNameRule( rule );
									}
									else
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
											"gpu_device_rule cannot accept \"" + i0.Value + "\" as first argument" );
									}
								}
								break;
							#endregion ID_GPU_DEVICE_RULE

							default:
								compiler.AddError( CompileErrorCode.UnexpectedToken, prop.File, prop.Line, "token \"" + prop.Name + "\" is not recognized" );
								break;

						} //end of switch statement
					} // end of if ( i is PropertyAbstractNode )
					else if ( i is ObjectAbstractNode )
					{
						_processNode( compiler, i );
					}
				}
			}
 /// <summary>
 ///    Creates a new Technique for this Material.
 /// </summary>
 /// <remarks>
 ///    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.
 ///    <p/>    
 ///    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.
 /// </remarks>
 /// <returns></returns>
 public Technique CreateTechnique()
 {
     Technique t = new Technique(this);
     techniques.Add(t);
     compilationRequired = true;
     return t;
 }
 public RSQuadOperation(CompositorInstance instance, uint pass_id, Material mat)
 {
     this.mat = mat;
     this.instance = instance;
     this.pass_id = pass_id;
     mat.Load();
     instance.FireNotifyMaterialSetup(pass_id, mat);
     technique = mat.GetTechnique(0);
     Debug.Assert(technique != null);
 }
			/// <summary>
			///   Add children to the render queue
			/// </summary>
			/// <param name="queue"> </param>
			/// <param name="group"> </param>
			/// <param name="camSquaredDistance"> </param>
			public void AddRenderables( RenderQueue queue, RenderQueueGroupID group, float camSquaredDistance )
			{
				// Determine the current material technique
				mTechnique = mMaterial.GetBestTechnique( mMaterial.GetLodIndex( camSquaredDistance ) );
				foreach ( GeometryBucket iter in mGeometryBucketList )
				{
					queue.AddRenderable( iter, group );
				}
			}
Beispiel #36
0
			public void AddRenderables( RenderQueue queue, RenderQueueGroupID group, Real lodValue )
			{
				// Get batch instance
#warning OGRE-1.6 BatchInstance Implementation
				//BatchInstance batchInstance = Parent.Parent;

				// Get material lod strategy
				var materialLodStrategy = Material.LodStrategy;

				// If material strategy doesn't match, recompute lod value with correct strategy
#warning OGRE-1.6 BatchInstance Implementation needed
				//if ( materialLodStrategy != batchInstance.LodStrategy )
				//    lodValue = materialLodStrategy.GetValue( batchInstance, batchInstance.Camera );

				// determine the current material technique
				this.technique = this.material.GetBestTechnique( this.material.GetLodIndex( lodValue ) );
				foreach ( var gbucket in this.geometryBucketList )
				{
					queue.AddRenderable( gbucket, RenderQueue.DEFAULT_PRIORITY, group );
				}
			}
Beispiel #37
0
			public TechniqueTranslator()
				: base()
			{
				_technique = null;
			}
        /// <summary>
        ///		Internal method for adding a solid renderable ot the group based on lighting stage.
        /// </summary>
        /// <param name="technique">Technique to use for this renderable.</param>
        /// <param name="renderable">Renderable to add to the queue.</param>
        protected void AddSolidRenderableSplitByLightType(Technique technique, IRenderable renderable)
        {
            // Divide the passes into the 3 categories
            for (int i = 0; i < technique.IlluminationPassCount; i++)
            {
                // Insert into solid list
                IlluminationPass illpass = technique.GetIlluminationPass(i);
                SortedList passMap = null;

                switch(illpass.Stage)
                {
                    case IlluminationStage.Ambient:
                        passMap = solidPasses;
                        break;
                    case IlluminationStage.PerLight:
                        passMap = solidPassesDiffuseSpecular;
                        break;
                    case IlluminationStage.Decal:
                        passMap = solidPassesDecal;
                        break;
                }

                RenderableList solidList = (RenderableList)passMap[illpass.Pass];

                if(solidList == null)
                {
                    // add a new list to hold renderables for this pass
                    solidList = new RenderableList();
                    passMap.Add(illpass.Pass, solidList);
                }

                solidList.Add(renderable);
            }
        }
 public void AddRenderables(RenderQueue queue, RenderQueueGroupID group, float camDistanceSquared)
 {
     if (material != null) {
         // determine the current material technique
         technique = material.GetBestTechnique(material.GetLodIndexSquaredDepth(camDistanceSquared));
         foreach (GeometryBucket gbucket in geometryBucketList)
             queue.AddRenderable(gbucket, RenderQueue.DEFAULT_PRIORITY, group);
     }
 }
        /// <summary>
        ///    Default constructor.
        /// </summary>
        /// <param name="parent">Technique that owns this Pass.</param>
        /// <param name="index">Index of this pass.</param>
        public Pass(Technique parent, int index)
        {
            this.parent = parent;
            this.index = index;

            lock (passLock) {
                this.passId = nextPassId++;
            }

            // color defaults
            ambient = ColorEx.White;
            diffuse = ColorEx.White;
            specular = ColorEx.Black;
            emissive = ColorEx.Black;

            // by default, don't override the scene's fog settings
            fogOverride = false;
            fogMode = FogMode.None;
            fogColor = ColorEx.White;
            fogStart = 0;
            fogEnd = 1;
            fogDensity = 0.001f;

            // default blending (overwrite)
            sourceBlendFactor = SceneBlendFactor.One;
            destBlendFactor = SceneBlendFactor.Zero;

            // depth buffer settings
            depthCheck = true;
            depthWrite = true;
            colorWrite = true;
            alphaRejectFunction = CompareFunction.AlwaysPass;
            alphaRejectValue = 0;
            depthFunc = CompareFunction.LessEqual;

            depthBiasConstant = 0f;
            depthBiasSlopeScale = 0f;

            // cull settings
            cullMode = CullingMode.Clockwise;
            manualCullMode = ManualCullingMode.Back;

            // light settings
            lightingEnabled = true;
            runOnlyForOneLightType = true;
            lightsPerIteration = 1;
            runOncePerLight = false;
            onlyLightType = LightType.Point;
            shadeOptions = Shading.Gouraud;

            // Default max lights to the global max
            maxLights = Config.MaxSimultaneousLights;

            // Starting light index
            startLight = 0;

            // Default to solid
            sceneDetail = SceneDetailLevel.Solid;

            // Iteration count of 1
            passIterationCount = 1;

            // pointSize, etc.
            pointSize = 1.0f;
            pointMinSize = 0f;
            pointMaxSize = 0f;
            pointSpritesEnabled = false;
            pointAttenuationEnabled = false;
            pointAttenuationConstant = 1.0f;
            pointAttenuationLinear = 0f;
            pointAttenuationQuadratic = 0f;

            contentTypeLookupBuilt = false;

            name = index.ToString();

            DirtyHash();
        }
Beispiel #41
0
	    /// <summary>
	    ///    Method for cloning a Pass object.
	    /// </summary>
	    /// <param name="parent">Parent technique that will own this cloned Pass.</param>
	    /// <param name="index"></param>
	    /// <returns></returns>
	    public Pass Clone( Technique parent, int index )
		{
			Pass newPass = new Pass( parent, index );

			CopyTo( newPass );

			// dirty the hash on the new pass
			newPass.DirtyHash();

			return newPass;
		}
Beispiel #42
0
		private void InsertSupportedTechnique( Technique technique )
		{
			this.SupportedTechniques.Add( technique );
			// get scheme
			ushort schemeIndex = technique.SchemeIndex;
			Dictionary<int, Technique> lodTechniques;
			if ( !this.bestTechniquesByScheme.ContainsKey( schemeIndex ) )
			{
				lodTechniques = new Dictionary<int, Technique>();
				this.bestTechniquesByScheme.Add( schemeIndex, lodTechniques );
			}
			else
			{
				lodTechniques = this.bestTechniquesByScheme[ schemeIndex ];
			}

			// Insert won't replace if supported technique for this scheme/lod is
			// already there, which is what we want
			if ( !lodTechniques.ContainsKey( technique.LodIndex ) )
			{
				lodTechniques.Add( technique.LodIndex, technique );
			}
		}