Object representing one pass or operation in a composition sequence. This provides a method to conviently interleave RenderSystem commands between Render Queues.
        ///<summary>
        ///    Create a new pass, and return a pointer to it.
        ///</summary>
        public CompositionPass CreatePass()
        {
            CompositionPass t = new CompositionPass(this);

            passes.Add(t);
            return(t);
        }
Пример #2
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);
        }
Пример #3
0
        ///<summary>
        ///    Create a new pass, and return a pointer to it.
        ///</summary>
        public CompositionPass CreatePass()
        {
            var t = new CompositionPass(this);

            this.passes.Add(t);
            return(t);
        }
        ///<summary>
        ///    Compile this Composition chain into a series of RenderTarget operations.
        ///</summary>
        protected void Compile()
        {
            ClearCompiledState();

            bool compositorsEnabled = false;

            /// Set previous CompositorInstance for each compositor in the list
            CompositorInstance lastComposition = originalScene;

            originalScene.PreviousInstance = null;
            CompositionPass pass = originalScene.Technique.OutputTarget.GetPass(0);

            pass.ClearBuffers = viewport.ClearBuffers;
            pass.ClearColor   = viewport.BackgroundColor;
            foreach (CompositorInstance instance in instances)
            {
                if (instance.Enabled)
                {
                    compositorsEnabled        = true;
                    instance.PreviousInstance = lastComposition;
                    lastComposition           = instance;
                }
            }

            /// Compile misc targets
            lastComposition.CompileTargetOperations(compiledState);

            /// Final target viewport (0)
            outputOperation.RenderSystemOperations.Clear();
            lastComposition.CompileOutputOperation(outputOperation);

            // Deal with viewport settings
            if (compositorsEnabled != anyCompositorsEnabled)
            {
                anyCompositorsEnabled = compositorsEnabled;
                if (anyCompositorsEnabled)
                {
                    // Save old viewport clearing options
                    oldClearEveryFrameBuffers = viewport.ClearBuffers;
                    // Don't clear anything every frame since we have our own clear ops
                    viewport.SetClearEveryFrame(false);
                }
                else
                {
                    // Reset clearing options
                    viewport.SetClearEveryFrame(oldClearEveryFrameBuffers > 0,
                                                oldClearEveryFrameBuffers);
                }
            }
            dirty = false;
        }
        ///<summary>
        ///    @see RenderTargetListener.PreViewportUpdate
        ///</summary>
        public virtual void BeforeViewportUpdate(object sender, ViewportUpdateEventArgs evt)
        {
            // Only set up if there is at least one compositor enabled, and it's this viewport
            if (evt.Viewport != viewport || !anyCompositorsEnabled)
            {
                return;
            }

            // set original scene details from viewport
            CompositionPass pass = originalScene.Technique.OutputTarget.GetPass(0);

            if (pass.ClearBuffers != viewport.ClearBuffers ||
                pass.ClearColor != viewport.BackgroundColor)
            {
                pass.ClearBuffers = viewport.ClearBuffers;
                pass.ClearColor   = viewport.BackgroundColor;
                Compile();
            }

            /// Prepare for output operation
            PreTargetOperation(outputOperation, viewport, viewport.Camera);
        }
Пример #6
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();
        }
