Class defining a single pass of a Technique (of a Material), ie a single rendering call.
Rendering can be repeated with many passes for more complex effects. Each pass is either a fixed-function pass (meaning it does not use a vertex or fragment program) or a programmable pass (meaning it does use either a vertex or a fragment program, or both).

Programmable passes are complex to define, because they require custom programs and you have to set all constant inputs to the programs (like the position of lights, any base material colors you wish to use etc), but they do give you much total flexibility over the algorithms used to render your pass, and you can create some effects which are impossible with a fixed-function pass. On the other hand, you can define a fixed-function pass in very little time, and you can use a range of fixed-function effects like environment mapping very easily, plus your pass will be more likely to be compatible with older hardware. There are pros and cons to both, just remember that if you use a programmable pass to create some great effects, allow more time for definition and testing.

Inheritance: DisposableObject
Exemplo n.º 1
0
		public override bool PreAddToRenderState( TargetRenderState targetRenderState, Pass srcPass, Pass dstPass )
		{
			//count the number of texture units we need to process
			int validTexUnits = 0;
			for ( int i = 0; i < srcPass.TextureUnitStatesCount; i++ )
			{
				if ( IsProcessingNeeded( srcPass.GetTextureUnitState( i ) ) )
				{
					validTexUnits++;
				}
			}

			SetTextureUnitCount( validTexUnits );

			//Build texture stage sub states
			for ( int i = 0; i < srcPass.TextureUnitStatesCount; i++ )
			{
				TextureUnitState texUnitState = srcPass.GetTextureUnitState( i );
				if ( IsProcessingNeeded( texUnitState ) )
				{
					SetTextureUnit( i, texUnitState );
				}
			}

			return true;
		}
Exemplo n.º 2
0
			UpdateGpuProgramsParams( IRenderable rend, Pass pass, AutoParamDataSource source,
			                         Core.Collections.LightList lightList )
		{
			if ( this.reflectionPowerChanged )
			{
				GpuProgramParameters fsParams = pass.FragmentProgramParameters;

				this.reflectionPower.SetGpuParameter( this.reflectionPowerValue );
				this.reflectionPowerChanged = false;
			}
		}
Exemplo n.º 3
0
		public override void UpdateGpuProgramsParams( IRenderable rend, Pass pass, AutoParamDataSource source,
		                                              Core.Collections.LightList lightList )
		{
			if ( this.fogMode == FogMode.None )
			{
				return;
			}

			FogMode fMode;
			ColorEx newFogColor;
			Real newFogStart, newFogEnd, newFogDensity;

			if ( this.passOverrideParams )
			{
				fMode = pass.FogMode;
				newFogColor = pass.FogColor;
				newFogStart = pass.FogStart;
				newFogEnd = pass.FogEnd;
				newFogDensity = pass.FogDensity;
			}
			else
			{
				var sceneMgr = ShaderGenerator.Instance.ActiveSceneManager;

				fMode = sceneMgr.FogMode;
				newFogColor = sceneMgr.FogColor;
				newFogStart = sceneMgr.FogStart;
				newFogEnd = sceneMgr.FogEnd;
				newFogDensity = sceneMgr.FogDensity;
			}

			SetFogProperties( fMode, newFogColor, newFogStart, newFogEnd, newFogDensity );

			//Per pixel fog
			if ( this.calcMode == CalcMode.PerPixel )
			{
				this.fogParams.SetGpuParameter( this.fogParamsValue );
			}

				//per vertex fog
			else
			{
				this.fogParams.SetGpuParameter( this.fogParamsValue );
			}

			this.fogColor.SetGpuParameter( this.fogColorValue );
		}
Exemplo n.º 4
0
		public override void UpdateGpuProgramsParams( IRenderable rend, Pass pass, AutoParamDataSource source,
		                                              Core.Collections.LightList lightList )
		{
			for ( int i = 0; i < this.textureUnitParamsList.Count; i++ )
			{
				TextureUnitParams curParams = this.textureUnitParamsList[ i ];

				if ( curParams.TextureProjector != null && curParams.TextureViewProjImageMatrix != null )
				{
					Matrix4 matTexViewProjImage;

					matTexViewProjImage = Matrix4.ClipSpace2DToImageSpace*
					                      curParams.TextureProjector.ProjectionMatrixRSDepth*
					                      curParams.TextureProjector.ViewMatrix;

					curParams.TextureViewProjImageMatrix.SetGpuParameter( matTexViewProjImage );
				}
			}
		}
Exemplo n.º 5
0
		public override bool PreAddToRenderState( TargetRenderState targetRenderState, Pass srcPass, Pass dstPass )
		{
			TextureUnitState textureUnit;

			//Create the mask texture unit.
			textureUnit = dstPass.CreateTextureUnitState();
			textureUnit.SetTextureName( this.maskMapTextureName );
			this.maskMapSamplerIndex = dstPass.TextureUnitStatesCount - 1;

			//Create the reflection texture unit.
			textureUnit = dstPass.CreateTextureUnitState();

			if ( this.reflectionMapType == TextureType.TwoD )
			{
				textureUnit.SetTextureName( this.reflectionMapTextureName );
			}
			else
			{
				textureUnit.SetCubicTextureName( this.reflectionMapTextureName, true );
			}
			this.reflectionMapSamplerIndex = dstPass.TextureUnitStatesCount - 1;

			return true;
		}
Exemplo n.º 6
0
		/// <summary>
		///     Render something as if it came from the current queue.
		/// </summary>
		///<param name="pass">Material pass to use for setting up this quad.</param>
		///<param name="rend">Renderable to render</param>
		///<param name="shadowDerivation">Whether passes should be replaced with shadow caster / receiver passes</param>
		public virtual void InjectRenderWithPass( Pass pass, IRenderable rend, bool shadowDerivation )
		{
			// render something as if it came from the current queue
			Pass usedPass = this.SetPass( pass, false, shadowDerivation );
			this.RenderSingleObject( rend, usedPass, false );
		}
Exemplo n.º 7
0
		/// <summary>
		///		Internal method to validate whether a Pass should be allowed to render.
		/// </summary>
		/// <remarks>
		///		Called just before a pass is about to be used for rendering a group to
		///		allow the SceneManager to omit it if required. A return value of false
		///		skips this pass.
		/// </remarks>
		protected virtual bool ValidatePassForRendering( Pass pass )
		{
			// Bypass if we're doing a texture shadow render and
			// this pass is after the first (only 1 pass needed for shadow texture)
			if ( !this.suppressShadows && this.currentViewport.ShowShadows &&
				 ( ( this.IsShadowTechniqueModulative
					 && this.illuminationStage == IlluminationRenderStage.RenderReceiverPass ) ||
				   this.illuminationStage == IlluminationRenderStage.RenderToTexture || this.suppressRenderStateChanges ) &&
				 pass.Index > 0 )
			{
				return false;
			}

			return true;
		}
Exemplo n.º 8
0
	    protected void RenderSingleObject( IRenderable renderable, Pass pass, bool doLightIteration )
		{
			this.RenderSingleObject( renderable, pass, doLightIteration, null );
		}
Exemplo n.º 9
0
		/// <summary>
		///		If only the first two parameters are supplied
		/// </summary>
		public virtual Pass SetPass( Pass pass, bool evenIfSuppressed )
		{
			return this.SetPass( pass, evenIfSuppressed, true );
		}
