/// <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.PushRenderState(); state.RenderState.AlphaBlend = blendMode; state.RenderState.DepthColourCull.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); } } //bind shader.Bind(state); vertices.Draw(state, null, PrimitiveType.LineList, drawCount, 0, 0); count -= drawCount; drawn += drawCount; } state.PopRenderState(); }
/// <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.PushRenderState(); state.RenderState.AlphaBlend = blendMode; state.RenderState.DepthColourCull.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); if (colourData != null) { shaderColour.PositionData.SetArray(positionSize, drawn); shaderColour.VelocityData.SetArray(velocityRotation, drawn); shaderColour.ColourData.SetArray(colourData, drawn); shaderColour.SetVelocityScale(ref velScale); shaderColour.Bind(state); } else { shaderNoColour.PositionData.SetArray(positionSize, drawn); shaderNoColour.VelocityData.SetArray(velocityRotation, drawn); shaderNoColour.SetVelocityScale(ref velScale); shaderNoColour.Bind(state); } vertices.Draw(state, null, PrimitiveType.LineList, drawCount, 0, 0); count -= drawCount; drawn += drawCount; } state.PopRenderState(); }