Base composition technique, can be subclassed in plugins.
Inheritance: DisposableObject
Example #1
0
        /// <summary>
        /// Create "default compositor"
        /// </summary>
        protected void CreateOriginalScene()
        {
            this.originalSceneMaterial = this.viewport.MaterialScheme;
            string compName = "Axiom/Scene/" + this.originalSceneMaterial;
            var    scene    = (Compositor)CompositorManager.Instance.GetByName(compName);

            if (scene == null)
            {
                scene = (Compositor)CompositorManager.Instance.Create(compName, ResourceGroupManager.InternalResourceGroupName);
                CompositionTechnique t = scene.CreateTechnique();
                t.SchemeName = string.Empty;
                CompositionTargetPass tp = t.OutputTarget;
                tp.VisibilityMask = 0xFFFFFFFF;

                {
                    CompositionPass pass = tp.CreatePass();
                    pass.Type = CompositorPassType.Clear;
                }
                {
                    CompositionPass pass = tp.CreatePass();
                    pass.Type = CompositorPassType.RenderScene;
                    //Render everything, including skies
                    pass.FirstRenderQueue = RenderQueueGroupID.Background;
                    pass.LastRenderQueue  = RenderQueueGroupID.SkiesLate;
                }

                scene = (Compositor)CompositorManager.Instance.Load(compName, ResourceGroupManager.InternalResourceGroupName);
            }


            this.originalScene = new CompositorInstance(scene.GetSupportedTechniqueByScheme(), this);
        }
Example #2
0
        ///<summary>
        ///    Apply a compositor. Initially, the filter is enabled.
        ///</summary>
        ///<param name="filter">Filter to apply</param>
        ///<param name="addPosition">Position in filter chain to insert this filter at; defaults to the end (last applied filter)</param>
        ///<param name="technique">Technique to use; CompositorChain::BEST (default) chooses to the best one
        ///                        available (first technique supported)
        ///</param>
        ///<param name="scheme"></param>
        private CompositorInstance AddCompositor(Compositor filter, int addPosition, int technique, string scheme)
        {
            filter.Touch();
            CompositionTechnique tech = filter.GetSupportedTechniqueByScheme(scheme);

            if (tech == null)
            {
                LogManager.Instance.DefaultLog.Write("CompositorChain: Compositor " + filter.Name + " has no supported techniques.");
            }
            var t = new CompositorInstance(tech, this);

            if (addPosition == lastCompositor)
            {
                addPosition = this.instances.Count;
            }
            else
            {
                Debug.Assert(addPosition <= this.instances.Count, "Index out of bounds.");
            }
            this.instances.Insert(addPosition, t);

            this.dirty = true;
            this.anyCompositorsEnabled = true;

            return(t);
        }
Example #3
0
        ///<summary>
        /// Create a new technique, and return a pointer to it.
        ///</summary>
        public CompositionTechnique CreateTechnique()
        {
            var t = new CompositionTechnique(this);

            this.techniques.Add(t);
            this.compilationRequired = true;
            return(t);
        }
 public CompositionTargetPass(CompositionTechnique parent)
 {
     this.parent    = parent;
     inputMode      = CompositorInputMode.None;
     passes         = new List <CompositionPass>();
     onlyInitial    = false;
     visibilityMask = 0xFFFFFFFF;
     lodBias        = 1.0f;
     materialScheme = MaterialManager.DefaultSchemeName;
 }
Example #5
0
 public CompositorInstance(Compositor filter, CompositionTechnique technique, CompositorChain chain)
 {
     this.compositor        = filter;
     this.technique         = technique;
     this.chain             = chain;
     this.enabled           = false;
     localTextures          = new Dictionary <string, Texture>();
     renderSystemOperations = new List <QueueIDAndOperation>();
     listeners = new List <CompositorInstanceListener>();
 }