Exemplo n.º 10
0
		/// <summary>Internal method for setting up the renderstate for a rendering pass.</summary>
		/// <param name="pass">The Pass details to set.</param>
		/// <param name="evenIfSuppressed">
		///    Sets the pass details even if render state
		///    changes are suppressed; if you are using this to manually set state
		///    when render state changes are suppressed, you should set this to true.
		/// </param>
		/// <param name="shadowDerivation">
		///    If false, disables the derivation of shadow passes from original passes
		/// </param>
		/// <returns>
		///		A Pass object that was used instead of the one passed in, can
		///		happen when rendering shadow passes
		///	</returns>
		public virtual Pass SetPass( Pass pass, bool evenIfSuppressed, bool shadowDerivation )
		{
			if ( !this.suppressRenderStateChanges || evenIfSuppressed )
			{
				if ( this.illuminationStage == IlluminationRenderStage.RenderToTexture && shadowDerivation )
				{
					// Derive a special shadow caster pass from this one
					pass = this.DeriveShadowCasterPass( pass );
				}
				else if ( this.illuminationStage == IlluminationRenderStage.RenderReceiverPass )
				{
					pass = this.DeriveShadowReceiverPass( pass );
				}

				//TODO :autoParamDataSource.SetPass( pass );

				bool passSurfaceAndLightParams = true;

				if ( pass.HasVertexProgram )
				{
					this.targetRenderSystem.BindGpuProgram( pass.VertexProgram.BindingDelegate );
					// bind parameters later since they can be per-object
					// does the vertex program want surface and light params passed to rendersystem?
					passSurfaceAndLightParams = pass.VertexProgram.PassSurfaceAndLightStates;
				}
				else
				{
					// Unbind program?
					if ( this.targetRenderSystem.IsGpuProgramBound( GpuProgramType.Vertex ) )
					{
						this.targetRenderSystem.UnbindGpuProgram( GpuProgramType.Vertex );
					}
					// Set fixed-function vertex parameters
				}

				if ( passSurfaceAndLightParams )
				{
					// Set surface reflectance properties, only valid if lighting is enabled
					if ( pass.LightingEnabled )
					{
						this.targetRenderSystem.SetSurfaceParams( pass.Ambient,
																  pass.Diffuse,
																  pass.Specular,
																  pass.Emissive,
																  pass.Shininess,
																  pass.VertexColorTracking );
					}
					// #if NOT_IN_OGRE
					else
					{
						// even with lighting off, we need ambient set to white
						this.targetRenderSystem.SetSurfaceParams( ColorEx.White,
																  ColorEx.Black,
																  ColorEx.Black,
																  ColorEx.Black,
																  0,
																  TrackVertexColor.None );
					}
					// #endif
					// Dynamic lighting enabled?
					this.targetRenderSystem.LightingEnabled = pass.LightingEnabled;
				}

				// Using a fragment program?
				if ( pass.HasFragmentProgram )
				{
					this.targetRenderSystem.BindGpuProgram( pass.FragmentProgram.BindingDelegate );
					// bind parameters later since they can be per-object
				}
				else
				{
					// Unbind program?
					if ( this.targetRenderSystem.IsGpuProgramBound( GpuProgramType.Fragment ) )
					{
						this.targetRenderSystem.UnbindGpuProgram( GpuProgramType.Fragment );
					}
				}
				// Set fixed-function fragment settings

				//We need to set fog properties always. In D3D, it applies to shaders prior
				//to version vs_3_0 and ps_3_0. And in OGL, it applies to "ARB_fog_XXX" in
				//fragment program, and in other ways, they maybe accessed by gpu program via
				//"state.fog.XXX".

				// New fog params can either be from scene or from material

				// jsw - set the fog for both fixed function and fragment programs
				ColorEx newFogColor;
				FogMode newFogMode;
				float newFogDensity, newFogStart, newFogEnd;

				// does the pass want to override the fog mode?
				if ( pass.FogOverride )
				{
					// New fog params from material
					newFogMode = pass.FogMode;
					newFogColor = pass.FogColor;
					newFogDensity = pass.FogDensity;
					newFogStart = pass.FogStart;
					newFogEnd = pass.FogEnd;
				}
				else
				{
					// New fog params from scene
					newFogMode = this.fogMode;
					newFogColor = this.fogColor;
					newFogDensity = this.fogDensity;
					newFogStart = this.fogStart;
					newFogEnd = this.fogEnd;
				}

				// set fog params
                /*
				float fogScale = 1f;
				if ( newFogMode == FogMode.None )
				{
					fogScale = 0f;
				}
                 */

				// set fog using the render system
				this.targetRenderSystem.SetFog( newFogMode, newFogColor, newFogDensity, newFogStart, newFogEnd );

				// Tell params about ORIGINAL fog
				// Need to be able to override fixed function fog, but still have
				// original fog parameters available to a shader that chooses to use
				// TODO: autoParamDataSource.SetFog( fogMode, fogColor, fogDensity, fogStart, fogEnd );

				// The rest of the settings are the same no matter whether we use programs or not

				// Set scene blending
				this.targetRenderSystem.SetSceneBlending( pass.SourceBlendFactor, pass.DestinationBlendFactor );

				// TODO : Set point parameters
				//targetRenderSystem.SetPointParameters(
				//                                        pass.PointSize,
				//                                        pass.IsPointAttenuationEnabled,
				//                                        pass.PointAttenuationConstant,
				//                                        pass.PointAttenuationLinear,
				//                                        pass.PointAttenuationQuadratic,
				//                                        pass.PointMinSize,
				//                                        pass.PointMaxSize
				//                                        );

				//targetRenderSystem.PointSpritesEnabled = pass.PointSpritesEnabled;

				// TODO : Reset the shadow texture index for each pass
				//foreach ( TextureUnitState textureUnit in pass.TextureUnitStates )
				//{
				//}

				// set all required texture units for this pass, and disable ones not being used
				int numTextureUnits = this.targetRenderSystem.Capabilities.TextureUnitCount;
				if ( pass.HasFragmentProgram  && pass.FragmentProgram.IsSupported )
				{
					numTextureUnits = pass.FragmentProgram.SamplerCount;
				}
				else if ( Config.MaxTextureLayers < this.targetRenderSystem.Capabilities.TextureUnitCount )
				{
					numTextureUnits = Config.MaxTextureLayers;
				}

				for ( int i = 0; i < numTextureUnits; i++ )
				{
					if ( i < pass.TextureUnitStageCount )
					{
						TextureUnitState texUnit = pass.GetTextureUnitState( i );
					    targetRenderSystem.SetTextureUnitSettings( i, texUnit );
						//this.targetRenderSystem.SetTextureUnit( i, texUnit, !pass.HasFragmentProgram );
					}
					else
					{
						// disable this unit
						if ( !pass.HasFragmentProgram )
						{
							this.targetRenderSystem.DisableTextureUnit( i );
						}
					}
				}

                // Disable remaining texture units
                targetRenderSystem.DisableTextureUnitsFrom(pass.TextureUnitStageCount);

				// Depth Settings
				this.targetRenderSystem.DepthBufferWriteEnabled = pass.DepthWrite;
				this.targetRenderSystem.DepthBufferCheckEnabled = pass.DepthCheck;
				this.targetRenderSystem.DepthBufferFunction = pass.DepthFunction;
				this.targetRenderSystem.SetDepthBias(pass.DepthBiasConstant);

				// Aplha Reject Settings
				this.targetRenderSystem.SetAlphaRejectSettings( pass.AlphaRejectFunction, (byte)pass.AlphaRejectValue, pass.IsAlphaToCoverageEnabled );

				// Color Write
				// right now only using on/off, not per channel
				bool colWrite = pass.ColorWriteEnabled;
				this.targetRenderSystem.SetColorBufferWriteEnabled( colWrite, colWrite, colWrite, colWrite );

				// Culling Mode
				this.targetRenderSystem.CullingMode = pass.CullingMode;

				// Shading mode
                //this.targetRenderSystem.ShadingMode = pass.ShadingMode;

				// Polygon Mode
				this.targetRenderSystem.PolygonMode = pass.PolygonMode;

				// set pass number
				this.autoParamDataSource.PassNumber = pass.Index;
			}

			return pass;
		}
