private void BuildFFPSubRenderState( int subRenderStateOrder, string subRenderStateType,
		                                     ShaderGenerator.SGPass sgPass, TargetRenderState renderState )
		{
			if ( subRenderStateOrder == -1 )
			{
				throw new Exception( "Actual sub render type needs to be declared" );
			}

			SubRenderState subRenderState;

			subRenderState = sgPass.GetCustomFFPSubState( subRenderStateOrder );

			if ( subRenderState == null )
			{
				subRenderState = ShaderGenerator.Instance.CreateSubRenderState( subRenderStateType );
			}

			if ( subRenderState.PreAddToRenderState( renderState, sgPass.SrcPass, sgPass.DstPass ) )
			{
				renderState.AddSubRenderStateInstance( subRenderState );
			}
			else
			{
				ShaderGenerator.Instance.DestroySubRenderState( subRenderState );
			}
		}
示例#2
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;
		}
示例#3
0
		internal void ReleasePrograms( Graphics.Pass pass, TargetRenderState renderState )
		{
			ProgramSet programSet = renderState.ProgramSet;

			pass.SetVertexProgram( string.Empty );
			pass.SetFragmentProgram( string.Empty );

			renderState.DestroyProgramSet();

			foreach ( var key in this.vertexShaderMap.Keys )
			{
				if ( true ) //TODO
				{
					DestroyGpuProgram( this.vertexShaderMap[ key ] );
					this.vertexShaderMap.Remove( key );
					break;
				}
			}

			foreach ( var key in this.fragmentShaderMap.Keys )
			{
				if ( true )
				{
					DestroyGpuProgram( this.fragmentShaderMap[ key ] );
					this.fragmentShaderMap.Remove( key );
					break;
				}
			}
		}
示例#4
0
		public override bool PreAddToRenderState( TargetRenderState targetRenderState, Graphics.Pass srcPass,
		                                          Graphics.Pass dstPass )
		{
			TrackVertexColor trackColor = srcPass.VertexColorTracking;

			if ( trackColor != null )
			{
				AddResolveStageMask( (int)StageFlags.VsInputDiffuse );
			}

			return true;
		}
示例#5
0
		public override bool PreAddToRenderState( TargetRenderState targetRenderState, Graphics.Pass srcPass,
		                                          Graphics.Pass dstPass )
		{
			bool isValid = true;
			Technique firstTech = srcPass.Parent.Parent.GetTechnique( 0 );
			//TODO
			//var hsAny = firstTech.UserObjectBindings.GetUserAny(HardwareSkinning.HsDataBindName);
			if ( false ) //hsAny.isEmpty == false)
			{
			}
			//If there is no associated techniqe, default to linear skinning as a pass-through
			if ( this.activeTechnique == null )
			{
				SetHardwareSkinningParam( 0, 0, RTShaderSystem.SkinningType.Linear, false, false );
			}
			int boneCount = this.activeTechnique.BoneCount;
			int weightCount = this.activeTechnique.WeightCount;

			bool doBoneCalculations = isValid && ( boneCount != 0 ) && ( boneCount <= 256 ) && ( weightCount != 0 ) &&
			                          ( weightCount <= 4 ) &&
			                          ( ( this.creator == null ) || ( boneCount <= this.creator.MaxCalculableBoneCount ) );

			this.activeTechnique.DoBoneCalculations = doBoneCalculations;


			if ( ( doBoneCalculations ) && ( this.creator != null ) )
			{
				//update the receiver and caster materials
				if ( dstPass.Parent.ShadowCasterMaterial == null )
				{
					Material mat = this.creator.GetCustomShadowCasterMaterial( this.skinningType, weightCount - 1 );
					dstPass.Parent.SetShadowCasterMaterial( mat.Name );
				}

				if ( dstPass.Parent.ShadowReceiverMaterial == null )
				{
					Material mat = this.creator.GetCustomShadowCasterMaterial( this.skinningType, weightCount - 1 );
					dstPass.Parent.SetShadowReceiverMaterial( mat.Name );
				}
			}
			return true;
		}
