Pipeline state represents all GPU states as single object.
Inheritance: GraphicsResource
Example #1
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flag"></param>
		void EnumAction ( PipelineState ps, Flags flag )
		{
			ps.BlendState			=	BlendState.Opaque;
			ps.DepthStencilState	=	DepthStencilState.None;
			ps.Primitive			=	Primitive.TriangleList;
			ps.VertexInputElements	=	VertexInputElement.Empty;

			if (flag==Flags.COC_TO_ALPHA) {
				ps.BlendState			=	BlendState.AlphaOnly;
			}
		}
Example #2
0
		void EnumFunc(PipelineState ps, int flag)
		{
			var flags = (PolyFlags)flag;

			ps.VertexInputElements	= VertexInputElement.FromStructure<Gis.GeoPoint>();
			ps.BlendState			= flags.HasFlag(PolyFlags.XRAY)			? BlendState.Additive		: BlendState.AlphaBlend;
			ps.DepthStencilState	= flags.HasFlag(PolyFlags.NO_DEPTH)		? DepthStencilState.None	: DepthStencilState.Default;
			ps.RasterizerState		= flags.HasFlag(PolyFlags.CULL_NONE)	? RasterizerState.CullNone	: RasterizerState.CullCW;

			ps.Primitive = Primitive.TriangleList;
		}