Exemplo n.º 11
0
		/// <summary>
		///		Internal method for turning a regular pass into a shadow caster pass.
		/// </summary>
		/// <remarks>
		///		This is only used for texture shadows, basically we're trying to
		///		ensure that objects are rendered solid black.
		///		This method will usually return the standard solid black pass for
		///		all fixed function passes, but will merge in a vertex program
		///		and fudge the AutpoParamDataSource to set black lighting for
		///		passes with vertex programs.
		/// </remarks>
		/// <param name="pass"></param>
		/// <returns></returns>
		protected virtual Pass DeriveShadowCasterPass( Pass pass )
		{
			if ( this.IsShadowTechniqueTextureBased )
			{
				Pass retPass;
				if ( pass.Parent.ShadowCasterMaterial != null )
				{
					retPass = pass.Parent.ShadowCasterMaterial.GetBestTechnique().GetPass( 0 );
				}
				else
				{
					retPass = ( this.shadowTextureCustomCasterPass != null ? this.shadowTextureCustomCasterPass : this.shadowCasterPlainBlackPass );
				}

				// Special case alpha-blended passes
				if ( ( pass.SourceBlendFactor == SceneBlendFactor.SourceAlpha &&
					   pass.DestinationBlendFactor == SceneBlendFactor.OneMinusSourceAlpha )
					|| pass.AlphaRejectFunction != CompareFunction.AlwaysPass )
				{
					// Alpha blended passes must retain their transparency
					retPass.SetAlphaRejectSettings( pass.AlphaRejectFunction, pass.AlphaRejectValue );
					retPass.SetSceneBlending( pass.SourceBlendFactor, pass.DestinationBlendFactor );
					retPass.Parent.Parent.TransparencyCastsShadows = true;

					// So we allow the texture units, but override the color functions
					// Copy texture state, shift up one since 0 is shadow texture
					int origPassTUCount = pass.TextureUnitStageCount;
					for ( int t = 0; t < origPassTUCount; ++t )
					{
						TextureUnitState tex;
						if ( retPass.TextureUnitStageCount <= t )
						{
							tex = retPass.CreateTextureUnitState();
						}
						else
						{
							tex = retPass.GetTextureUnitState( t );
						}
						// copy base state
						pass.GetTextureUnitState( t ).CopyTo( tex );
						// override colour function
						tex.SetColorOperationEx( LayerBlendOperationEx.Source1, LayerBlendSource.Manual, LayerBlendSource.Current, this.IsShadowTechniqueAdditive ? ColorEx.Black : shadowColor );
					}
					// Remove any extras
					while ( retPass.TextureUnitStageCount > origPassTUCount )
					{
						retPass.RemoveTextureUnitState( origPassTUCount );
					}
				}
				else
				{
					// reset
					retPass.SetSceneBlending( SceneBlendType.Replace );
					retPass.AlphaRejectFunction = CompareFunction.AlwaysPass;
					while ( retPass.TextureUnitStageCount > 0 )
					{
						retPass.RemoveTextureUnitState( 0 );
					}
				}

				// Propogate culling modes
				retPass.CullingMode = pass.CullingMode;
				retPass.ManualCullingMode = pass.ManualCullingMode;

				// Does incoming pass have a custom shadow caster program?
				if ( pass.ShadowCasterVertexProgramName != "" )
				{
					retPass.SetVertexProgram( pass.ShadowCasterVertexProgramName, false );
					GpuProgram prg = retPass.VertexProgram;
					// Load this program if not done already
					if ( !prg.IsLoaded )
					{
						prg.Load();
					}
					// Copy params
					retPass.VertexProgramParameters = pass.ShadowCasterVertexProgramParameters;
					// Also have to hack the light autoparams, that is done later
				}
				else
				{
					// reset vp?
					if ( retPass == this.shadowTextureCustomCasterPass )
					{
						if ( retPass.VertexProgramName != this.shadowTextureCustomCasterVertexProgram )
						{
							this.shadowTextureCustomCasterPass.SetVertexProgram( this.shadowTextureCustomCasterVertexProgram );
							if ( retPass.HasVertexProgram )
							{
								retPass.VertexProgramParameters = this.shadowTextureCustomCasterVPParams;
							}
						}
					}
					else
					{
						// Standard shadow caster pass, reset to no vp
						retPass.SetVertexProgram( "" );
					}
				}

				return retPass;
			}
			else
			{
				return pass;
			}
		}
Exemplo n.º 12
0
		/// <summary>
		///		Copy the details of this pass to the target pass.
		/// </summary>
		/// <param name="target">Destination pass to copy this pass's attributes to.</param>
		public void CopyTo( Pass target )
		{
			target._name = _name;
			target._hashCode = _hashCode;

			// surface
			target._ambient = _ambient.Clone();
			target._diffuse = _diffuse.Clone();
			target._specular = _specular.Clone();
			target._emissive = _emissive.Clone();
			target._shininess = _shininess;
			target._tracking = _tracking;

			// fog
			target._fogOverride = _fogOverride;
			target._fogMode = _fogMode;
			target._fogColor = _fogColor.Clone();
			target._fogStart = _fogStart;
			target._fogEnd = _fogEnd;
			target._fogDensity = _fogDensity;

			// default blending
			target._sourceBlendFactor = _sourceBlendFactor;
			target._destinationBlendFactor = _destinationBlendFactor;

			target._depthCheck = _depthCheck;
			target._depthWrite = _depthWrite;
			target._alphaRejectFunction = _alphaRejectFunction;
			target._alphaRejectValue = _alphaRejectValue;
			target._colorWriteEnabled = _colorWriteEnabled;
			target._depthFunction = _depthFunction;
			target._depthBiasConstant = _depthBiasConstant;
			target._depthBiasSlopeScale = _depthBiasSlopeScale;
			target._cullingMode = _cullingMode;
			target._manualCullingMode = _manualCullingMode;
			target._lightingEnabled = _lightingEnabled;
			target._maxSimultaneousLights = _maxSimultaneousLights;
			target._iteratePerLight = _iteratePerLight;
			target._runOnlyForOneLightType = _runOnlyForOneLightType;
			target._onlyLightType = _onlyLightType;
			target._shadingMode = _shadingMode;
			target._polygonMode = _polygonMode;
			target.IterationCount = IterationCount;

			// vertex program
			if ( _vertexProgramUsage != null )
			{
				target._vertexProgramUsage = _vertexProgramUsage.Clone();
			}
			else
			{
				target._vertexProgramUsage = null;
			}

			// shadow caster vertex program
			if ( shadowCasterVertexProgramUsage != null )
			{
				target.shadowCasterVertexProgramUsage = shadowCasterVertexProgramUsage.Clone();
			}
			else
			{
				target.shadowCasterVertexProgramUsage = null;
			}

			// shadow receiver vertex program
			if ( _shadowReceiverVertexProgramUsage != null )
			{
				target._shadowReceiverVertexProgramUsage = _shadowReceiverVertexProgramUsage.Clone();
			}
			else
			{
				target._shadowReceiverVertexProgramUsage = null;
			}

			// fragment program
			if ( _fragmentProgramUsage != null )
			{
				target._fragmentProgramUsage = _fragmentProgramUsage.Clone();
			}
			else
			{
				target._fragmentProgramUsage = null;
			}

			// shadow caster fragment program
			if ( _shadowCasterFragmentProgramUsage != null )
			{
				target._shadowCasterFragmentProgramUsage = _shadowCasterFragmentProgramUsage.Clone();
			}
			else
			{
				target._shadowCasterFragmentProgramUsage = null;
			}

			// shadow receiver fragment program
			if ( _shadowReceiverFragmentProgramUsage != null )
			{
				target._shadowReceiverFragmentProgramUsage = _shadowReceiverFragmentProgramUsage.Clone();
			}
			else
			{
				target._shadowReceiverFragmentProgramUsage = null;
			}


			// Clear texture units but doesn't notify need recompilation in the case
			// we are cloning, The parent material will take care of this.
			target.textureUnitStates.Clear();

			// Copy texture units

			for ( int i = 0; i < textureUnitStates.Count; i++ )
			{
				TextureUnitState newState = new TextureUnitState( target );
				TextureUnitState src = (TextureUnitState)textureUnitStates[ i ];
				src.CopyTo( newState );

				target.textureUnitStates.Add( newState );
			}

			target.DirtyHash();
		}