Пример #7
0
		///<summary>
		///    Create a new pass, and return a pointer to it.
		///</summary>
		public CompositionPass CreatePass()
		{
			var t = new CompositionPass( this );
			this.passes.Add( t );
			return t;
		}
			/// <see cref="Translator.Translate"/>
			public override void Translate( ScriptCompiler compiler, AbstractNode node )
			{
				var obj = (ObjectAbstractNode)node;

				this._Pass = (CompositionPass)obj.Parent.Context;

				// Should be no parameters, just children
				if ( obj.Values.Count != 0 )
				{
					compiler.AddError( CompileErrorCode.UnexpectedToken, obj.File, obj.Line );
				}

				foreach ( var i in obj.Children )
				{
					if ( i is ObjectAbstractNode )
					{
						processNode( compiler, i );
					}
					else if ( i is PropertyAbstractNode )
					{
						var prop = (PropertyAbstractNode)i;
						switch ( (Keywords)prop.Id )
						{
								#region ID_BUFFERS

							case Keywords.ID_BUFFERS:
							{
								FrameBufferType buffers = 0;
								foreach ( var k in prop.Values )
								{
									if ( k is AtomAbstractNode )
									{
										switch ( (Keywords)( (AtomAbstractNode)k ).Id )
										{
											case Keywords.ID_COLOUR:
												buffers |= FrameBufferType.Color;
												break;

											case Keywords.ID_DEPTH:
												buffers |= FrameBufferType.Depth;
												break;

											case Keywords.ID_STENCIL:
												buffers |= FrameBufferType.Stencil;
												break;

											default:
												compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
												break;
										}
									}
									else
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
									}
								}
								this._Pass.ClearBuffers = buffers;
							}
								break;

								#endregion ID_BUFFERS

								#region ID_COLOUR_VALUE

							case Keywords.ID_COLOUR_VALUE:
							{
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line );
									return;
								}

								var val = ColorEx.White;
								if ( getColor( prop.Values, 0, out val ) )
								{
									this._Pass.ClearColor = val;
								}
								else
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								}
							}
								break;

								#endregion ID_COLOUR_VALUE

								#region ID_DEPTH_VALUE

							case Keywords.ID_DEPTH_VALUE:
							{
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line );
									return;
								}
								Real val = 0;
								if ( getReal( prop.Values[ 0 ], out val ) )
								{
									this._Pass.ClearDepth = val;
								}
								else
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								}
							}
								break;

								#endregion ID_DEPTH_VALUE

								#region ID_STENCIL_VALUE

							case Keywords.ID_STENCIL_VALUE:
							{
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line );
									return;
								}

								var val = 0;
								if ( getInt( prop.Values[ 0 ], out val ) )
								{
									this._Pass.ClearStencil = val;
								}
								else
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								}
							}
								break;

								#endregion ID_STENCIL_VALUE

							default:
								compiler.AddError( CompileErrorCode.UnexpectedToken, prop.File, prop.Line,
								                   "token \"" + prop.Name + "\" is not recognized" );
								break;
						}
					}
				}
			}
 ///<summary>
 ///    Create a new pass, and return a pointer to it.
 ///</summary>
 public CompositionPass CreatePass()
 {
     CompositionPass t = new CompositionPass(this);
     passes.Add(t);
     return t;
 }
			/// <see cref="Translator.Translate"/>
			public override void Translate( ScriptCompiler compiler, AbstractNode node )
			{
				var obj = (ObjectAbstractNode)node;

				var target = (CompositionTargetPass)obj.Parent.Context;
				this._Pass = target.CreatePass();
				obj.Context = this._Pass;

				// The name is the type of the pass
				if ( obj.Values.Count == 0 )
				{
					compiler.AddError( CompileErrorCode.StringExpected, obj.File, obj.Line );
					return;
				}
				var type = string.Empty;
				if ( !getString( obj.Values[ 0 ], out type ) )
				{
					compiler.AddError( CompileErrorCode.InvalidParameters, obj.File, obj.Line );
					return;
				}

				this._Pass.Type = (CompositorPassType)ScriptEnumAttribute.Lookup( type, typeof ( CompositorPassType ) );
				if ( this._Pass.Type == CompositorPassType.RenderCustom )
				{
					var customType = string.Empty;
					//This is the ugly one liner for safe access to the second parameter.
					if ( obj.Values.Count < 2 || !getString( obj.Values[ 1 ], out customType ) )
					{
						compiler.AddError( CompileErrorCode.StringExpected, obj.File, obj.Line );
						return;
					}
					this._Pass.CustomType = customType;
				}
				else
				{
					compiler.AddError( CompileErrorCode.InvalidParameters, obj.File, obj.Line,
					                   "pass types must be \"clear\", \"stencil\", \"render_quad\", \"render_scene\" or \"render_custom\"." );
					return;
				}

				foreach ( var i in obj.Children )
				{
					if ( i is ObjectAbstractNode )
					{
						processNode( compiler, i );
					}
					else if ( i is PropertyAbstractNode )
					{
						var prop = (PropertyAbstractNode)i;
						switch ( (Keywords)prop.Id )
						{
								#region ID_MATERIAL

							case Keywords.ID_MATERIAL:
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}
								else if ( prop.Values.Count > 1 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line );
									return;
								}
								else
								{
									var val = string.Empty;
									if ( getString( prop.Values[ 0 ], out val ) )
									{
										ScriptCompilerEvent evt =
											new ProcessResourceNameScriptCompilerEvent( ProcessResourceNameScriptCompilerEvent.ResourceType.Material, val );

										compiler._fireEvent( ref evt );
										this._Pass.MaterialName = ( (ProcessResourceNameScriptCompilerEvent)evt ).Name;
									}
									else
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
									}
								}
								break;

								#endregion ID_MATERIAL

								#region ID_INPUT

							case Keywords.ID_INPUT:
								if ( prop.Values.Count < 2 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}
								else if ( prop.Values.Count > 3 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line );
									return;
								}
								else
								{
									AbstractNode i0 = getNodeAt( prop.Values, 0 ),
									             i1 = getNodeAt( prop.Values, 1 ),
									             i2 = getNodeAt( prop.Values, 2 );
									var id = 0;
									var name = string.Empty;
									if ( getInt( i0, out id ) && getString( i1, out name ) )
									{
										var index = 0;

										if ( !getInt( i2, out index ) )
										{
											compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line );
											return;
										}

										this._Pass.SetInput( id, name, index );
									}
									else
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
									}
								}
								break;

								#endregion ID_INPUT

								#region ID_IDENTIFIER

							case Keywords.ID_IDENTIFIER:
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}
								else if ( prop.Values.Count > 1 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line );
									return;
								}
								else
								{
									uint val;
									if ( getUInt( prop.Values[ 0 ], out val ) )
									{
										this._Pass.Identifier = val;
									}
									else
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
									}
								}
								break;

								#endregion ID_IDENTIFIER

								#region ID_FIRST_RENDER_QUEUE

							case Keywords.ID_FIRST_RENDER_QUEUE:
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}
								else if ( prop.Values.Count > 1 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line );
									return;
								}
								else
								{
									uint val;
									if ( getUInt( prop.Values[ 0 ], out val ) )
									{
										this._Pass.FirstRenderQueue = (RenderQueueGroupID)val;
									}
									else
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
									}
								}
								break;

								#endregion ID_FIRST_RENDER_QUEUE

								#region ID_LAST_RENDER_QUEUE

							case Keywords.ID_LAST_RENDER_QUEUE:
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}
								else if ( prop.Values.Count > 1 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line );
									return;
								}
								else
								{
									uint val;
									if ( getUInt( prop.Values[ 0 ], out val ) )
									{
										this._Pass.LastRenderQueue = (RenderQueueGroupID)val;
									}
									else
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
									}
								}
								break;

								#endregion ID_LAST_RENDER_QUEUE

								#region ID_MATERIAL_SCHEME

							case Keywords.ID_MATERIAL_SCHEME:
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}
								else if ( prop.Values.Count > 1 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line );
									return;
								}
								else
								{
									string val;
									if ( getString( prop.Values[ 0 ], out val ) )
									{
										this._Pass.MaterialScheme = val;
									}
									else
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
									}
								}
								break;

								#endregion ID_MATERIAL_SCHEME

								#region ID_QUAD_NORMALS

							case Keywords.ID_QUAD_NORMALS:
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}
								else if ( prop.Values.Count > 1 )
								{
									compiler.AddError( CompileErrorCode.FewerParametersExpected, prop.File, prop.Line );
									return;
								}
								else
								{
									if ( prop.Values[ 0 ] is AtomAbstractNode )
									{
										var atom = (AtomAbstractNode)prop.Values[ 0 ];
										if ( atom.Id == (uint)Keywords.ID_CAMERA_FAR_CORNERS_VIEW_SPACE )
										{
											this._Pass.SetQuadFarCorners( true, true );
										}
										else if ( atom.Id == (uint)Keywords.ID_CAMERA_FAR_CORNERS_WORLD_SPACE )
										{
											this._Pass.SetQuadFarCorners( true, false );
										}
										else
										{
											compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
										}
									}
									else
									{
										compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
									}
								}
								break;

								#endregion ID_QUAD_NORMALS

							default:
								compiler.AddError( CompileErrorCode.UnexpectedToken, prop.File, prop.Line,
								                   "token \"" + prop.Name + "\" is not recognized" );
								break;
						}
					}
				}
			}
			public CompositionPassTranslator()
				: base()
			{
				this._Pass = null;
			}
			/// <see cref="Translator.Translate"/>
			public override void Translate( ScriptCompiler compiler, AbstractNode node )
			{
				var obj = (ObjectAbstractNode)node;

				this._Pass = (CompositionPass)obj.Parent.Context;

				// Should be no parameters, just children
				if ( obj.Values.Count != 0 )
				{
					compiler.AddError( CompileErrorCode.UnexpectedToken, obj.File, obj.Line );
				}

				foreach ( var i in obj.Children )
				{
					if ( i is ObjectAbstractNode )
					{
						processNode( compiler, i );
					}
					else if ( i is PropertyAbstractNode )
					{
						var prop = (PropertyAbstractNode)i;
						switch ( (Keywords)prop.Id )
						{
								#region ID_CHECK

							case Keywords.ID_CHECK:
							{
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}

								var val = false;
								if ( getBoolean( prop.Values[ 0 ], out val ) )
								{
									this._Pass.StencilCheck = val;
								}
								else
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								}
							}
								break;

								#endregion ID_CHECK

								#region ID_COMP_FUNC

							case Keywords.ID_COMP_FUNC:
							{
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}

								CompareFunction func;
								if ( getEnumeration<CompareFunction>( prop.Values[ 0 ], compiler, out func ) )
								{
									this._Pass.StencilFunc = func;
								}
								else
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								}
							}
								break;

								#endregion ID_COMP_FUNC

								#region ID_REF_VALUE

							case Keywords.ID_REF_VALUE:
							{
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line );
									return;
								}

								int val;
								if ( getInt( prop.Values[ 0 ], out val ) )
								{
									this._Pass.StencilRefValue = val;
								}
								else
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								}
							}
								break;

								#endregion ID_REF_VALUE

								#region ID_MASK

							case Keywords.ID_MASK:
							{
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.NumberExpected, prop.File, prop.Line );
									return;
								}
								int val;
								if ( getInt( prop.Values[ 0 ], out val ) )
								{
									this._Pass.StencilMask = val;
								}
								else
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								}
							}
								break;

								#endregion ID_MASK

								#region ID_FAIL_OP

							case Keywords.ID_FAIL_OP:
							{
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}

								StencilOperation val;
								if ( getEnumeration<StencilOperation>( prop.Values[ 0 ], compiler, out val ) )
								{
									this._Pass.StencilFailOp = val;
								}
								else
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								}
							}
								break;

								#endregion ID_FAIL_OP

								#region ID_DEPTH_FAIL_OP

							case Keywords.ID_DEPTH_FAIL_OP:
							{
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}

								StencilOperation val;
								if ( getEnumeration<StencilOperation>( prop.Values[ 0 ], compiler, out val ) )
								{
									this._Pass.StencilDepthFailOp = val;
								}
								else
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								}
							}
								break;

								#endregion ID_DEPTH_FAIL_OP

								#region ID_PASS_OP

							case Keywords.ID_PASS_OP:
							{
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}

								StencilOperation val;
								if ( getEnumeration<StencilOperation>( prop.Values[ 0 ], compiler, out val ) )
								{
									this._Pass.StencilPassOp = val;
								}
								else
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								}
							}
								break;

								#endregion ID_PASS_OP

								#region ID_TWO_SIDED

							case Keywords.ID_TWO_SIDED:
							{
								if ( prop.Values.Count == 0 )
								{
									compiler.AddError( CompileErrorCode.StringExpected, prop.File, prop.Line );
									return;
								}

								bool val;
								if ( getBoolean( prop.Values[ 0 ], out val ) )
								{
									this._Pass.StencilTwoSidedOperation = val;
								}
								else
								{
									compiler.AddError( CompileErrorCode.InvalidParameters, prop.File, prop.Line );
								}
							}
								break;

								#endregion ID_TWO_SIDED

							default:
								compiler.AddError( CompileErrorCode.UnexpectedToken, prop.File, prop.Line,
								                   "token \"" + prop.Name + "\" is not recognized" );
								break;
						}
					}
				}
			}
			public CompositionPassClearTranslator()
				: base()
			{
				_Pass = null;
			}
			public CompositionPassStencilTranslator()
				: base()
			{
				_Pass = null;
			}