示例#6
0
		public override bool PreAddToRenderState( TargetRenderState targetRenderState, Graphics.Pass srcPass,
		                                          Graphics.Pass dstPass )
		{
			if ( srcPass.LightingEnabled == false || srcPass.Parent.Parent.ReceiveShadows == false )
			{
				return false;
			}

			foreach ( var it in this.shadowTextureParamsList )
			{
				TextureUnitState curShadowTexture = dstPass.CreateTextureUnitState();

				//TODO
				//curShadowTexture.ContentType = TextureUnitState.ContentShadow;
				curShadowTexture.SetTextureAddressingMode( TextureAddressing.Border );
				curShadowTexture.TextureBorderColor = Core.ColorEx.White;
				it.TextureSamplerIndex = dstPass.TextureUnitStatesCount - 1;
			}

			return true;
		}
		/// <summary>
		///   build render state from the given pass that emulates the fixed function pipeline behavior
		/// </summary>
		/// <param name="sgPass"> The shader generator pass representation. Contains both source and destination pass </param>
		/// <param name="renderState"> The target render state that will hold the given pass FFP representation </param>
		public void BuildRenderState( ShaderGenerator.SGPass sgPass, TargetRenderState renderState )
		{
			renderState.Reset();

			//Build transformation sub state
			BuildFFPSubRenderState( -1, FFPTransform.FFPType, sgPass, renderState );

			//Build color sub state
			BuildFFPSubRenderState( -1, FFPTransform.FFPType, sgPass, renderState );

			//Build lighting sub state.
			BuildFFPSubRenderState( -1, FFPTransform.FFPType, sgPass, renderState );

			//Build texturing sub state
			BuildFFPSubRenderState( -1, FFPTransform.FFPType, sgPass, renderState );

			//Build fog sub state
			BuildFFPSubRenderState( -1, FFPTransform.FFPType, sgPass, renderState );

			//resolve color stage flags
			ResolveColorStageFlags( sgPass, renderState );
		}
示例#8
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);
        }
示例#9
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;
		}
示例#10
0
		internal void AcquirePrograms( Graphics.Pass pass, TargetRenderState renderState )
		{
			//Create the CPU programs
			if ( !renderState.CreateCpuPrograms() )
			{
				throw new Core.AxiomException( "Could not apply render state " );
			}

			ProgramSet programSet = renderState.ProgramSet;

			//Create the GPU programs
			if ( !CreateGpuPrograms( programSet ) )
			{
				throw new Core.AxiomException( "Could not create gpu program from render state " );
			}

			//bind the created gpu programs to the target pass
			pass.SetVertexProgram( programSet.GpuVertexProgram.Name );
			pass.SetFragmentProgram( programSet.GpuFragmentProgram.Name );

			//Bind uniform parameters to pass parameters
			BindUniformParameters( programSet.CpuVertexProgram, pass.VertexProgramParameters );
			BindUniformParameters( programSet.CpuFragmentProgram, pass.FragmentProgramParameters );
		}
		private void ResolveColorStageFlags( ShaderGenerator.SGPass sgPass, TargetRenderState renderState )
		{
			var subRenderStateList = renderState.TemplateSubRenderStateList;
			FFPColor colorSubState = null;

			//find the color sub state
			foreach ( var curSubRenderState in subRenderStateList )
			{
				if ( curSubRenderState.Type == FFPColor.FFPType )
				{
					colorSubState = curSubRenderState as FFPColor;
				}
			}

			foreach ( var curSubRenderState in subRenderStateList )
			{
				//Add vertex shader specular lighting output in case of specular enabled.
				if ( curSubRenderState.Type == FFPLighting.FFPType )
				{
					colorSubState.AddResolveStageMask( (int)FFPColor.StageFlags.VsOutputdiffuse );

					Pass srcPass = sgPass.SrcPass;

					if ( srcPass.Shininess > 0 && srcPass.Specular != ColorEx.Black )
					{
						colorSubState.AddResolveStageMask( (int)FFPColor.StageFlags.VsOutputSpecular );
					}
					break;
				}
			}
		}
示例#12
0
		public override bool PreAddToRenderState( TargetRenderState targetRenderState, Graphics.Pass srcPass,
		                                          Graphics.Pass dstPass )
		{
			if ( srcPass.LightingEnabled == false )
			{
				return false;
			}

			var lightCount = new int[3];
			targetRenderState.GetLightCount( out lightCount );

			TrackVertexColorType = srcPass.VertexColorTracking;

			if ( srcPass.Shininess > 0.0 && srcPass.Specular != ColorEx.Black )
			{
				SpecularEnable = true;
			}
			else
			{
				SpecularEnable = false;
			}

			//Case this pass should run once per light(s) -> override the light policy.
			if ( srcPass.IteratePerLight )
			{
				//This is the preferred case -> only one type of light is handled
				if ( srcPass.RunOnlyOncePerLightType )
				{
					if ( srcPass.OnlyLightType == LightType.Point )
					{
						lightCount[ 0 ] = srcPass.LightsPerIteration;
						lightCount[ 1 ] = 0;
						lightCount[ 2 ] = 0;
					}
					else if ( srcPass.OnlyLightType == LightType.Directional )
					{
						lightCount[ 0 ] = 0;
						lightCount[ 1 ] = srcPass.LightsPerIteration;
						lightCount[ 2 ] = 0;
					}
					else if ( srcPass.OnlyLightType == LightType.Spotlight )
					{
						lightCount[ 0 ] = 0;
						lightCount[ 1 ] = 0;
						lightCount[ 2 ] = srcPass.LightsPerIteration;
					}
				}
				else
				{
					throw new AxiomException(
						"Using iterative lighting method with RT Shader System requires specifying explicit light type." );
				}
			}

			SetLightCount( lightCount );

			return true;
		}