Exemplo n.º 13
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;
		}
Exemplo n.º 14
0
		public RenderablePass( IRenderable renderable, Pass pass )
		{
			this.renderable = renderable;
			this.pass = pass;
		}
Exemplo n.º 15
0
		protected override void SetupContent()
		{
			ResourceGroupManager.Instance.InitializeAllResourceGroups();
			// setup some basic lighting for our scene
			SceneManager.AmbientLight = new ColorEx( 0.5f, 0.5f, 0.5f );
			SceneManager.CreateLight( "BezierLight" ).Position = new Vector3( 100, 100, 100 );

			// define the control point vertices for our patch
			// Patch data
			PatchVertex[] patchVertices = new PatchVertex[ 9 ];

			patchVertices[ 0 ].X = -500;
			patchVertices[ 0 ].Y = 200;
			patchVertices[ 0 ].Z = -500;
			patchVertices[ 0 ].Nx = -0.5f;
			patchVertices[ 0 ].Ny = 0.5f;
			patchVertices[ 0 ].Nz = 0;
			patchVertices[ 0 ].U = 0;
			patchVertices[ 0 ].V = 0;

			patchVertices[ 1 ].X = 0;
			patchVertices[ 1 ].Y = 500;
			patchVertices[ 1 ].Z = -750;
			patchVertices[ 1 ].Nx = 0;
			patchVertices[ 1 ].Ny = 0.5f;
			patchVertices[ 1 ].Nz = 0;
			patchVertices[ 1 ].U = 0.5f;
			patchVertices[ 1 ].V = 0;

			patchVertices[ 2 ].X = 500;
			patchVertices[ 2 ].Y = 1000;
			patchVertices[ 2 ].Z = -500;
			patchVertices[ 2 ].Nx = 0.5f;
			patchVertices[ 2 ].Ny = 0.5f;
			patchVertices[ 2 ].Nz = 0;
			patchVertices[ 2 ].U = 1;
			patchVertices[ 2 ].V = 0;

			patchVertices[ 3 ].X = -500;
			patchVertices[ 3 ].Y = 0;
			patchVertices[ 3 ].Z = 0;
			patchVertices[ 3 ].Nx = -0.5f;
			patchVertices[ 3 ].Ny = 0.5f;
			patchVertices[ 3 ].Nz = 0;
			patchVertices[ 3 ].U = 0;
			patchVertices[ 3 ].V = 0.5f;

			patchVertices[ 4 ].X = 0;
			patchVertices[ 4 ].Y = 500;
			patchVertices[ 4 ].Z = 0;
			patchVertices[ 4 ].Nx = 0;
			patchVertices[ 4 ].Ny = 0.5f;
			patchVertices[ 4 ].Nz = 0;
			patchVertices[ 4 ].U = 0.5f;
			patchVertices[ 4 ].V = 0.5f;

			patchVertices[ 5 ].X = 500;
			patchVertices[ 5 ].Y = -50;
			patchVertices[ 5 ].Z = 0;
			patchVertices[ 5 ].Nx = 0.5f;
			patchVertices[ 5 ].Ny = 0.5f;
			patchVertices[ 5 ].Nz = 0;
			patchVertices[ 5 ].U = 1;
			patchVertices[ 5 ].V = 0.5f;

			patchVertices[ 6 ].X = -500;
			patchVertices[ 6 ].Y = 0;
			patchVertices[ 6 ].Z = 500;
			patchVertices[ 6 ].Nx = -0.5f;
			patchVertices[ 6 ].Ny = 0.5f;
			patchVertices[ 6 ].Nz = 0;
			patchVertices[ 6 ].U = 0;
			patchVertices[ 6 ].V = 1;

			patchVertices[ 7 ].X = 0;
			patchVertices[ 7 ].Y = 500;
			patchVertices[ 7 ].Z = 500;
			patchVertices[ 7 ].Nx = 0;
			patchVertices[ 7 ].Ny = 0.5f;
			patchVertices[ 7 ].Nz = 0;
			patchVertices[ 7 ].U = 0.5f;
			patchVertices[ 7 ].V = 1;

			patchVertices[ 8 ].X = 500;
			patchVertices[ 8 ].Y = 200;
			patchVertices[ 8 ].Z = 800;
			patchVertices[ 8 ].Nx = 0.5f;
			patchVertices[ 8 ].Ny = 0.5f;
			patchVertices[ 8 ].Nz = 0;
			patchVertices[ 8 ].U = 1;
			patchVertices[ 8 ].V = 1;
			// specify a vertex format declaration for our patch: 3 floats for position, 3 floats for normal, 2 floats for UV
			patchDeclaration = HardwareBufferManager.Instance.CreateVertexDeclaration();
			patchDeclaration.AddElement( 0, 0, VertexElementType.Float3, VertexElementSemantic.Position );
			patchDeclaration.AddElement( 0, 12, VertexElementType.Float3, VertexElementSemantic.Normal );
			patchDeclaration.AddElement( 0, 24, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0 );

			// create a patch mesh using vertices and declaration
			patch = MeshManager.Instance.CreateBezierPatch( "patch", ResourceGroupManager.DefaultResourceGroupName, patchVertices, patchDeclaration, 3, 3, 5, 5, VisibleSide.Both, BufferUsage.StaticWriteOnly, BufferUsage.DynamicWriteOnly, true, true );

			// Start patch at 0 detail
			patch.Subdivision = 0;

			// Create entity based on patch
			patchEntity = SceneManager.CreateEntity( "Entity1", "patch" );
			Material material = (Material)MaterialManager.Instance.Create( "TextMat", ResourceGroupManager.DefaultResourceGroupName, null );
			material.GetTechnique( 0 ).GetPass( 0 ).CreateTextureUnitState( "BumpyMetal.jpg" );

			patchEntity.MaterialName = "TextMat";
			patchPass = material.GetTechnique( 0 ).GetPass( 0 );

			// Attach the entity to the root of the scene
			SceneManager.RootSceneNode.AttachObject( patchEntity );

			// save the main pass of the material so we can toggle wireframe on it
			if ( material != null )
			{
				patchPass = material.GetTechnique( 0 ).GetPass( 0 );

				// use an orbit style camera
				CameraManager.setStyle( CameraStyle.Orbit );
				CameraManager.SetYawPitchDist( 0, 0, 250 );

				TrayManager.ShowCursor();

				// create slider to adjust detail and checkbox to toggle wireframe
				Slider slider = TrayManager.CreateThickSlider( TrayLocation.TopLeft, "Detail", "Detail", 120, 44, 0, 1, 6 );
				CheckBox box = TrayManager.CreateCheckBox( TrayLocation.TopLeft, "Wireframe", "Wireframe", 120 );
				slider.SliderMoved += new SliderMovedHandler( slider_SliderMoved );
				box.CheckChanged += new CheckChangedHandler( box_CheckChanged );

			}
		}