Example #6
0
        public CompositionTargetPass(CompositionTechnique parent)
        {
            this.parent         = parent;
            this.inputMode      = CompositorInputMode.None;
            this.passes         = new List <CompositionPass>();
            this.onlyInitial    = false;
            this.visibilityMask = 0xFFFFFFFF;
            this.lodBias        = 1.0f;
            this.materialScheme = MaterialManager.DefaultSchemeName;
            ShadowsEnabled      = true;

            if (Root.Instance.RenderSystem != null)
            {
                this.materialScheme = Root.Instance.RenderSystem.DefaultViewportMaterialScheme;
            }
        }
        ///<summary>
        ///    Apply a compositor. Initially, the filter is enabled.
        ///</summary>
        ///<param name="filter">Filter to apply</param>
        ///<param name="addPosition">Position in filter chain to insert this filter at; defaults to the end (last applied filter)</param>
        ///<param name="technique">Technique to use; CompositorChain::BEST (default) chooses to the best one
        ///                        available (first technique supported)
        ///</param>
        CompositorInstance AddCompositor(Compositor filter, int addPosition, int technique)
        {
            // Init on demand
            if (originalScene == null)
            {
                viewport.Target.BeforeUpdate += BeforeRenderTargetUpdate;
                // viewport.Target.AfterUpdate += AfterRenderTargetUpdate;
                viewport.Target.BeforeViewportUpdate += BeforeViewportUpdate;
                viewport.Target.AfterViewportUpdate  += AfterViewportUpdate;
                /// Create base "original scene" compositor
                Compositor baseCompositor = (Compositor)CompositorManager.Instance.LoadExisting("Ogre/Scene");
                originalScene = baseCompositor.GetSupportedTechnique(0).CreateInstance(this);
            }


            filter.Touch();
            if (technique >= filter.SupportedTechniques.Count)
            {
                /// Warn user
                LogManager.Instance.Write("CompositorChain: Compositor " + filter.Name + " has no supported techniques.");
                return(null);
            }
            CompositionTechnique tech = filter.GetSupportedTechnique(technique);
            CompositorInstance   t    = tech.CreateInstance(this);

            if (addPosition == lastCompositor)
            {
                instances.Add(t);
            }
            else
            {
                Debug.Assert(addPosition <= instances.Count);
                instances.Insert(addPosition, t);
            }

            dirty = true;
            anyCompositorsEnabled = true;
            return(t);
        }