Example #3
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flags"></param>
		void Enum ( PipelineState ps, ShaderFlags flags )
		{
			ps.Primitive			=	Primitive.TriangleList;
			ps.VertexInputElements	=	VertexInputElement.Empty;
			ps.BlendState			=	BlendState.Opaque;
			ps.RasterizerState		=	RasterizerState.CullNone;
			ps.DepthStencilState	=	DepthStencilState.None;

			if (flags==ShaderFlags.SSAO) {
				ps.BlendState = BlendState.Opaque;
			}
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="rs"></param>
		/// <param name="maxTextures"></param>
		internal MaterialInstance ( RenderSystem rs, ContentManager content, MaterialData parameters, IEnumerable<TextureMapBind> textureBinds, SurfaceFlags surfaceFlags )
		{
			if (rs==null) {
				throw new ArgumentNullException("rs");
			}

			if (textureBinds.Count()<0 || textureBinds.Count()>MaxTextures) {
				throw new ArgumentException("textureCount", "Must be less or equal to " + MaxTextures.ToString() );
			}


			//
			//	Pipeline states :
			//
			var factory	=	rs.SceneRenderer.Factory;

			var gbufferRigid	=	SurfaceFlags.GBUFFER | SurfaceFlags.RIGID	| surfaceFlags ;
			var gbufferSkinned	=	SurfaceFlags.GBUFFER | SurfaceFlags.SKINNED | surfaceFlags ;
			var shadowRigid		=	SurfaceFlags.SHADOW  | SurfaceFlags.RIGID	| surfaceFlags ;
			var shadowSkinned	=	SurfaceFlags.SHADOW  | SurfaceFlags.SKINNED | surfaceFlags ;

			GBufferRigid	=	factory[ (int)gbufferRigid ];
			GBufferSkinned	=	factory[ (int)gbufferSkinned ];

			ShadowRigid		=	factory[ (int)shadowRigid ];
			ShadowSkinned	=	factory[ (int)shadowSkinned ];


			//
			//	Textures :
			//
			var textures = textureBinds
				.Select( texBind => texBind.TextureMap.LoadTexture( content, texBind.FallbackPath ) );

			var uvMods = new Vector4[MaxTextures];

			textureBinds
				.Select( tb => tb.TextureMap )
				.Select( tm => new Vector4( tm.ScaleU, tm.ScaleV, tm.OffsetU, tm.OffsetV ) )
				.ToArray()
				.CopyTo( uvMods, 0 );

			shaderResources		=	textures.Select( tex => tex.Srv ).ToArray();

			//
			//	Constants :
			//
			constBufferParams	=	new ConstantBuffer( rs.Device, typeof(MaterialData) );
			constBufferParams.SetData( parameters );

			constBufferUVMods	=	new ConstantBuffer( rs.Device, typeof(Vector4), MaxTextures );
			constBufferUVMods.SetData( uvMods );
		}
Example #5
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flags"></param>
		void StateEnum ( PipelineState ps, Flags flags )
		{
			switch ( flags ) {																			   
				case Flags.OPAQUE				: ps.BlendState		=	BlendState.Opaque			; break;
				case Flags.ALPHA_BLEND			: ps.BlendState		=	BlendState.AlphaBlend		; break;
				case Flags.ALPHA_BLEND_PREMUL	: ps.BlendState		=	BlendState.AlphaBlendPremul	; break;
				case Flags.ADDITIVE				: ps.BlendState		=	BlendState.Additive			; break;
				case Flags.SCREEN				: ps.BlendState		=	BlendState.Screen			; break;
				case Flags.MULTIPLY				: ps.BlendState		=	BlendState.Multiply			; break;
				case Flags.NEG_MULTIPLY			: ps.BlendState		=	BlendState.NegMultiply		; break;
				case Flags.ALPHA_ONLY			: ps.BlendState		=	BlendState.AlphaMaskWrite	; break;
			}

			ps.RasterizerState		=	RasterizerState.CullNone;
			ps.DepthStencilState	=	DepthStencilState.None;
			ps.Primitive			=	Primitive.TriangleList;
			ps.VertexInputElements	=	VertexInputElement.FromStructure( typeof(SpriteVertex) );
		}
Example #6
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flags"></param>
		void Enum ( PipelineState ps, ShaderFlags flags )
		{
			ps.Primitive			=	Primitive.TriangleList;
			ps.VertexInputElements	=	VertexInputElement.Empty;
			ps.BlendState			=	BlendState.Opaque;
			ps.RasterizerState		=	RasterizerState.CullNone;
			ps.DepthStencilState	=	DepthStencilState.None;

			if (flags==ShaderFlags.OVERLAY_ADDITIVE) {
				ps.BlendState = BlendState.Additive;
			}

			if (flags==ShaderFlags.FILL_ALPHA_ONE) {
				ps.BlendState = BlendState.AlphaMaskWrite;
			}
		}
Example #7
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="?"></param>
		void Enumerate ( Type enumType, Ubershader ubershader, Action<PipelineState,int> enumAction )
		{
			pipelineStates	=	new Dictionary<int,PipelineState>();

			combinerEnum	=	enumType;

			//
			//	validate enum :
			//
			if (Enum.GetUnderlyingType(enumType)!=typeof(int)) {
				throw new ArgumentException("Underlying type should be Int32");
			}

			Dictionary<string,int> enumDict = new Dictionary<string,int>();

			foreach ( var enumValue in Enum.GetValues( enumType ) ) {
				if ( !MathUtil.IsPowerOfTwo( (int)enumValue ) && (int)enumValue!=0 ) {
					throw new ArgumentException("Each value must be zero or power of two");
				}
				enumDict.Add( enumValue.ToString(), (int)enumValue );
			}



			//
			//	Enumerate :
			//
			var defineList = ubershader.Defines;

			foreach ( var defines in defineList ) {
				
				int combination = 0;

				if ( GetCombinerSet( enumDict, defines, out combination ) ) {
					
					var ps = new PipelineState( device );

					ps.PixelShader		=	ubershader.GetPixelShader		( defines );
					ps.VertexShader		=	ubershader.GetVertexShader		( defines );
					ps.GeometryShader	=	ubershader.GetGeometryShader	( defines );
					ps.HullShader		=	ubershader.GetHullShader		( defines );
					ps.DomainShader		=	ubershader.GetDomainShader		( defines );
					ps.ComputeShader	=	ubershader.GetComputeShader		( defines );
					
					enumAction( ps, combination );

					pipelineStates.Add( combination, ps );
				}	
			}
		}
Example #8
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flags"></param>
		void Enum ( PipelineState ps, SurfaceFlags flags )
		{
			ps.RasterizerState	=	RasterizerState.CullCW;

			if (flags.HasFlag( SurfaceFlags.SKINNED )) {
				ps.VertexInputElements	=	VertexColorTextureTBNSkinned.Elements;
			}
			
			if (flags.HasFlag( SurfaceFlags.RIGID )) {
				ps.VertexInputElements	=	VertexColorTextureTBNRigid.Elements;
			}

			if (flags.HasFlag( SurfaceFlags.VOXELIZE )) {
				ps.RasterizerState		=	RasterizerState.CullNone;
				ps.DepthStencilState	=	DepthStencilState.None;
			}
		}
Example #9
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flag"></param>
		void EnumAction ( PipelineState ps, Flags flag )
		{
			ps.BlendState			=	BlendState.AlphaBlendPremul;
			ps.DepthStencilState	=	DepthStencilState.Readonly;
			ps.Primitive			=	Primitive.PointList;

			if (flag==Flags.DRAW_SHADOW) {

				var bs = new BlendState();
				bs.DstAlpha	=	Blend.One;
				bs.SrcAlpha	=	Blend.One;
				bs.SrcColor	=	Blend.DstColor;
				bs.DstColor	=	Blend.Zero;
				bs.AlphaOp	=	BlendOp.Add;

				ps.BlendState			=	bs;
				ps.DepthStencilState	=	DepthStencilState.Readonly;
			}
		}
Example #10
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flags"></param>
		void EnumFunc ( PipelineState ps, SkyFlags flags )
		{
			ps.VertexInputElements	=	VertexInputElement.FromStructure<SkyVertex>();

			//	do not cull triangles for both for RH and LH coordinates 
			//	for direct view and cubemaps.
			ps.RasterizerState		=	RasterizerState.CullNone; 
			ps.BlendState			=	BlendState.Opaque;
			ps.DepthStencilState	=	flags.HasFlag(SkyFlags.FOG) ? DepthStencilState.None : DepthStencilState.Readonly;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flag"></param>
		void EnumAction ( PipelineState ps, Flags flag )
		{
			ps.Primitive			=	Primitive.PointList;
			ps.VertexInputElements	=	VertexInputElement.FromStructure<ParticleVertex>();
			ps.DepthStencilState	=	DepthStencilState.Readonly;

			var outputElements = new[]{
				new VertexOutputElement("SV_POSITION", 0, 0, 4),
				new VertexOutputElement("COLOR"		 , 0, 0, 4),
				new VertexOutputElement("COLOR"		 , 1, 0, 4),
				new VertexOutputElement("TEXCOORD"	 , 0, 0, 4),
				new VertexOutputElement("TEXCOORD"	 , 1, 0, 4),
				new VertexOutputElement("TEXCOORD"	 , 2, 0, 4),
			};


			if (flag==Flags.INJECTION || flag==Flags.SIMULATION) {
				ps.VertexOutputElements	=	outputElements;
			}

			if (flag==Flags.RENDER) {
				ps.BlendState		=	BlendState.Additive;
				ps.RasterizerState	=	RasterizerState.CullNone;
			}
		}
Example #12
0
		void EnumVoxel ( PipelineState ps, VoxelFlags flags )
		{
			ps.Primitive			=	Primitive.TriangleList;
			ps.RasterizerState		=	RasterizerState.CullNone;
			ps.BlendState			=	BlendState.Opaque;
			ps.DepthStencilState	=	DepthStencilState.None;

			//ps.VertexInputElements	=	VertexInputElement.Empty;

			if (flags==VoxelFlags.DEBUG_DRAW_VOXEL) {
				ps.RasterizerState		=	RasterizerState.CullCW;
				ps.DepthStencilState	=	DepthStencilState.Default;
				ps.BlendState			=	BlendState.Opaque;
				ps.Primitive			=	Primitive.PointList;
			}
		}