Exemplo n.º 16
0
		private void InitShadowDebugPass()
		{
			Material matDebug = (Material)MaterialManager.Instance[ SHADOW_VOLUMES_MATERIAL ];

			if ( matDebug == null )
			{
				// Create
				matDebug =
					(Material)
					MaterialManager.Instance.Create( SHADOW_VOLUMES_MATERIAL,
													 ResourceGroupManager.InternalResourceGroupName );
				this.shadowDebugPass = matDebug.GetTechnique( 0 ).GetPass( 0 );
				this.shadowDebugPass.SetSceneBlending( SceneBlendType.Add );
				this.shadowDebugPass.LightingEnabled = false;
				this.shadowDebugPass.DepthWrite = false;
				TextureUnitState t = this.shadowDebugPass.CreateTextureUnitState();
				t.SetColorOperationEx(
					LayerBlendOperationEx.Modulate,
					LayerBlendSource.Manual,
					LayerBlendSource.Current,
					new ColorEx( 0.7f, 0.0f, 0.2f ) );

				this.shadowDebugPass.CullingMode = CullingMode.None;

				if ( this.targetRenderSystem.Capabilities.HasCapability( Capabilities.VertexPrograms ) )
				{
					ShadowVolumeExtrudeProgram.Initialize();

					// Enable the (infinite) point light extruder for now, just to get some params
					this.shadowDebugPass.SetVertexProgram(
						ShadowVolumeExtrudeProgram.GetProgramName( ShadowVolumeExtrudeProgram.Programs.PointLight ) );

					this.infiniteExtrusionParams = this.shadowDebugPass.VertexProgramParameters;
					this.infiniteExtrusionParams.SetAutoConstant( 0, GpuProgramParameters.AutoConstantType.WorldViewProjMatrix );
					this.infiniteExtrusionParams.SetAutoConstant( 4, GpuProgramParameters.AutoConstantType.LightPositionObjectSpace );
					// Note ignored extra parameter - for compatibility with finite extrusion vertex program
					this.infiniteExtrusionParams.SetAutoConstant( 5, GpuProgramParameters.AutoConstantType.ShadowExtrusionDistance );
				}

				matDebug.Compile();
			}
			else
			{
				this.shadowDebugPass = matDebug.GetTechnique( 0 ).GetPass( 0 );
				if ( this.targetRenderSystem.Capabilities.HasCapability( Capabilities.VertexPrograms ) )
				{
					this.infiniteExtrusionParams = this.shadowDebugPass.VertexProgramParameters;
				}
			}
		}
Exemplo n.º 17
0
		private void InitShadowStencilPass()
		{
			Material matStencil = (Material)MaterialManager.Instance[ STENCIL_SHADOW_VOLUMES_MATERIAL ];

			if ( matStencil == null )
			{
				// Create
				matStencil =
					(Material)
					MaterialManager.Instance.Create( STENCIL_SHADOW_VOLUMES_MATERIAL,
													 ResourceGroupManager.InternalResourceGroupName );
				this.shadowStencilPass = matStencil.GetTechnique( 0 ).GetPass( 0 );

				if ( this.targetRenderSystem.Capabilities.HasCapability( Capabilities.VertexPrograms ) )
				{
					// Enable the finite point light extruder for now, just to get some params
					this.shadowStencilPass.SetVertexProgram(
						ShadowVolumeExtrudeProgram.GetProgramName(
							ShadowVolumeExtrudeProgram.Programs.PointLightFinite ) );

					this.finiteExtrusionParams = this.shadowStencilPass.VertexProgramParameters;
					this.finiteExtrusionParams.SetAutoConstant( 0, GpuProgramParameters.AutoConstantType.WorldViewProjMatrix );
					this.finiteExtrusionParams.SetAutoConstant( 4, GpuProgramParameters.AutoConstantType.LightPositionObjectSpace );
					this.finiteExtrusionParams.SetAutoConstant( 5, GpuProgramParameters.AutoConstantType.ShadowExtrusionDistance );
				}
				matStencil.Compile();
				// Nothing else, we don't use this like a 'real' pass anyway,
				// it's more of a placeholder
			}
			else
			{
				this.shadowStencilPass = matStencil.GetTechnique( 0 ).GetPass( 0 );
				if ( this.targetRenderSystem.Capabilities.HasCapability( Capabilities.VertexPrograms ) )
				{
					this.finiteExtrusionParams = this.shadowStencilPass.VertexProgramParameters;
				}
			}
		}
Exemplo n.º 18
0
		/// <summary>
		///		Overriden from SceneManager.
		/// </summary>
		protected override void RenderSingleObject( IRenderable renderable, Pass pass, bool doLightIteration,
		                                            LightList manualLightList )
		{
			if ( renderable is BspGeometry )
			{
				// Render static level geometry
				if ( doLightIteration )
				{
					// render all geometry without lights first
					RenderStaticGeometry();

					// render geometry affected by each visible light
					foreach ( Light l in lightsAffectingFrustum )
					{
						RenderTextureLighting( l );
					}
				}
				else
				{
					if ( manualLightList.Count == 0 )
					{
						if ( illuminationStage == IlluminationRenderStage.RenderReceiverPass )
						{
							// texture shadows
							RenderTextureShadowOnGeometry();
						}
						else
						{
							// ambient stencil pass, render geometry without lights
							RenderStaticGeometry();
						}
					}
					else
					{
						// render only geometry affected by the provided light
						foreach ( Light l in manualLightList )
						{
							RenderTextureLighting( l );
						}
					}
				}
			}
			else
			{
				base.RenderSingleObject( renderable, pass, doLightIteration, manualLightList );
			}
		}