Example #8
0
        ///<summary>
        ///    Intialises the Compositor manager, which also triggers it to
        ///    parse all available .compositor scripts.
        ///</summary>
        public void Initialize()
        {
            Compositor            scene = (Compositor)Create("Ogre/Scene");
            CompositionTechnique  t     = scene.CreateTechnique();
            CompositionTargetPass tp    = t.OutputTarget;

            tp.VisibilityMask = 0xFFFFFFFF;
            CompositionPass pass = tp.CreatePass();

            pass.Type = CompositorPassType.Clear;
            CompositionPass nextPass = tp.CreatePass();

            nextPass.Type = CompositorPassType.RenderScene;
            /// Render everything, including skies
            pass.FirstRenderQueue = RenderQueueGroupID.SkiesEarly;
            pass.LastRenderQueue  = RenderQueueGroupID.SkiesLate;

            chains = new Dictionary <Viewport, CompositorChain>();

            // parse all compositing scripts
            ParseAllSources();
        }
		public CompositorInstance( CompositionTechnique technique, CompositorChain chain )
		{
			this.compositor = technique.Parent;
			this.technique = technique;
			this.chain = chain;
			this.enabled = false;

			var logicName = technique.CompositorLogicName;
			if ( !String.IsNullOrEmpty( logicName ) )
			{
				CompositorManager.Instance.CompositorLogics[ logicName ].CompositorInstanceCreated( this );
			}

			this.localTextures = new Dictionary<string, Texture>();
			this.renderSystemOperations = new List<QueueIDAndOperation>();
		}
			/// <see cref="Translator.Translate"/>
			public override void Translate( ScriptCompiler compiler, AbstractNode node )
			{
				ObjectAbstractNode obj = (ObjectAbstractNode)node;

				Compositor compositor = (Compositor)obj.Parent.Context;
				_Technique = compositor.CreateTechnique();
				obj.Context = _Technique;

				foreach ( AbstractNode i in obj.Children )
				{
					if ( i is ObjectAbstractNode )
					{
						_processNode( compiler, i );
					}
					else if ( i is PropertyAbstractNode )
					{
						PropertyAbstractNode prop = (PropertyAbstractNode)i;
						switch ( (Keywords)prop.Id )
						{
							#region ID_TEXTURE
							case Keywords.ID_TEXTURE:
								{
									int atomIndex = 1;

									AbstractNode it = getNodeAt( prop.Values, 0 );

									if ( it is AtomAbstractNode )
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
										return;
									}
									// Save the first atom, should be name
									AtomAbstractNode atom0 = (AtomAbstractNode)it;

									int width = 0, height = 0;
									float widthFactor = 1.0f, heightFactor = 1.0f;
									bool widthSet = false, heightSet = false, formatSet = false;
									bool pooled = false;
									bool hwGammaWrite = false;
									bool fsaa = true;

									CompositionTechnique.TextureScope scope = CompositionTechnique.TextureScope.Local;
									List<PixelFormat> formats = new List<PixelFormat>();

									while ( atomIndex < prop.Values.Count )
									{
										it = getNodeAt( prop.Values, atomIndex++ );
										if ( !(it is AtomAbstractNode) )
										{
											compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
											return;
										}
										AtomAbstractNode atom = (AtomAbstractNode)it;

										switch ( (Keywords)atom.Id )
										{
											case Keywords.ID_TARGET_WIDTH:
												width = 0;
												widthSet = true;
												break;

											case Keywords.ID_TARGET_HEIGHT:
												height = 0;
												heightSet = true;
												break;

											case Keywords.ID_TARGET_WIDTH_SCALED:
											case Keywords.ID_TARGET_HEIGHT_SCALED:
												{
													bool pSetFlag = false;
													int pSize = 0;
													float pFactor = 0;
													if ( atom.Id == (uint)Keywords.ID_TARGET_WIDTH_SCALED )
													{
														pSetFlag = widthSet;
														pSize = width;
														pFactor = widthFactor;
													}
													else
													{
														pSetFlag = heightSet;
														pSize = height;
														pFactor = heightFactor;
													}
													// advance to next to get scaling
													it = getNodeAt( prop.Values, atomIndex++ );
													if ( it == null || !(it is AtomAbstractNode) )
													{
														compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
														return;
													}
													atom = (AtomAbstractNode)it;
													if ( !atom.IsNumber )
													{
														compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
														return;
													}

													pSize = 0;
													pFactor = atom.Number;
													pSetFlag = true;
												}
												break;

											case Keywords.ID_POOLED:
												pooled = true;
												break;

											case Keywords.ID_SCOPE_LOCAL:
												scope = CompositionTechnique.TextureScope.Local;
												break;

											case Keywords.ID_SCOPE_CHAIN:
												scope = CompositionTechnique.TextureScope.Chain;
												break;

											case Keywords.ID_SCOPE_GLOBAL:
												scope = CompositionTechnique.TextureScope.Global;
												break;

											case Keywords.ID_GAMMA:
												hwGammaWrite = true;
												break;

											case Keywords.ID_NO_FSAA:
												fsaa = false;
												break;

											default:
												if ( atom.IsNumber )
												{
													if ( atomIndex == 2 )
													{
														width = (int)atom.Number;
														widthSet = true;
													}
													else if ( atomIndex == 3 )
													{
														height = (int)atom.Number;
														heightSet = true;
													}
													else
													{
														compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
														return;
													}
												}
												else
												{
													// pixel format?
													PixelFormat format = PixelUtil.GetFormatFromName( atom.Value, true );
													if ( format == PixelFormat.Unknown )
													{
														compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
														return;
													}
													formats.Add( format );
													formatSet = true;
												}
												break;
										}
									}
									if ( !widthSet || !heightSet || !formatSet )
									{
										compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
										return;
									}

									// No errors, create
									CompositionTechnique.TextureDefinition def = _Technique.CreateTextureDefinition( atom0.Value );
									def.Width = width;
									def.Height = height;
									def.WidthFactor = widthFactor;
									def.HeightFactor = heightFactor;
									def.PixelFormats = formats;
									def.HwGammaWrite = hwGammaWrite;
									def.Fsaa = fsaa;
									def.Pooled = pooled;
									def.Scope = scope;
								}
								break;
							#endregion ID_TEXTURE

							#region ID_TEXTURE_REF
							case Keywords.ID_TEXTURE_REF:
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
								}
								else if ( prop.Values.Count != 3 )
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
										"texture_ref only supports 3 argument" );
								}
								else
								{
									string texName = string.Empty, refCompName = string.Empty, refTexName = string.Empty;

									AbstractNode it = getNodeAt( prop.Values, 0 );
									if ( !getString( it, out texName ) )
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
										"texture_ref must have 3 string arguments" );
									}

									it = getNodeAt( prop.Values, 1 );
									if ( !getString( it, out refCompName ) )
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
										"texture_ref must have 3 string arguments" );
									}

									it = getNodeAt( prop.Values, 2 );
									if ( !getString( it, out refTexName ) )
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
										"texture_ref must have 3 string arguments" );
									}

									CompositionTechnique.TextureDefinition refTexDef = _Technique.CreateTextureDefinition( texName );

									refTexDef.ReferenceCompositorName = refCompName;
									refTexDef.ReferenceTextureName = refTexName;
								}
								break;
							#endregion ID_TEXTURE_REF

							#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
								{
									AbstractNode i0 = getNodeAt( prop.Values, 0 );
									string scheme = string.Empty;

									if ( getString( i0, out scheme ) )
										_Technique.SchemeName = scheme;
									else
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
										"scheme must have 1 string argument" );
								}
								break;
							#endregion ID_SCHEME

							#region ID_COMPOSITOR_LOGIC
							case Keywords.ID_COMPOSITOR_LOGIC:
								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,
										"compositor logic only supports 1 argument" );
								}
								else
								{
									AbstractNode i0 = getNodeAt( prop.Values, 0 );
									string logicName = string.Empty;

									if ( getString( i0, out logicName ) )
										_Technique.CompositorLogicName = logicName;
									else
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line,
										"compositor logic must have 1 string argument" );
								}
								break;
							#endregion ID_COMPOSITOR_LOGIC

							default:
								compiler.AddError( CompileErrorCode.UnexpectedToken, prop.File, prop.Line,
									"token \"" + prop.Name + "\" is not recognized" );
								break;
						}
					}
				}
			}
			public CompositionTechniqueTranslator()
				: base()
			{
				_Technique = null;
			}
		public CompositionTargetPass( CompositionTechnique parent )
		{
			this.parent = parent;
			this.inputMode = CompositorInputMode.None;
			this.passes = new List<CompositionPass>();
			this.onlyInitial = false;
			this.visibilityMask = 0xFFFFFFFF;
			this.lodBias = 1.0f;
			this.materialScheme = MaterialManager.DefaultSchemeName;
			ShadowsEnabled = true;

			if ( Root.Instance.RenderSystem != null )
			{
				this.materialScheme = Root.Instance.RenderSystem.DefaultViewportMaterialScheme;
			}
		}
 public CompositorInstance(Compositor filter, CompositionTechnique technique, CompositorChain chain)
 {
     this.compositor = filter;
     this.technique = technique;
     this.chain = chain;
     this.enabled = false;
     localTextures = new Dictionary<string, Texture>();
     renderSystemOperations = new List<QueueIDAndOperation>();
     listeners = new List<CompositorInstanceListener>();
 }
 public CompositionTargetPass(CompositionTechnique parent)
 {
     this.parent = parent;
     inputMode = CompositorInputMode.None;
     passes = new List<CompositionPass>();
     onlyInitial = false;
     visibilityMask = 0xFFFFFFFF;
     lodBias = 1.0f;
     materialScheme = MaterialManager.DefaultSchemeName;
 }
Example #15
0
		///<summary>
		/// Create a new technique, and return a pointer to it.
		///</summary>
		public CompositionTechnique CreateTechnique()
		{
			CompositionTechnique t = new CompositionTechnique( this );
			techniques.Add( t );
			compilationRequired = true;
			return t;
		}