示例#13
0
		public override bool PreAddToRenderState( TargetRenderState targetRenderState, Graphics.Pass srcPass,
		                                          Graphics.Pass dstPass )
		{
			return base.PreAddToRenderState( targetRenderState, srcPass, dstPass );
		}
示例#14
0
		public override bool PreAddToRenderState( TargetRenderState targetRenderState, Pass srcPass, Pass dstPass )
		{
			FogMode fMode;
			ColorEx newFogColor;
			Real newFogStart, newFogEnd, newFogDensity;

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

				if ( sceneMgr == null )
				{
					fMode = FogMode.None;
					newFogColor = ColorEx.White;
					newFogStart = 0.0f;
					newFogEnd = 0.0f;
					newFogDensity = 0.0f;
				}
				else
				{
					fMode = sceneMgr.FogMode;
					newFogColor = sceneMgr.FogColor;
					newFogStart = sceneMgr.FogStart;
					newFogEnd = sceneMgr.FogEnd;
					newFogDensity = sceneMgr.FogDensity;
				}

				this.passOverrideParams = false;
			}
			//Set fog properties
			SetFogProperties( fMode, newFogColor, newFogStart, newFogEnd, newFogDensity );

			//Override scene fog since it will happen in shader
			dstPass.SetFog( true, FogMode.None, newFogColor, newFogDensity, newFogStart, newFogEnd );
			return true;
		}
示例#15
0
		public virtual bool PreAddToRenderState( TargetRenderState targetRenderState, Graphics.Pass srcPass,
		                                         Graphics.Pass dstPass )
		{
			return true;
		}
示例#16
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TargetRenderState obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
示例#17
0
		public override bool PreAddToRenderState( TargetRenderState targetRenderState, Pass srcPass, Pass dstPass )
		{
			if ( srcPass.LightingEnabled == false )
			{
				return false;
			}

			var lightCount = new int[3];

			targetRenderState.GetLightCount( out lightCount );

			TextureUnitState normalMapTexture = dstPass.CreateTextureUnitState();

			normalMapTexture.SetTextureName( this.normalMapTextureName );
			normalMapTexture.SetTextureFiltering( this.normalMapMinFilter, this.normalMapMagFilter, this.normalMapMipfilter );
			normalMapTexture.TextureAnisotropy = (int)this.normalMapAnisotropy;
			normalMapTexture.TextureMipmapBias = this.normalMapMipBias;
			this.normalMapSamplerIndex = dstPass.TextureUnitStatesCount - 1;

			TrackVertexColorType = ( srcPass.VertexColorTracking );

			if ( srcPass.Shininess > 0 && srcPass.Specular != ColorEx.Black )
			{
				SpecularEnable = true;
			}
			else
			{
				SpecularEnable = false;
			}

			//Case this pass should run once per light(s)
			if ( srcPass.IteratePerLight )
			{
				//This is the preferred case -> only one type of light is handled
				if ( srcPass.RunOnlyOncePerLightType )
				{
					if ( srcPass.OnlyLightType == LightType.Point )
					{
						lightCount[ 0 ] = srcPass.LightsPerIteration;
						lightCount[ 1 ] = 0;
						lightCount[ 2 ] = 0;
					}
					else if ( srcPass.OnlyLightType == LightType.Directional )
					{
						lightCount[ 0 ] = 0;
						lightCount[ 1 ] = srcPass.LightsPerIteration;
						lightCount[ 2 ] = 0;
					}
					else if ( srcPass.OnlyLightType == LightType.Spotlight )
					{
						lightCount[ 0 ] = 0;
						lightCount[ 1 ] = 0;
						lightCount[ 2 ] = srcPass.LightsPerIteration;
					}
				}

					//This is wors case -> all light types epected to be handled.
					//Can not handle this request in efficient way - throw an exception
				else
				{
					throw new AxiomException(
						"Using iterative lighting method with RT Shader System requires specifying explicit light type." );
				}
			}

			SetLightCount( lightCount );
			return true;
		}
示例#18
0
 public override bool PreAddToRenderState(TargetRenderState targetRenderState, Graphics.Pass srcPass,
                                          Graphics.Pass dstPass)
 {
     return(base.PreAddToRenderState(targetRenderState, srcPass, dstPass));
 }