Exemplo n.º 19
0
		/// <summary>
		///		Internal method for turning a regular pass into a shadow receiver pass.
		/// </summary>
		/// <remarks>
		///		This is only used for texture shadows, basically we're trying to
		///		ensure that objects are rendered with a projective texture.
		///		This method will usually return a standard single-texture pass for
		///		all fixed function passes, but will merge in a vertex program
		///		for passes with vertex programs.
		/// </remarks>
		/// <param name="pass"></param>
		/// <returns></returns>
		protected virtual Pass DeriveShadowReceiverPass( Pass pass )
		{
			if ( this.IsShadowTechniqueTextureBased )
			{
				Pass retPass;
				if ( pass.Parent.ShadowReceiverMaterial != null )
				{
					retPass = pass.Parent.ShadowReceiverMaterial.GetBestTechnique().GetPass( 0 );
				}
				else
				{
					retPass = ( this.shadowTextureCustomReceiverPass != null ? this.shadowTextureCustomReceiverPass : this.shadowReceiverPass );
				}

				// Does incoming pass have a custom shadow receiver program?
				if ( pass.ShadowReceiverVertexProgramName != "" )
				{
					retPass.SetVertexProgram( pass.ShadowReceiverVertexProgramName );
					GpuProgram prg = retPass.VertexProgram;
					// Load this program if not done already
					if ( !prg.IsLoaded )
					{
						prg.Load();
					}
					// Copy params
					retPass.VertexProgramParameters = pass.ShadowReceiverVertexProgramParameters;
					// Also have to hack the light autoparams, that is done later
				}
				else
				{
					if ( retPass == this.shadowTextureCustomReceiverPass )
					{
						if ( this.shadowTextureCustomReceiverPass.VertexProgramName != this.shadowTextureCustomReceiverVertexProgram )
						{
							this.shadowTextureCustomReceiverPass.SetVertexProgram( this.shadowTextureCustomReceiverVertexProgram );
							if ( retPass.HasVertexProgram )
							{
								retPass.VertexProgramParameters = this.shadowTextureCustomReceiverVPParams;
							}
						}
					}
					else
					{
						retPass.SetVertexProgram( "" );
					}
				}
				int keepTUCount;
				// If additive, need lighting parameters & standard programs
				if ( this.IsShadowTechniqueAdditive )
				{
					keepTUCount = 1;
					retPass.LightingEnabled = true;
					retPass.Ambient = pass.Ambient;
					retPass.SelfIllumination = pass.SelfIllumination;
					retPass.Diffuse = pass.Diffuse;
					retPass.Specular = pass.Specular;
					retPass.Shininess = pass.Shininess;
					retPass.SetRunOncePerLight( pass.IteratePerLight,
												pass.RunOnlyOncePerLightType,
												pass.OnlyLightType );
					// We need to keep alpha rejection settings
					retPass.SetAlphaRejectSettings( pass.AlphaRejectFunction, pass.AlphaRejectValue );
					// Copy texture state, shift up one since 0 is shadow texture
					int origPassTUCount = pass.TextureUnitStageCount;
					for ( int t = 0; t < origPassTUCount; ++t )
					{
						int targetIndex = t + 1;
						TextureUnitState tex = ( retPass.TextureUnitStageCount <= targetIndex
													 ?
														 retPass.CreateTextureUnitState()
													 :
														 retPass.GetTextureUnitState( targetIndex ) );
						pass.GetTextureUnitState( t ).CopyTo( tex );
						// If programmable, have to adjust the texcoord sets too
						// D3D insists that texcoordsets match tex unit in programmable mode
						if ( retPass.HasVertexProgram )
							tex.TextureCoordSet = targetIndex;
					}
					keepTUCount = origPassTUCount + 1;
				}
				else
				{
					// need to keep spotlight fade etc
					keepTUCount = retPass.TextureUnitStageCount;
				}

				// Will also need fragment programs since this is a complex light setup
				if ( pass.ShadowReceiverFragmentProgramName != "" )
				{
					// Have to merge the shadow receiver vertex program in
					retPass.SetFragmentProgram( pass.ShadowReceiverFragmentProgramName );
					GpuProgram prg = retPass.FragmentProgram;
					// Load this program if not done already
					if ( !prg.IsLoaded )
					{
						prg.Load();
					}
					// Copy params
					retPass.FragmentProgramParameters = pass.ShadowReceiverFragmentProgramParameters;
					// Did we bind a shadow vertex program?
					if ( pass.HasVertexProgram && !retPass.HasVertexProgram )
					{
						// We didn't bind a receiver-specific program, so bind the original
						retPass.SetVertexProgram( pass.VertexProgramName );
						prg = retPass.VertexProgram;
						// Load this program if required
						if ( !prg.IsLoaded )
						{
							prg.Load();
						}
						// Copy params
						retPass.VertexProgramParameters = pass.VertexProgramParameters;
					}
				}
				else
				{
					// Reset any merged fragment programs from last time
					if ( retPass == this.shadowTextureCustomReceiverPass )
					{
						// reset fp?
						if ( retPass.FragmentProgramName != this.shadowTextureCustomReceiverFragmentProgram )
						{
							retPass.SetFragmentProgram( this.shadowTextureCustomReceiverFragmentProgram );
							if ( retPass.HasFragmentProgram )
							{
								retPass.FragmentProgramParameters = this.shadowTextureCustomReceiverFPParams;
							}
						}
					}
					else
					{
						// Standard shadow receiver pass, reset to no fp
						retPass.SetFragmentProgram( "" );
					}
				}

				// Remove any extra texture units
				while ( retPass.TextureUnitStageCount > keepTUCount )
				{
					retPass.RemoveTextureUnitState( keepTUCount );
				}
				retPass.Load();
				return retPass;
			}
			else
			{
				return pass;
			}
		}
Exemplo n.º 20
0
		protected void InitTextureLighting()
		{
			if ( targetRenderSystem.Capabilities.TextureUnitCount < 2 )
			{
				LogManager.Instance.Write( "--WARNING--At least 2 available texture units are required for BSP dynamic lighting!" );
			}

			Texture texLight = TextureLight.CreateTexture();

			this.textureLightMaterial = (Material)MaterialManager.Instance.GetByName( "Axiom/BspTextureLightMaterial" );
			if ( this.textureLightMaterial == null )
			{
				this.textureLightMaterial =
					(Material)
					MaterialManager.Instance.Create( "Axiom/BspTextureLightMaterial", ResourceGroupManager.DefaultResourceGroupName );
				this.textureLightPass = this.textureLightMaterial.GetTechnique( 0 ).GetPass( 0 );
				// the texture light
				TextureUnitState tex = this.textureLightPass.CreateTextureUnitState( texLight.Name );
				tex.SetColorOperation( LayerBlendOperation.Modulate );
				tex.ColorBlendMode.source2 = LayerBlendSource.Diffuse;
				tex.SetAlphaOperation( LayerBlendOperationEx.Modulate );
				tex.AlphaBlendMode.source2 = LayerBlendSource.Diffuse;
				tex.TextureCoordSet = 2;
				tex.SetTextureAddressingMode( TextureAddressing.Clamp );

				// The geometry texture without lightmap. Use the light texture on this
				// pass, the appropriate texture will be rendered at RenderTextureLighting
				tex = this.textureLightPass.CreateTextureUnitState( texLight.Name );
				tex.SetColorOperation( LayerBlendOperation.Modulate );
				tex.SetAlphaOperation( LayerBlendOperationEx.Modulate );
				tex.SetTextureAddressingMode( TextureAddressing.Wrap );

				this.textureLightPass.SetSceneBlending( SceneBlendType.TransparentAlpha );

				this.textureLightMaterial.CullingMode = CullingMode.None;
				this.textureLightMaterial.Lighting = false;
			}
			else
			{
				this.textureLightPass = this.textureLightMaterial.GetTechnique( 0 ).GetPass( 0 );
			}
		}
Exemplo n.º 21
0
		/// <summary>
		///		If only the first parameter is supplied
		/// </summary>
		public virtual Pass SetPass( Pass pass )
		{
			return this.SetPass( pass, false, true );
		}
Exemplo n.º 22
0
		public void ManualRender( RenderOperation op,
								  Pass pass,
								  Viewport vp,
								  Matrix4 worldMatrix,
								  Matrix4 viewMatrix,
								  Matrix4 projMatrix )
		{
			this.ManualRender( op, pass, vp, worldMatrix, viewMatrix, projMatrix, false );
		}
