当前位置: 首页>>代码示例>>C#>>正文


C# DrawState.GetShader方法代码示例

本文整理汇总了C#中DrawState.GetShader方法的典型用法代码示例。如果您正苦于以下问题:C# DrawState.GetShader方法的具体用法?C# DrawState.GetShader怎么用?C# DrawState.GetShader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DrawState的用法示例。


在下文中一共展示了DrawState.GetShader方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BindShader

		protected override IShader BindShader(DrawState state, bool maskOnly)
		{
			Xen.Ex.Graphics2D.Statistics.DrawGraphLine shader = state.GetShader<Xen.Ex.Graphics2D.Statistics.DrawGraphLine>();

			if (dirty)
			{
				float x = widthScale;
				for (int i = 0; i < graphData.Length; i++)
				{
					int index = (i + this.index) % graphData.Length;
					float good = 0;

					if (goodValue != 0)
					{
						good = values[index];
						good = (good - Math.Abs(goodValue)) / goodValue;
					}
					graphData[i] = new Vector4(x, values[index] * maxValueInv, 0, good);
					x += widthScale;
				}
				dirty = false;
			}

			shader.GraphLine = this.graphData;

			return shader;
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:27,代码来源:Stats.cs

示例2: DrawGpuParticles

		/// <summary>
		/// <para>implements the method to draw gpu particles</para>
		/// <para>Note: When 'usesUserValuesPositionBuffer' is true, the values 'user1, user2 and user3' (yzw in the UserTexture) store a position offset for the particle</para></summary>
		protected override void DrawGpuParticles(DrawState state, Content.ParticleSystemTypeData particleType, uint particleCount, AlphaBlendState blendMode, Texture2D positionTex, Texture2D velocityRotation, Texture2D colourTex, Texture2D userValues, bool usesUserValuesPositionBuffer)
		{
			Vector2 targetSize = state.DrawTarget.Size;

			state.RenderState.Push();
			state.RenderState.CurrentBlendState = blendMode;
			state.RenderState.CurrentDepthState.DepthWriteEnabled = false;

			//get the display texture, or a white texture if none exists
			Texture2D displayTexture = particleType.Texture ?? state.Properties.WhiteTexture;

			//get / create the shared vertices and indices for drawing billboard particles
			BillboardParticles2DElement.GenerateBillboardVertices(state, ref vertices, ref indices);

			int count = (int)particleCount;

			//instances of the two possible shaders
			DrawBillboardParticles_GpuTex3D shaderNoColour = null;
			DrawBillboardParticlesColour_GpuTex3D shaderColour = null;
			//user offset variants
			DrawBillboardParticles_GpuTex3D_UserOffset shaderNoColour_UO = null;
			DrawBillboardParticlesColour_GpuTex3D_UserOffset shaderColour_UO = null;

			float resolutionXF = (float)positionTex.Width;
			float resolutionYF = (float)positionTex.Height;

			Vector2 invTextureSize = new Vector2(1.0f / resolutionXF, 1.0f / resolutionYF);

			Matrix cameraMatrix;
			state.Camera.GetCameraMatrix(out cameraMatrix);

			Vector3 worldSpaceYAxis = new Vector3(cameraMatrix.M21, cameraMatrix.M22, cameraMatrix.M23);

			IShader shader;

			if (!usesUserValuesPositionBuffer)
			{
				if (colourTex != null) // does this particle system use colours?
				{
					//get the shader
					shaderColour = state.GetShader<DrawBillboardParticlesColour_GpuTex3D>();

					//set the samplers
					shaderColour.PositionTexture = positionTex;
					shaderColour.ColourTexture = colourTex;
					shaderColour.VelocityTexture = velocityRotation;
					shaderColour.DisplayTexture = displayTexture;

					shaderColour.SetWorldSpaceYAxis(ref worldSpaceYAxis);
					shader = shaderColour;
				}
				else
				{
					shaderNoColour = state.GetShader<DrawBillboardParticles_GpuTex3D>();

					shaderNoColour.PositionTexture = positionTex;
					shaderNoColour.VelocityTexture = velocityRotation;
					shaderNoColour.DisplayTexture = displayTexture;

					shaderNoColour.SetWorldSpaceYAxis(ref worldSpaceYAxis);
					shader = shaderNoColour;
				}
			}
			else
			{
				if (colourTex != null) // does this particle system use colours?
				{
					//get the shader
					shaderColour_UO = state.GetShader<DrawBillboardParticlesColour_GpuTex3D_UserOffset>();

					//set the samplers
					shaderColour_UO.PositionTexture = positionTex;
					shaderColour_UO.ColourTexture = colourTex;
					shaderColour_UO.VelocityTexture = velocityRotation;
					shaderColour_UO.UserTexture = userValues;
					shaderColour_UO.DisplayTexture = displayTexture;

					shaderColour_UO.SetWorldSpaceYAxis(ref worldSpaceYAxis);
					shader = shaderColour_UO;
				}
				else
				{
					shaderNoColour_UO = state.GetShader<DrawBillboardParticles_GpuTex3D_UserOffset>();

					shaderNoColour_UO.PositionTexture = positionTex;
					shaderNoColour_UO.VelocityTexture = velocityRotation;
					shaderNoColour_UO.UserTexture = userValues;
					shaderNoColour_UO.DisplayTexture = displayTexture;

					shaderNoColour_UO.SetWorldSpaceYAxis(ref worldSpaceYAxis);
					shader = shaderNoColour_UO;
				}
			}


			int drawn = 0;
			while (count > 0)
//.........这里部分代码省略.........
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:101,代码来源:Billboard3D.cs

示例3: DrawCpuParticles

		/// <summary>
		/// <para>implements the method to draw cpu particles</para>
		/// </summary>
		protected override void DrawCpuParticles(DrawState state, Content.ParticleSystemTypeData particleType, uint particleCount, AlphaBlendState blendMode, Vector4[] positionSize, Vector4[] velocityRotation, Vector4[] colourData, Vector4[] userValues)
		{
			//this is a bit more complex, but mostly the same as the GPU draw method
			Vector2 targetSize = state.DrawTarget.Size;

			state.RenderState.Push();
			state.RenderState.CurrentBlendState = blendMode;
			state.RenderState.CurrentDepthState.DepthWriteEnabled = false;

			Texture2D displayTexture = particleType.Texture ?? state.Properties.WhiteTexture;

			BillboardParticles2DElement.GenerateBillboardVertices(state, ref this.vertices, ref this.indices);

			Matrix cameraMatrix;
			state.Camera.GetCameraMatrix(out cameraMatrix);

			Vector3 worldSpaceYAxis = new Vector3(cameraMatrix.M21, cameraMatrix.M22, cameraMatrix.M23);


			int count = (int)particleCount;

			DrawBillboardParticles_BillboardCpu3D shaderNoColour = null;
			DrawBillboardParticlesColour_BillboardCpu3D shaderColour = null;

			if (colourData != null)
			{
				shaderColour = state.GetShader<DrawBillboardParticlesColour_BillboardCpu3D>();
				shaderColour.SetWorldSpaceYAxis(ref worldSpaceYAxis);
			}
			else
			{
				shaderNoColour = state.GetShader<DrawBillboardParticles_BillboardCpu3D>();
				shaderNoColour.SetWorldSpaceYAxis(ref worldSpaceYAxis);
			}

			int drawn = 0;
			while (count > 0)
			{
				int drawCount;

				drawCount = Math.Min(count, 75);
				uint drawCountU = (uint)drawCount;
				uint drawnU = (uint)drawn;

				if (colourData != null)
				{
					shaderColour.SetPositionData(positionSize, drawnU, 0, drawCountU);
					shaderColour.SetVelocityData(velocityRotation, drawnU, 0, drawCountU);
					shaderColour.SetColourData(colourData, drawnU,0,drawCountU);

					shaderColour.DisplayTexture = displayTexture;

					state.Shader.Push(shaderColour);
				}
				else
				{
					shaderNoColour.SetPositionData(positionSize, drawnU, 0, drawCountU);
					shaderNoColour.SetVelocityData(velocityRotation, drawnU, 0, drawCountU);

					shaderNoColour.DisplayTexture = displayTexture;

					state.Shader.Push(shaderNoColour);
				}

				vertices.Draw(state, indices, PrimitiveType.TriangleList, drawCount * 2, 0, 0);

				state.Shader.Pop();

				count -= drawCount;
				drawn += drawCount;
			}


			state.RenderState.Pop();
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:78,代码来源:Billboard3D.cs

示例4: DrawGpuParticles

		/// <summary>
		/// draws the particles on a GPU system
		/// </summary>
		protected override void DrawGpuParticles(DrawState state, Content.ParticleSystemTypeData particleType, uint particleCount, AlphaBlendState blendMode, Texture2D positionTex, Texture2D velocityRotation, Texture2D colourTex, Texture2D userValues, bool usesUserValuesPositionBuffer)
		{
			Vector2 targetSize = state.DrawTarget.Size;

			state.RenderState.Push();
			state.RenderState.CurrentBlendState = blendMode;
			state.RenderState.CurrentDepthState.DepthWriteEnabled = false;

			//get the shared vertice
			VelocityLineParticles2DElement.GenerateLinesVertices(state, ref vertices);

			int count = (int)particleCount;

			DrawVelocityParticles_LinesGpuTex shaderNoColour = null;
			DrawVelocityParticlesColour_LinesGpuTex shaderColour = null;
			//user variants
			DrawVelocityParticles_LinesGpuTex_UserOffset shaderNoColour_UO = null;
			DrawVelocityParticlesColour_LinesGpuTex_UserOffset shaderColour_UO = null;

			float resolutionXF = (float)positionTex.Width;
			float resolutionYF = (float)positionTex.Height;

			Vector2 invTextureSize;

			Vector2 velScale = new Vector2(velocityScale, 0);
			if (this.useRotationToScaleVelocityEffect)
				velScale = new Vector2(0, velocityScale);
			invTextureSize = new Vector2(1.0f / resolutionXF, 1.0f / resolutionYF);


			IShader shader;
			if (!usesUserValuesPositionBuffer)
			{
				if (colourTex != null)
				{
					shader = shaderColour = state.GetShader<DrawVelocityParticlesColour_LinesGpuTex>();

					shaderColour.PositionTexture = positionTex;
					shaderColour.ColourTexture = colourTex;
					shaderColour.VelocityTexture = velocityRotation;

					shaderColour.SetVelocityScale(ref velScale);
				}
				else
				{
					shader = shaderNoColour = state.GetShader<DrawVelocityParticles_LinesGpuTex>();

					shaderNoColour.PositionTexture = positionTex;
					shaderNoColour.VelocityTexture = velocityRotation;

					shaderNoColour.SetVelocityScale(ref velScale);
				}
			}
			else
			{
				if (colourTex != null)
				{
					shader = shaderColour_UO = state.GetShader<DrawVelocityParticlesColour_LinesGpuTex_UserOffset>();

					shaderColour_UO.PositionTexture = positionTex;
					shaderColour_UO.ColourTexture = colourTex;
					shaderColour_UO.VelocityTexture = velocityRotation;

					shaderColour_UO.SetVelocityScale(ref velScale);
				}
				else
				{
					shader = shaderNoColour_UO = state.GetShader<DrawVelocityParticles_LinesGpuTex_UserOffset>();

					shaderNoColour_UO.PositionTexture = positionTex;
					shaderNoColour_UO.VelocityTexture = velocityRotation;

					shaderNoColour_UO.SetVelocityScale(ref velScale);
				}
			}


			int drawn = 0;
			while (count > 0)
			{
				int drawCount = Math.Min(count, vertices.Count / 4);

				if (!usesUserValuesPositionBuffer)
				{
					if (colourTex != null)
						shaderColour.TextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
					else
						shaderNoColour.TextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
				}
				else
				{
					if (colourTex != null)
						shaderColour_UO.TextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
					else
						shaderNoColour_UO.TextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
				}

//.........这里部分代码省略.........
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:101,代码来源:VelocityLines.cs

示例5: DrawCpuParticles

		/// <summary>
		/// draws the particles from a CPU system
		/// </summary>
		protected override void DrawCpuParticles(DrawState state, Content.ParticleSystemTypeData particleType, uint particleCount, AlphaBlendState blendMode, Vector4[] positionSize, Vector4[] velocityRotation, Vector4[] colourData, Vector4[] userValues)
		{
			Vector2 targetSize = state.DrawTarget.Size;

			state.RenderState.Push();
			state.RenderState.CurrentBlendState = blendMode;
			state.RenderState.CurrentDepthState.DepthWriteEnabled = false;

			VelocityLineParticles2DElement.GenerateLinesVertices(state, ref this.vertices);


			int count = (int)particleCount;



			DrawVelocityParticles_LinesCpu shaderNoColour = null;
			DrawVelocityParticlesColour_LinesCpu shaderColour = null;

			if (colourData != null)
				shaderColour = state.GetShader<DrawVelocityParticlesColour_LinesCpu>();
			else
				shaderNoColour = state.GetShader<DrawVelocityParticles_LinesCpu>();

			Vector2 velScale = new Vector2(velocityScale, 0);
			if (this.useRotationToScaleVelocityEffect)
				velScale = new Vector2(0, velocityScale);

			int drawn = 0;
			while (count > 0)
			{
				int drawCount;

				drawCount = Math.Min(count, 80);
				uint drawCountU = (uint)drawCount;
				uint drawnU = (uint)drawn;

				if (colourData != null)
				{
					shaderColour.SetPositionData(positionSize, drawnU, 0, drawCountU);
					shaderColour.SetVelocityData(velocityRotation, drawnU, 0, drawCountU);
					shaderColour.SetColourData(colourData, drawnU, 0, drawCountU);

					shaderColour.SetVelocityScale(ref velScale);

					state.Shader.Push(shaderColour);
				}
				else
				{
					shaderNoColour.SetPositionData(positionSize, drawnU, 0, drawCountU);
					shaderNoColour.SetVelocityData(velocityRotation, drawnU, 0, drawCountU);

					shaderNoColour.SetVelocityScale(ref velScale);

					state.Shader.Push(shaderNoColour);
				}

				vertices.Draw(state, null, PrimitiveType.LineList, drawCount, 0, 0);

				state.Shader.Pop();

				count -= drawCount;
				drawn += drawCount;
			}


			state.RenderState.Pop();
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:70,代码来源:VelocityLines.cs

示例6: BindShader

		/// <summary></summary>
		/// <param name="state"></param>
		/// <param name="maskOnly"></param>
		protected override IShader BindShader(DrawState state, bool maskOnly)
		{
			return state.GetShader<Shaders.FillVertexColour>();
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:7,代码来源:SimpleElement.cs

示例7: End

		/// <summary>
		/// End the modifier (This method is called by the DrawTarget)
		/// </summary>
		/// <param name="state"></param>
		public void End(DrawState state)
		{
			if (enabledBuffer)
				state.Cullers.PopPostCuller();

			this.cameras = null;

			if (cubes.Count > 0 || spheres.Count > 0)
			{
				Xen.Ex.Shaders.FillSolidColour shader = state.GetShader<Xen.Ex.Shaders.FillSolidColour>();
				shader.FillColour = new Vector4(1,1,1,0.25f);

				using (state.RenderState.Push())
				using (state.Shader.Push(shader))
				using (state.Camera.Push())
				{
					ICamera camera = state.Camera.GetCamera();

					state.RenderState.CurrentDepthState.DepthWriteEnabled = false;
					state.RenderState.CurrentDepthState.DepthTestEnabled = EnableDepthTesting;
					state.RenderState.CurrentBlendState = AlphaBlendState.Alpha;

					GenCubeVS(state);
					GenSphereVS(state);

					Matrix mat;
					for (int i = 0; i < cubes.Count; i++)
					{
						mat = cubes[i].Matrix;
						if (camera != cubes[i].Camera)
						{
							camera = cubes[i].Camera;
							state.Camera.SetCamera(camera);
						}
						using (state.WorldMatrix.Push(ref mat))
						{
							cubeVS.Draw(state, null, PrimitiveType.LineList);
						}
					}

					mat = Matrix.Identity;

					for (int i = 0; i < spheres.Count; i++)
					{
						Vector3 v = spheres[i].Position;
						float scale = spheres[i].Radius;

						if (camera != spheres[i].Camera)
						{
							camera = spheres[i].Camera;
							state.Camera.SetCamera(camera);
						}

						mat.M11 = scale;
						mat.M22 = scale;
						mat.M33 = scale;
						mat.M41 = v.X;
						mat.M42 = v.Y;
						mat.M43 = v.Z;

						using (state.WorldMatrix.Push(ref mat))
						{
							sphereVS.Draw(state, null, PrimitiveType.LineList);
						}
					}
				}
			}

			spheres.Clear();
			cubes.Clear();
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:75,代码来源:CullTestVisualizer.cs

示例8: BindShader

        protected override void BindShader(DrawState state, bool maskOnly)
        {
            SimpleTextureEffect shader = state.GetShader<SimpleTextureEffect>();

            shader.Texture = _texture;
            shader.Bind(state);
        }
开发者ID:TormentedEmu,项目名称:OpenUO,代码行数:7,代码来源:TexturedElement.cs

示例9: DrawCpuParticles

		/// <summary>
		/// implements the method to draw cpu particles
		/// </summary>
		protected override void DrawCpuParticles(DrawState state, Content.ParticleSystemTypeData particleType, uint particleCount, AlphaBlendState blendMode, Vector4[] positionSize, Vector4[] velocityRotation, Vector4[] colourData, Vector4[] userValues)
		{
			//this is a bit more complex, but mostly the same as the GPU draw method
			Vector2 targetSize = state.DrawTarget.Size;

			state.RenderState.Push();
			state.RenderState.CurrentBlendState = blendMode;
			state.RenderState.CurrentDepthState.DepthWriteEnabled = false;

			Texture2D displayTexture = particleType.Texture ?? state.Properties.WhiteTexture;

			GenerateBillboardVertices(state, ref this.vertices, ref this.indices);


			int count = (int)particleCount;

			DrawBillboardParticles_BillboardCpu shaderNoColour = null;
			DrawBillboardParticlesColour_BillboardCpu shaderColour = null;

			if (positionBuffer == null)
			{
				positionBuffer = GetPositionBuffer(state, positionBuffer);
			}

			if (colourData != null)
				shaderColour = state.GetShader<DrawBillboardParticlesColour_BillboardCpu>();
			else
				shaderNoColour = state.GetShader<DrawBillboardParticles_BillboardCpu>();
		
			int drawn = 0;
			while (count > 0)
			{
				int drawCount;

				drawCount = Math.Min(count, 120);
				uint drawCountU = (uint)drawCount;
				uint drawnU = (uint)drawn;

				//the only major difference from the GPU drawer is here
				for (int i = 0; i < drawCount; i++)
				{
					//copy position xy and w (size), and velocity.w (rotation)
					positionBuffer[i] = positionSize[drawn + i];
					positionBuffer[i].Z = velocityRotation[drawn + i].W;
				}

				if (colourData != null)
				{
					shaderColour.SetPositionData(positionBuffer, 0, 0, drawCountU);
					shaderColour.SetColourData(colourData, drawnU, 0, drawCountU);

					shaderColour.DisplayTexture = displayTexture;

					state.Shader.Push(shaderColour);
				}
				else
				{
					shaderNoColour.SetPositionData(positionBuffer, 0, 0, drawCountU);

					shaderNoColour.DisplayTexture = displayTexture;

					state.Shader.Push(shaderNoColour);
				}

				vertices.Draw(state, indices, PrimitiveType.TriangleList, drawCount * 2, 0, 0);

				state.Shader.Pop();

				count -= drawCount;
				drawn += drawCount;
			}


			state.RenderState.Pop();
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:78,代码来源:Billboard.cs

示例10: DrawGpuParticles

		/// <summary>
		/// draws the particles on a GPU system
		/// </summary>
		protected override void DrawGpuParticles(DrawState state, Xen.Ex.Graphics.Content.ParticleSystemTypeData particleType, uint particleCount, AlphaBlendState blendMode, Texture2D positionTex, Texture2D velocityRotation, Texture2D colourTex, Texture2D userValues, bool usesUserValuesPositionBuffer)
		{
			//this is very similar to the billboard drawer (see it for reference)

			using (state.RenderState.Push())
			{
				state.RenderState.CurrentBlendState = blendMode;
				state.RenderState.CurrentDepthState.DepthWriteEnabled = false;

				Texture2D displayTexture = particleType.Texture;

				//get the shared vertice
				BillboardParticles2DElement.GenerateBillboardVertices(state, ref vertices, ref indices);

				int count = (int)particleCount;

				DrawVelocityParticles_GpuTex shaderNoColour = null;
				DrawVelocityParticlesColour_GpuTex shaderColour = null;
				//user variants
				DrawVelocityParticles_GpuTex_UserOffset shaderNoColour_UO = null;
				DrawVelocityParticlesColour_GpuTex_UserOffset shaderColour_UO = null;

				float resolutionXF = (float)positionTex.Width;
				float resolutionYF = (float)positionTex.Height;

				Vector2 invTextureSize;

				Vector2 velScale = new Vector2(velocityScale, 0);
				if (this.useRotationToScaleVelocityEffect)
					velScale = new Vector2(0, velocityScale);
				invTextureSize = new Vector2(1.0f / resolutionXF, 1.0f / resolutionYF);


				IShader shader;

				if (!usesUserValuesPositionBuffer)
				{
					if (colourTex != null)
					{
						shader = shaderColour = state.GetShader<DrawVelocityParticlesColour_GpuTex>();

						shaderColour.PositionTexture = positionTex;
						shaderColour.ColourTexture = colourTex;
						shaderColour.VelocityTexture = velocityRotation;
						shaderColour.DisplayTexture = displayTexture;

						shaderColour.SetVelocityScale(ref velScale);
					}
					else
					{
						shader = shaderNoColour = state.GetShader<DrawVelocityParticles_GpuTex>();

						shaderNoColour.PositionTexture = positionTex;
						shaderNoColour.VelocityTexture = velocityRotation;
						shaderNoColour.DisplayTexture = displayTexture;

						shaderNoColour.SetVelocityScale(ref velScale);
					}
				}
				else
				{
					if (colourTex != null)
					{
						shader = shaderColour_UO = state.GetShader<DrawVelocityParticlesColour_GpuTex_UserOffset>();

						shaderColour_UO.PositionTexture = positionTex;
						shaderColour_UO.ColourTexture = colourTex;
						shaderColour_UO.VelocityTexture = velocityRotation;
						shaderColour_UO.UserTexture = userValues;
						shaderColour_UO.DisplayTexture = displayTexture;

						shaderColour_UO.SetVelocityScale(ref velScale);
					}
					else
					{
						shader = shaderNoColour_UO = state.GetShader<DrawVelocityParticles_GpuTex_UserOffset>();

						shaderNoColour_UO.PositionTexture = positionTex;
						shaderNoColour_UO.VelocityTexture = velocityRotation;
						shaderNoColour_UO.UserTexture = userValues;
						shaderNoColour_UO.DisplayTexture = displayTexture;

						shaderNoColour_UO.SetVelocityScale(ref velScale);
					}
				}


				int drawn = 0;
				while (count > 0)
				{
					int drawCount = Math.Min(count, vertices.Count / 4);

					if (!usesUserValuesPositionBuffer)
					{
						if (colourTex != null)
							shaderColour.TextureSizeOffset = new Vector3(invTextureSize, (float)drawn);
						else
//.........这里部分代码省略.........
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:101,代码来源:VelocityBillboard.cs

示例11: DrawCpuParticles

		//draws on CPU particle systems
		/// <summary>
		/// draws the particles from a CPU system
		/// </summary>
		protected override void DrawCpuParticles(DrawState state, Xen.Ex.Graphics.Content.ParticleSystemTypeData particleType, uint particleCount, AlphaBlendState blendMode, Vector4[] positionSize, Vector4[] velocityRotation, Vector4[] colourData, Vector4[] userValues)
		{
			//this is very similar to the billboard drawer (see it for reference)
			Vector2 targetSize = state.DrawTarget.Size;

			using (state.RenderState.Push())
			{
				state.RenderState.CurrentBlendState = blendMode;
				state.RenderState.CurrentDepthState.DepthWriteEnabled = false;

				Texture2D displayTexture = particleType.Texture;

				BillboardParticles2DElement.GenerateBillboardVertices(state, ref this.vertices, ref this.indices);


				int count = (int)particleCount;



				DrawVelocityParticles_BillboardCpu shaderNoColour = null;
				DrawVelocityParticlesColour_BillboardCpu shaderColour = null;


				Vector2 velScale = new Vector2(velocityScale, 0);
				if (this.useRotationToScaleVelocityEffect)
					velScale = new Vector2(0, velocityScale);

				if (colourData != null)
				{
					shaderColour = state.GetShader<DrawVelocityParticlesColour_BillboardCpu>();

					shaderColour.DisplayTexture = displayTexture;
					shaderColour.SetVelocityScale(ref velScale);
				}
				else
				{
					shaderNoColour = state.GetShader<DrawVelocityParticles_BillboardCpu>();

					shaderNoColour.DisplayTexture = displayTexture;
					shaderNoColour.SetVelocityScale(ref velScale);
				}

				int drawn = 0;
				while (count > 0)
				{
					int drawCount;

					drawCount = Math.Min(count, 80);
					IShader shader = null;

					if (colourData != null)
					{
						shaderColour.SetPositionData(positionSize, (uint)drawn, 0, (uint)drawCount);
						shaderColour.SetVelocityData(velocityRotation, (uint)drawn, 0, (uint)drawCount);
						shaderColour.SetColourData(colourData, (uint)drawn, 0, (uint)drawCount);

						shader = shaderColour;
					}
					else
					{
						shaderNoColour.SetPositionData(positionSize, (uint)drawn, 0, (uint)drawCount);
						shaderNoColour.SetVelocityData(velocityRotation, (uint)drawn, 0, (uint)drawCount);

						shader = shaderNoColour;
					}

					using (state + shader)
						vertices.Draw(state, indices, PrimitiveType.TriangleList, drawCount * 2, 0, 0);

					count -= drawCount;
					drawn += drawCount;
				}
			}
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:78,代码来源:VelocityBillboard.cs

示例12: BindShader

		/// <summary></summary>
		/// <param name="state"></param>
		/// <param name="maskOnly"></param>
		protected override sealed IShader BindShader(DrawState state, bool maskOnly)
		{
			if (this.vertices == null)
			{
				this.vertices = state.Application.UserValues[GetType().FullName + ".vertices"] as IVertices;
				this.indices = state.Application.UserValues[GetType().FullName + ".indices"] as Indices<ushort>;

				this.verticesSI = state.Application.UserValues[GetType().FullName + ".verticesSI"] as IVertices;
				this.indicesSI = state.Application.UserValues[GetType().FullName + ".indicesSI"] as Indices<ushort>;

				if (this.vertices == null)
				{
					//still null, create the global vertices
					this.vertices = new Vertices<Vector4>(
						new Vector4(0, 0, 0, 1),
						new Vector4(1, 0, 0, 1),
						new Vector4(1, 1, 0, 1),
						new Vector4(0, 1, 0, 1));

					this.indices = new Indices<ushort>(0, 2, 1, 0, 3, 2);

					//shader instancing..
					List<InstanceVertex> verts = new List<InstanceVertex>();
					List<ushort> inds = new List<ushort>();

					for (int i = 0; i < NonInstancingRenderCount; i++)
					{
						verts.Add(new InstanceVertex(new Vector3(0, 0, 0), (float)i));
						verts.Add(new InstanceVertex(new Vector3(1, 0, 0), (float)i));
						verts.Add(new InstanceVertex(new Vector3(1, 1, 0), (float)i));
						verts.Add(new InstanceVertex(new Vector3(0, 1, 0), (float)i));

						inds.Add((ushort)(0 + i * 4));
						inds.Add((ushort)(2 + i * 4));
						inds.Add((ushort)(1 + i * 4));
						inds.Add((ushort)(0 + i * 4));
						inds.Add((ushort)(3 + i * 4));
						inds.Add((ushort)(2 + i * 4));
					}

					this.verticesSI = new Vertices<InstanceVertex>(verts.ToArray());
					this.indicesSI = new Indices<ushort>(inds.ToArray());

					state.Application.UserValues[GetType().FullName + ".vertices"] = vertices;
					state.Application.UserValues[GetType().FullName + ".indices"] = indices;
					state.Application.UserValues[GetType().FullName + ".verticesSI"] = verticesSI;
					state.Application.UserValues[GetType().FullName + ".indicesSI"] = indicesSI;
				}
			}

			if (state.Properties.SupportsHardwareInstancing && instanceCount > HardwareInstancingMinimum)
			{
				Graphics2D.InstancingSprite shader = state.GetShader<Graphics2D.InstancingSprite>();
				Matrix world;
				state.WorldMatrix.GetMatrix(out world);
				shader.SetSpriteWorldMatrix(ref world);
				shader.CustomTexture = texture ?? state.Properties.WhiteTexture;
				return shader;
			}
			else
			{
				Graphics2D.NonInstancingSprite shader = state.GetShader<Graphics2D.NonInstancingSprite>();

				shader.CustomTexture = texture ?? state.Properties.WhiteTexture;
				return shader;
			}
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:70,代码来源:SpriteElement.cs

示例13: DrawElement

		/// <summary></summary>
		/// <param name="state"></param>
		protected sealed override void DrawElement(DrawState state)
		{
			if (state.Properties.SupportsHardwareInstancing && instanceCount > HardwareInstancingMinimum)
			{
				using (state.WorldMatrix.PushIdentity())
				{
					vertices.DrawInstances(state, indices, PrimitiveType.TriangleList, state.GetDynamicInstanceBuffer(this.instances, this.instanceCount));
				}
			}
			else
			{
				Graphics2D.NonInstancingSprite shader = state.GetShader<Graphics2D.NonInstancingSprite>();

				for (int i = 0; i < instanceCount; i += NonInstancingRenderCount)
				{
					int count = Math.Min(NonInstancingRenderCount, (instanceCount - i));

					shader.SetInstances(this.instances, (uint)i, 0, (uint)count);

					this.verticesSI.Draw(state, this.indicesSI, PrimitiveType.TriangleList, 2 * count, 0, 0);
				}
			}
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:25,代码来源:SpriteElement.cs


注:本文中的DrawState.GetShader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。