Exemplo n.º 1
0
		public override void SetLightCount( int[] currLightCount )
		{
			for ( int type = 0; type < 3; type++ )
			{
				for ( int i = 0; i < currLightCount[ type ]; i++ )
				{
					var curParams = new LightParams();

					if ( type == 0 )
					{
						curParams.Type = LightType.Point;
					}
					else if ( type == 1 )
					{
						curParams.Type = LightType.Directional;
					}
					else if ( type == 2 )
					{
						curParams.Type = LightType.Spotlight;
					}

					this.lightParamsList.Add( curParams );
				}
			}
		}
Exemplo n.º 2
0
		internal bool AddPSIlluminationInvocation( LightParams curLightParams, Function psMain, int groupOrder,
		                                           ref int internalCounter )
		{
			FunctionInvocation curFuncInvocation = null;

			//merge diffuse color with vertex color if need to
			if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) != 0 )
			{
				curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncModulate, groupOrder,
				                                            internalCounter++ );
				curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In,
				                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
				curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In,
				                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
				curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.Out,
				                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
				psMain.AddAtomInstance( curFuncInvocation );
			}
			//merge specular color with vertex color if need to
			if ( this.specularEnable && ( this.trackVertexColorType & TrackVertexColor.Specular ) != 0 )
			{
				curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncModulate, groupOrder,
				                                            internalCounter++ );
				curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In,
				                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
				curFuncInvocation.PushOperand( curLightParams.SpecularColor, Operand.OpSemantic.In,
				                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
				curFuncInvocation.PushOperand( curLightParams.SpecularColor, Operand.OpSemantic.Out,
				                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
				psMain.AddAtomInstance( curFuncInvocation );
			}

			switch ( curLightParams.Type )
			{
				case LightType.Directional:
					if ( this.specularEnable )
					{
						curFuncInvocation = new FunctionInvocation( SGXFuncLightDirectionalDiffuseSpecular, groupOrder,
						                                            internalCounter++ );
						curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( this.psInViewPos, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( curLightParams.SpecularColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.surfaceShininess, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.Out,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						psMain.AddAtomInstance( curFuncInvocation );
					}

					else
					{
						curFuncInvocation = new FunctionInvocation( SGXFuncLightDirectionalDiffuse, groupOrder,
						                                            internalCounter++ );
						curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						psMain.AddAtomInstance( curFuncInvocation );
					}
					break;
				case LightType.Point:
					if ( this.specularEnable )
					{
						curFuncInvocation = new FunctionInvocation( SGXFuncLightPointDiffuseSpecular, groupOrder,
						                                            internalCounter++ );
						curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( this.psInViewPos, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.Position, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( curLightParams.AttenuatParams, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( curLightParams.SpecularColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.surfaceShininess, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.Out,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						psMain.AddAtomInstance( curFuncInvocation );
					}
					else
					{
						curFuncInvocation = new FunctionInvocation( SGXFuncLightPointDiffuse, groupOrder,
						                                            internalCounter++ );
						curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( this.psInViewPos, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.Position, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( curLightParams.AttenuatParams, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						psMain.AddAtomInstance( curFuncInvocation );
					}
					break;
				case LightType.Spotlight:
					if ( this.specularEnable )
					{
						curFuncInvocation = new FunctionInvocation( SGXFuncLightSpotDiffuseSpecular, groupOrder,
						                                            internalCounter++ );
						curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( this.psInViewPos, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.Position, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( curLightParams.AttenuatParams, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.SpotParams, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( curLightParams.SpecularColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.surfaceShininess, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.Out,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
					}
					else
					{
						curFuncInvocation = new FunctionInvocation( SGXFuncLightSpotDiffuse, groupOrder,
						                                            internalCounter++ );
						curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( this.psInViewPos, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.Position, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( curLightParams.AttenuatParams, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.SpotParams, Operand.OpSemantic.In );
						curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out,
						                               (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) );
						psMain.AddAtomInstance( curFuncInvocation );
					}
					break;
			}

			return true;
		}
Exemplo n.º 3
0
		internal bool AddVSIlluminationInvocation( LightParams curLightParams, Function vsMain, int groupOrder,
		                                           ref int internalCounter )
		{
			FunctionInvocation curFuncInvocation = null;

			//Computer light direction in texture space.
			if ( curLightParams.Direction != null && curLightParams.VSOutDirection != null )
			{
				//Transform to texture space.
				if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent )
				{
					curFuncInvocation = new FunctionInvocation( SGXFuncTranformNormal, groupOrder, internalCounter++ );
					curFuncInvocation.PushOperand( this.vsTBNMatrix, Operand.OpSemantic.In );
					curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In,
					                               ( (int)Operand.OpMask.X | (int)Operand.OpMask.Y |
					                                 (int)Operand.OpMask.Z ) );
					curFuncInvocation.PushOperand( curLightParams.VSOutDirection, Operand.OpSemantic.Out );
					vsMain.AddAtomInstance( curFuncInvocation );
				}
					//Output object space
				else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object )
				{
					curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder,
					                                            internalCounter++ );
					curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In,
					                               ( (int)Operand.OpMask.X | (int)Operand.OpMask.Y |
					                                 (int)Operand.OpMask.Z ) );
					curFuncInvocation.PushOperand( curLightParams.VSOutDirection, Operand.OpSemantic.Out );
					vsMain.AddAtomInstance( curFuncInvocation );
				}
			}

			//Transform light vector to target space
			if ( curLightParams.Position != null && curLightParams.VSOutToLightDir != null )
			{
				//Compute light vector.
				curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncSubtract, groupOrder,
				                                            internalCounter++ );
				curFuncInvocation.PushOperand( curLightParams.Position, Operand.OpSemantic.In,
				                               ( (int)Operand.OpMask.X | (int)Operand.OpMask.Y | (int)Operand.OpMask.Z ) );
				curFuncInvocation.PushOperand( this.vsWorldPosition, Operand.OpSemantic.In );
				curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.Out );
				vsMain.AddAtomInstance( curFuncInvocation );

				//Transform to object space
				curFuncInvocation = new FunctionInvocation( SGXFuncTranformNormal, groupOrder, internalCounter++ );
				curFuncInvocation.PushOperand( this.worldInvRotMatrix, Operand.OpSemantic.In );
				curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.In );
				curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.Out );
				vsMain.AddAtomInstance( curFuncInvocation );

				if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent )
				{
					curFuncInvocation = new FunctionInvocation( SGXFuncTranformNormal, groupOrder, internalCounter++ );
					curFuncInvocation.PushOperand( this.vsTBNMatrix, Operand.OpSemantic.In );
					curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.In );
					curFuncInvocation.PushOperand( curLightParams.VSOutToLightDir, Operand.OpSemantic.Out );
					vsMain.AddAtomInstance( curFuncInvocation );
				}
					//Output object space
				else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object )
				{
					curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder,
					                                            internalCounter++ );
					curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.In );
					curFuncInvocation.PushOperand( curLightParams.VSOutToLightDir, Operand.OpSemantic.Out );
					vsMain.AddAtomInstance( curFuncInvocation );
				}
			}

			return true;
		}