Exemplo n.º 23
0
        protected virtual void UpdateGpuProgramParameters(Pass pass)
        {
            if ( pass.IsProgrammable )
            {
                if (_gpuParamsDirty == 0)
                	return;

                if (_gpuParamsDirty != 0)
                	pass.UpdateAutoParams(autoParamDataSource, _gpuParamsDirty);

                if ( pass.HasVertexProgram )
                {
                    targetRenderSystem.BindGpuProgramParameters( GpuProgramType.Vertex, pass.VertexProgramParameters,
                                                                 _gpuParamsDirty );
                }

                if ( pass.HasGeometryProgram )
                {
                    targetRenderSystem.BindGpuProgramParameters( GpuProgramType.Geometry, pass.GeometryProgramParameters,
                                                                 _gpuParamsDirty );
                }

                if ( pass.HasFragmentProgram )
                {
                    targetRenderSystem.BindGpuProgramParameters( GpuProgramType.Fragment, pass.FragmentProgramParameters,
                                                                 _gpuParamsDirty );
                }

                //_gpuParamsDirty = 0;
            }

        }
Exemplo n.º 24
0
		/// <summary>
		///		Manual rendering method, for advanced users only.
		/// </summary>
		/// <remarks>
		///		This method allows you to send rendering commands through the pipeline on
		///		demand, bypassing any normal world processing. You should only use this if you
		///		really know what you're doing; the engine does lots of things for you that you really should
		///		let it do. However, there are times where it may be useful to have this manual interface,
		///		for example overlaying something on top of the scene.
		///		<p/>
		///		Because this is an instant rendering method, timing is important. The best
		///		time to call it is from a RenderTarget event handler.
		///		<p/>
		///		Don't call this method a lot, it's designed for rare (1 or 2 times per frame) use.
		///		Calling it regularly per frame will cause frame rate drops!
		/// </remarks>
		/// <param name="op">A RenderOperation object describing the rendering op.</param>
		/// <param name="pass">The Pass to use for this render.</param>
		/// <param name="vp">Reference to the viewport to render to.</param>
		/// <param name="worldMatrix">The transform to apply from object to world space.</param>
		/// <param name="viewMatrix">The transform to apply from object to view space.</param>
		/// <param name="projMatrix">The transform to apply from view to screen space.</param>
		/// <param name="doBeginEndFrame">
		///		If true, BeginFrame() and EndFrame() are called, otherwise not.
		///		You should leave this as false if you are calling this within the main render loop.
		/// </param>
		public virtual void ManualRender( RenderOperation op,
										  Pass pass,
										  Viewport vp,
										  Matrix4 worldMatrix,
										  Matrix4 viewMatrix,
										  Matrix4 projMatrix,
										  bool doBeginEndFrame )
		{
			// configure all necessary parameters
			this.targetRenderSystem.Viewport = vp;
			this.targetRenderSystem.WorldMatrix = worldMatrix;
			this.targetRenderSystem.ViewMatrix = viewMatrix;
			this.targetRenderSystem.ProjectionMatrix = projMatrix;

			if ( doBeginEndFrame )
			{
				this.targetRenderSystem.BeginFrame();
			}

			// set the pass and render the object
			this.SetPass( pass );
			this.targetRenderSystem.Render( op );

			if ( doBeginEndFrame )
			{
				this.targetRenderSystem.EndFrame();
			}
		}
Exemplo n.º 25
0
		/// <summary>
		///		Internal utility method for rendering a single object.
		/// </summary>
		/// <param name="renderable">The renderable to issue to the pipeline.</param>
		/// <param name="pass">The pass which is being used.</param>
		/// <param name="doLightIteration">If true, this method will issue the renderable to
		/// the pipeline possibly multiple times, if the pass indicates it should be
		/// done once per light.</param>
		/// <param name="manualLightList">Only applicable if 'doLightIteration' is false, this
		/// method allows you to pass in a previously determined set of lights
		/// which will be used for a single render of this object.</param>
		protected virtual void RenderSingleObject( IRenderable renderable,
												   Pass pass,
												   bool doLightIteration,
												   LightList manualLightList )
		{
			ushort numMatrices = 0;

			// grab the current scene detail level
			PolygonMode camPolyMode = this.cameraInProgress.PolygonMode;

			// get the world matrices and the count
			renderable.GetWorldTransforms( this.xform );
			numMatrices = renderable.NumWorldTransforms;

			// set the world matrices in the render system
			if ( numMatrices > 1 )
			{
				this.targetRenderSystem.SetWorldMatrices( this.xform, numMatrices );
			}
			else
			{
				this.targetRenderSystem.WorldMatrix = this.xform[ 0 ];
			}

			// issue view/projection changes (if any)
			this.UseRenderableViewProjection( renderable );

			if ( !this.suppressRenderStateChanges )
			{
				bool passSurfaceAndLightParams = true;
				if ( pass.IsProgrammable )
				{
					// Tell auto params object about the renderable change
					this.autoParamDataSource.Renderable = renderable;
					pass.UpdateAutoParamsNoLights( this.autoParamDataSource );
					if ( pass.HasVertexProgram )
					{
						passSurfaceAndLightParams = pass.VertexProgram.PassSurfaceAndLightStates;
					}
				}

				// issue texture units that depend on updated view matrix
				// reflective env mapping is one case
				for ( int i = 0; i < pass.TextureUnitStageCount; i++ )
				{
					TextureUnitState texUnit = pass.GetTextureUnitState( i );

					if ( texUnit.HasViewRelativeTexCoordGen )
					{
					    targetRenderSystem.SetTextureUnitSettings( i, texUnit );
					    //this.targetRenderSystem.SetTextureUnit( i, texUnit, !pass.HasFragmentProgram );
					}
				}

				// Normalize normals
				bool thisNormalize = renderable.NormalizeNormals;

				if ( thisNormalize != normalizeNormals )
				{
					this.targetRenderSystem.NormalizeNormals = thisNormalize;
					normalizeNormals = thisNormalize;
				}

				// Set up the solid / wireframe override
				PolygonMode requestedMode = pass.PolygonMode;
				if ( renderable.PolygonModeOverrideable == true )
				{
					// check camera detial only when render detail is overridable
					if ( requestedMode > camPolyMode )
					{
						// only downgrade detail; if cam says wireframe we don't go up to solid
						requestedMode = camPolyMode;
					}
				}

				if ( requestedMode != this.lastPolyMode )
				{
					this.targetRenderSystem.PolygonMode = requestedMode;
					this.lastPolyMode = requestedMode;
				}

				// TODO: Add ClipPlanes to RenderSystem.cs
				// This is removed in OGRE 1.6.0... no need to port - J. Price
				//targetRenderSystem.ClipPlanes = renderable.ClipPlanes;

				// get the renderables render operation
				op = renderable.RenderOperation;
				// TODO: Add srcRenderable to RenderOperation.cs
				//op.srcRenderable = renderable;

				if ( doLightIteration )
				{
					// Here's where we issue the rendering operation to the render system
					// Note that we may do this once per light, therefore it's in a loop
					// and the light parameters are updated once per traversal through the
					// loop
					LightList rendLightList = renderable.Lights;
					bool iteratePerLight = pass.IteratePerLight;
					int numIterations = iteratePerLight ? rendLightList.Count : 1;
					LightList lightListToUse = null;

					for ( int i = 0; i < numIterations; i++ )
					{
						// determine light list to use
						if ( iteratePerLight )
						{
							localLightList.Clear();

							// check whether we need to filter this one out
							if ( pass.RunOnlyOncePerLightType && pass.OnlyLightType != rendLightList[ i ].Type )
							{
								// skip this one
								continue;
							}

							localLightList.Add( rendLightList[ i ] );
							lightListToUse = localLightList;
						}
						else
						{
							// use complete light list
							lightListToUse = rendLightList;
						}

						if ( pass.IsProgrammable )
						{
							// Update any automatic gpu params for lights
							// Other bits of information will have to be looked up
							this.autoParamDataSource.SetCurrentLightList( lightListToUse );
							pass.UpdateAutoParamsLightsOnly( this.autoParamDataSource );

						    UpdateGpuProgramParameters( pass );
						}

						// Do we need to update light states?
						// Only do this if fixed-function vertex lighting applies
						if ( pass.LightingEnabled && passSurfaceAndLightParams )
						{
							this.targetRenderSystem.UseLights( lightListToUse, pass.MaxSimultaneousLights );
						}
                        this.targetRenderSystem.CurrentPassIterationCount = pass.IterationCount;
						// issue the render op
						this.targetRenderSystem.Render( op );
					} // iterate per light
				}
				else
				{
					// do we need to update GPU program parameters?
					if ( pass.IsProgrammable )
					{
						// do we have a manual light list
						if ( manualLightList != null )
						{
							// Update any automatic gpu params for lights
							// Other bits of information will have to be looked up
							this.autoParamDataSource.SetCurrentLightList( manualLightList );
							pass.UpdateAutoParamsLightsOnly( this.autoParamDataSource );
						}

					    UpdateGpuProgramParameters( pass );
					}

					// Use manual lights if present, and not using vertex programs
					if ( manualLightList != null && pass.LightingEnabled && passSurfaceAndLightParams )
					{
						this.targetRenderSystem.UseLights( manualLightList, pass.MaxSimultaneousLights );
					}
                    this.targetRenderSystem.CurrentPassIterationCount = pass.IterationCount;
					// issue the render op
					this.targetRenderSystem.Render( op );
				}
			}
			else
			{
				// suppressRenderStateChanges
				// Just render
                this.targetRenderSystem.CurrentPassIterationCount = 1;
				this.targetRenderSystem.Render( op );
			}

			// Reset view / projection changes if any
			this.ResetViewProjectionMode();
		}
Exemplo n.º 26
0
		private void InitShadowReceiverPass()
		{
			Material matShadRec = (Material)MaterialManager.Instance[ TEXTURE_SHADOW_RECEIVER_MATERIAL ];

			if ( matShadRec == null )
			{
				matShadRec =
					(Material)
					MaterialManager.Instance.Create( TEXTURE_SHADOW_RECEIVER_MATERIAL,
													 ResourceGroupManager.InternalResourceGroupName );
				this.shadowReceiverPass = matShadRec.GetTechnique( 0 ).GetPass( 0 );
				this.shadowReceiverPass.SetSceneBlending( SceneBlendFactor.DestColor, SceneBlendFactor.Zero );
				// Don't set lighting and blending modes here, depends on additive / modulative
				TextureUnitState t = this.shadowReceiverPass.CreateTextureUnitState();
                t.SetTextureAddressingMode( TextureAddressing.Clamp );
			}
			else
			{
				this.shadowReceiverPass = matShadRec.GetTechnique( 0 ).GetPass( 0 );
			}
		}
Exemplo n.º 27
0
		/// <summary>
		///		Internal method to validate whether a Renderable should be allowed to render.
		/// </summary>
		/// <remarks>
		///		Called just before a pass is about to be used for rendering a Renderable to
		///		allow the SceneManager to omit it if required. A return value of false
		///		skips it.
		/// </remarks>
		protected virtual bool ValidateRenderableForRendering( Pass pass, IRenderable renderable )
		{
			// Skip this renderable if we're doing texture shadows, it casts shadows
			// and we're doing the render receivers pass
			if ( !this.suppressShadows && this.currentViewport.ShowShadows && this.IsShadowTechniqueTextureBased )
			{
				if ( this.illuminationStage == IlluminationRenderStage.RenderReceiverPass &&
					 renderable.CastsShadows && !this.shadowTextureSelfShadow )
				{
					return false;
				}
				// Some duplication here with validatePassForRendering, for transparents
				if ( ( ( this.IsShadowTechniqueModulative
						 && this.illuminationStage == IlluminationRenderStage.RenderReceiverPass )
					   || this.illuminationStage == IlluminationRenderStage.RenderToTexture
					   || this.suppressRenderStateChanges ) &&
					 pass.Index > 0 )
				{
					return false;
				}
			}
			return true;
		}
Exemplo n.º 28
0
		private void InitShadowCasterPass()
		{
			Material matPlainBlack = (Material)MaterialManager.Instance[ TEXTURE_SHADOW_CASTER_MATERIAL ];

			if ( matPlainBlack == null )
			{
				matPlainBlack =
					(Material)
					MaterialManager.Instance.Create( TEXTURE_SHADOW_CASTER_MATERIAL,
													 ResourceGroupManager.InternalResourceGroupName );
				this.shadowCasterPlainBlackPass = matPlainBlack.GetTechnique( 0 ).GetPass( 0 );
				// Lighting has to be on, because we need shadow coloured objects
				// Note that because we can't predict vertex programs, we'll have to
				// bind light values to those, and so we bind White to ambient
				// reflectance, and we'll set the ambient colour to the shadow colour
				this.shadowCasterPlainBlackPass.Ambient = ColorEx.White;
				this.shadowCasterPlainBlackPass.Diffuse = ColorEx.Black;
				this.shadowCasterPlainBlackPass.SelfIllumination = ColorEx.Black;
				this.shadowCasterPlainBlackPass.Specular = ColorEx.Black;
				// Override fog
				this.shadowCasterPlainBlackPass.SetFog( true, FogMode.None );
				// no textures or anything else, we will bind vertex programs
				// every so often though
			}
			else
			{
				this.shadowCasterPlainBlackPass = matPlainBlack.GetTechnique( 0 ).GetPass( 0 );
			}
		}
Exemplo n.º 29
0
		public virtual void InjectRenderWithPass( Pass pass, IRenderable rend )
		{
			this.InjectRenderWithPass( pass, rend, true );
		}
Exemplo n.º 30
0
		private void InitShadowModulativePass()
		{
			Material matModStencil = (Material)MaterialManager.Instance[ STENCIL_SHADOW_MODULATIVE_MATERIAL ];

			if ( matModStencil == null )
			{
				// Create
				matModStencil =
					(Material)
					MaterialManager.Instance.Create( STENCIL_SHADOW_MODULATIVE_MATERIAL,
													 ResourceGroupManager.InternalResourceGroupName );

				this.shadowModulativePass = matModStencil.GetTechnique( 0 ).GetPass( 0 );
				this.shadowModulativePass.SetSceneBlending( SceneBlendFactor.DestColor, SceneBlendFactor.Zero );
				this.shadowModulativePass.LightingEnabled = false;
				this.shadowModulativePass.DepthWrite = false;
				this.shadowModulativePass.DepthCheck = false;
				TextureUnitState t = this.shadowModulativePass.CreateTextureUnitState();
				t.SetColorOperationEx(
					LayerBlendOperationEx.Modulate,
					LayerBlendSource.Manual,
					LayerBlendSource.Current,
					this.shadowColor );
				this.shadowModulativePass.CullingMode = CullingMode.None;
			}
			else
			{
				this.shadowModulativePass = matModStencil.GetTechnique( 0 ).GetPass( 0 );
			}
		}