/// <summary> /// Draws the quad using the specified effect. Sets no parameters on the effect, nor any render states on /// the graphics device. Those must be set appropriately before calling Draw. /// This is a convenience function, calling Begin, End, and DrawGeometry for you. /// </summary> /// <param name="effect">The effect to draw with.</param> public void Draw(Effect effect) { effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); DrawGeometry(); pass.End(); } effect.End(); }
public void RenderScreenQuad(Effect effect, EffectTechnique technique, Texture2D texture) { effect.CurrentTechnique = technique; sb.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None); effect.Begin(); technique.Passes[0].Begin(); sb.Draw(texture, screen, Color.White); technique.Passes[0].End(); effect.End(); sb.End(); }
public void Draw(Effect effect) { var device = GraphicsDeviceHolder.Device; device.VertexDeclaration = vertexDeclaration; device.Vertices[0].SetSource(vertexBuffer, 0, 3 * sizeof(float)); effect.Parameters["xWorld"].SetValue(Matrix.Identity); effect.Begin(); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Begin(); device.DrawPrimitives(PrimitiveType.LineList, 0, 2); pass.End(); } effect.End(); }
public void Draw(GameTime gameTime, GraphicsDevice device, Effect effect, Matrix worldViewProjectionMatrix, int resolutionWidth, int resolutionHeight) { effect.Parameters["xWorldViewProjection"].SetValue(worldViewProjectionMatrix); effect.Parameters["xWidth"].SetValue(resolutionWidth); effect.Parameters["xHeight"].SetValue(resolutionHeight); effect.Begin(); foreach (SModelMesh mesh in _meshes) { effect.Parameters["xTexture"].SetValue(mesh.texture); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); device.VertexDeclaration = _vertexDeclaration; device.Vertices[0].SetSource(mesh.vertexBuffer, 0, _vertexSizeInBytes); device.DrawPrimitives(PrimitiveType.TriangleList, 0, mesh.numPrimitives); pass.End(); } } effect.End(); }
void DrawSpawns(Effect effectToUse, String technique) { GraphicsDevice device = parentGame.device; foreach (EventFlag flag in parentGame.myLevel.FlagsList) { if (flag == activeFlag) { foreach (GameEvent g_event in flag.Events) { VertexPositionColor[] pointList = new VertexPositionColor[2]; #region Get Corners Vector3 corner = g_event.SpawnPoint.Position; Vector2 center = FindCenter2D(flag.Corners); Vector3 Center = new Vector3(center.X, 0, center.Y); Vector3 norm; if(parentGame.terrainEngine.IsOnHeightmap(Center)) parentGame.terrainEngine.GetHeight(Center, out Center.Y, out norm); pointList[0] = new VertexPositionColor(corner, Color.Red); pointList[1] = new VertexPositionColor(Center, Color.Red); float scale = 0.05f; if (activeEvent == g_event) scale *= 1.5f; parentGame.currentColor = Color.GreenYellow; parentGame.DrawModel(effectToUse, parentGame.cornerModel, parentGame.tankTextures, Matrix.CreateScale(scale) * Matrix.Identity * Matrix.CreateTranslation(corner), technique, true); parentGame.currentColor = Color.Brown; #endregion #region draw lines short[] lineStripIndices = new short[2] { 0, 1 }; device.RenderState.FillMode = FillMode.WireFrame; device.RenderState.CullMode = CullMode.None; effectToUse.Begin(); foreach (EffectPass pass in effectToUse.CurrentTechnique.Passes) { pass.Begin(); device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements); device.DrawUserIndexedPrimitives<VertexPositionColor>( PrimitiveType.LineStrip, pointList, 0, // vertex buffer offset to add to each element of the index buffer 2, // number of vertices to draw lineStripIndices, 0, // first index element to read 1 // number of primitives to draw ); pass.End(); } effectToUse.End(); //device.RenderState.FillMode = FillMode.Solid; device.RenderState.FillMode = FillMode.Solid; device.RenderState.CullMode = CullMode.CullClockwiseFace; #endregion } } } }
//method shadow effect render part private void renderPart(GraphicsDevice device, List<SRenderInfoMesh> v_list, Matrix world, Effect shadow_effect) { shadow_effect.Begin(); shadow_effect.Parameters["xWorld"].SetValue(world); for (int i = 0; i < v_list.Count; ++i) { VertexPositionNormalTexture[] vertices = v_list[i].vertex_info; //model_effect.Texture = getTexture(v_list[i].texture_name); foreach (EffectPass pass in shadow_effect.CurrentTechnique.Passes) { pass.Begin(); int count_primitives = vertices.Length / 3; device.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, vertices, 0, count_primitives); pass.End(); } } shadow_effect.End(); }
void DrawFlags(Effect effectToUse, String technique) { GraphicsDevice device = parentGame.device; //effectToUse = new BasicEffect(device, new EffectPool()); foreach (EventFlag flag in parentGame.myLevel.FlagsList) { currentColor.G -= 1; VertexPositionColor[] pointList = new VertexPositionColor[5]; int x = 0; #region Get Corners foreach (Vector2 Crnr in flag.Corners) { Vector3 corner = new Vector3(Crnr.X, 0, Crnr.Y); Vector3 norm; parentGame.terrainEngine.GetHeight(corner, out corner.Y, out norm); corner.Y += 2; pointList[x] = new VertexPositionColor(corner, Color.Red); if (x == 0) { pointList[4] = new VertexPositionColor(corner, Color.Red); currentColor = Color.Red; } else currentColor = Color.Chartreuse; float scale = 0.05f; if (activeFlag == flag && activeCorner == Crnr) scale *= 1.5f; parentGame.currentColor = Color.Brown; parentGame.DrawModel(effectToUse, parentGame.cornerModel, parentGame.tankTextures, Matrix.CreateScale(scale) * Matrix.Identity * Matrix.CreateTranslation(corner), technique, true); x++; } #endregion short[] lineStripIndices = new short[5] { 0, 1, 2, 3, 4 }; device.RenderState.FillMode = FillMode.WireFrame; device.RenderState.CullMode = CullMode.None; effectToUse.Begin(); foreach (EffectPass pass in effectToUse.CurrentTechnique.Passes) { pass.Begin(); device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements); device.DrawUserIndexedPrimitives<VertexPositionColor>( PrimitiveType.LineStrip, pointList, 0, // vertex buffer offset to add to each element of the index buffer 5, // number of vertices to draw lineStripIndices, 0, // first index element to read 4 // number of primitives to draw ); pass.End(); } effectToUse.End(); //device.RenderState.FillMode = FillMode.Solid; device.RenderState.FillMode = FillMode.Solid; device.RenderState.CullMode = CullMode.CullClockwiseFace; } }
/// <summary> /// Отрисовывает объект /// </summary> /// <param name="effect">Эффект, который должен испльзоваться для отрисовки. Предполагается, что как минимум матрицы xProjection и xView уже заданы!</param> public void Draw(Effect effect, Matrix worldMatrix, bool useMaterial) { GraphicsDevice device = vertexDeclaration.GraphicsDevice; device.RenderState.CullMode = CullMode.None; effect.Parameters["xWorld"].SetValue(worldMatrix); device.VertexDeclaration = vertexDeclaration; device.Vertices[0].SetSource(vertexBuffer, 0, vertexSize); device.Indices = indexBuffer; foreach (ModelMeshPart3D part in meshParts) { if (useMaterial) { Material mat = materials[part.MaterialId]; if (mat.Texture != null) { effect.CurrentTechnique = effect.Techniques["Textured"]; effect.Parameters["xTexture"].SetValue(mat.Texture); } else { effect.CurrentTechnique = effect.Techniques["SolidColored"]; effect.Parameters["xSolidColor"].SetValue(mat.Color.ToVector4()); } } effect.Begin(); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Begin(); device.DrawIndexedPrimitives(triangleStrip ? PrimitiveType.TriangleStrip : PrimitiveType.TriangleList, 0, 0, verticesCount, part.StartIdx, part.PrimitivesCount); pass.End(); } effect.End(); } }
private void DrawQuad(Texture2D source, RenderTarget2D target, int x, int y, int width, int height, SpriteBlendMode spriteBlendMode, Effect effect, Color color) { graphics.GraphicsDevice.SetRenderTarget(0, target); if (effect != null) graphics.GraphicsDevice.Textures[0] = source; // Draw a fullscreen sprite to apply the postprocessing effect. spriteBatch.Begin(spriteBlendMode, SpriteSortMode.Immediate, SaveStateMode.SaveState); if (effect != null) { effect.Begin(); effect.CurrentTechnique.Passes[0].Begin(); } spriteBatch.Draw(source, new Rectangle(x, y, width, height), color); spriteBatch.End(); if (effect != null) { effect.CurrentTechnique.Passes[0].End(); effect.End(); } graphics.GraphicsDevice.SetRenderTarget(0, null); }
public void drawMe(GraphicsDevice device, Effect effect) { if (mDecl == null) { mDecl = new VertexDeclaration(device, VertexPositionColor.VertexElements); } // update vert buffer. for (int i = 0; i < mPointMasses.Count; i++) { mVerts[i].Position = JelloPhysics.VectorTools.vec3FromVec2(mPointMasses[i].Position); float dist = (mPointMasses[i].Position - mGlobalShape[i]).Length() * 2.0f; if (dist > 1f) { dist = 1f; } mVerts[i].Color = mColor; } device.VertexDeclaration = mDecl; // draw me! effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); device.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, mVerts, 0, mVerts.Length, mIndices, 0, mIndices.Length / 3); pass.End(); } effect.End(); }
public void ApplyFullScreenEffect(Effect effect, Texture2D tex) { Viewport viewport = _graphicDevice.Viewport; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { _spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None); pass.Begin(); Rectangle destinationRectangle = new Rectangle(0, 0, viewport.Width, viewport.Height); _spriteBatch.Draw(tex, destinationRectangle, Color.White); _spriteBatch.End(); pass.End(); } effect.End(); }
public static byte[] Generate(AsmTechnique technique, Platform platform) { string techniqueCode; AsmToHlslConverter vsConvert = new AsmToHlslConverter(technique.VertexShader, "vs", platform, technique.VertexShader.RegisterSet.FloatRegisterCount, technique.VertexShader.RegisterSet.BooleanRegisterCount); AsmToHlslConverter psConvert = new AsmToHlslConverter(technique.PixelShader, "ps", platform, technique.PixelShader.RegisterSet.FloatRegisterCount, technique.PixelShader.RegisterSet.BooleanRegisterCount); if (platform == Platform.Windows) { StringBuilder constantSetup = new StringBuilder(); // technique.ConstructTechniqueConstants(constantSetup, false); string vsAsm = technique.VertexShader.ToString(); vsAsm = vsAsm.Replace(Environment.NewLine, Environment.NewLine + "\t\t\t\t"); string psAsm = technique.PixelShader.ToString(); psAsm = psAsm.Replace(Environment.NewLine, Environment.NewLine + "\t\t\t\t"); techniqueCode = string.Format( @" uniform float4 _vs_c[11] : register(vs, c0); {4} technique Shader {0} pass {0} VertexShader = asm {0} {2} {1}; PixelShader = asm {0} {3} {1}; {1} {1}", "{", "}", vsAsm, psAsm, constantSetup); } else { string vsSource = vsConvert.GetSource(); string psSource = psConvert.GetSource(); //setup the technique. techniqueCode = string.Format( @" {2} {3} technique Shader {0} pass {0} VertexShader = compile {4} vsMain(); PixelShader = compile {5} psMain(); {1} {1}", "{", "}", vsSource, psSource, vsConvert.GetProfile().ToString().ToLower(), psConvert.GetProfile().ToString().ToLower()); } TargetPlatform target = TargetPlatform.Unknown; switch (platform) { case Platform.Both: throw new ArgumentException(); case Platform.Windows: target = TargetPlatform.Windows; break; case Platform.Xbox: target = TargetPlatform.Xbox360; break; } CompiledEffect effectSource = Effect.CompileEffectFromSource(techniqueCode, null, null, CompilerOptions.None, target); if (effectSource.Success == false) Common.ThrowError(effectSource.ErrorsAndWarnings, techniqueCode); byte[] code = effectSource.GetEffectCode(); Effect effect = new Effect(Graphics.GraphicsDevice, code, CompilerOptions.None, new EffectPool()); Vector4[] valuesV = new Vector4[11]; for (int i = 0; i < valuesV.Length; i++) { valuesV[i] = new Vector4(i,0,0,0); } //Vector4[] valuesP = new Vector4[24]; //for (int i = 0; i < valuesP.Length; i++) //{ // valuesP[i] = new Vector4(0, i, 0, 0); //} effect.Parameters[0].SetValue(valuesV); Vector4[] test = effect.Parameters[0].GetValueVector4Array(11); //effect.Parameters[1].SetValue(valuesP); //effect.Parameters[2].SetValue(new bool[] { false, false }); GraphicsDevice gd = Graphics.GraphicsDevice; effect.CurrentTechnique = effect.Techniques[0]; effect.Begin(); effect.Techniques[0].Passes[0].Begin(); Vector4[] outputV = gd.GetVertexShaderVector4ArrayConstant(0, 255); Vector4[] outputP = gd.GetPixelShaderVector4ArrayConstant(0, 24); //bool[] outputPB = gd.GetPixelShaderBooleanConstant(0, 2); effect.Techniques[0].Passes[0].End(); effect.End(); string asm = effect.Disassemble(false); return code; }
public void Draw(Effect effect, string colorMapParamName, string normalMapParamName, string heightMapParamName, Texture2D wallColorMap, Texture2D wallNormalMap, Texture2D wallHeightMap, Texture2D floorColorMap, Texture2D floorNormalMap, Texture2D floorHeightMap, Texture2D ceilingColorMap, Texture2D ceilingNormalMap, Texture2D ceilingHeightMap, bool drawingCeiling) { graphicsDevice.VertexDeclaration = vertexDeclaration; graphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, NormalMappedVertex.SizeInBytes); // Draw the scene geometry. effect.Begin(); // Draw the walls. effect.Parameters[colorMapParamName].SetValue(wallColorMap); effect.Parameters[normalMapParamName].SetValue(wallNormalMap); effect.Parameters[heightMapParamName].SetValue(wallHeightMap); effect.CommitChanges(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, wallsIndex, 8); pass.End(); } if (drawingCeiling) { // Draw the ceiling. effect.Parameters[colorMapParamName].SetValue(ceilingColorMap); effect.Parameters[normalMapParamName].SetValue(ceilingNormalMap); effect.Parameters[heightMapParamName].SetValue(ceilingHeightMap); effect.CommitChanges(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, ceilingIndex, 2); pass.End(); } } // Draw the floor. effect.Parameters[colorMapParamName].SetValue(floorColorMap); effect.Parameters[normalMapParamName].SetValue(floorNormalMap); effect.Parameters[heightMapParamName].SetValue(floorHeightMap); effect.CommitChanges(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, floorIndex, 2); pass.End(); } effect.End(); }
public void Draw(GraphicsDevice graphics, Effect effect, Effect terrainEffect) { this.frustrum = new BoundingFrustum(terrainEffect.Parameters["WorldViewProjection"].GetValueMatrix()); graphics.VertexDeclaration = this.terrainVertexDeclaration; graphics.RenderState.CullMode = CullMode.CullCounterClockwiseFace; graphics.RenderState.AlphaBlendEnable = true; graphics.Indices = this.indices; terrainEffect.CurrentTechnique = effect.Techniques["Default"]; terrainEffect.Begin(); for (int i = 0; i < this.mapBlocks.GetLength(0); i++) { for (int j = 0; j < this.mapBlocks.GetLength(1); j++) { if (this.mapBlocks[i, j].IsView(this.frustrum)) { this.mapBlocks[i, j].Draw(terrainEffect); this.isView[i, j] = true; } else { this.isView[i, j] = false; } } } terrainEffect.End(); graphics.RenderState.AlphaBlendEnable = false; graphics.RenderState.CullMode = CullMode.CullClockwiseFace; graphics.VertexDeclaration = this.decorationVertexDeclaration; effect.CurrentTechnique = effect.Techniques["Default"]; effect.Begin(); for (int i = 0; i < this.decorationBlocks.GetLength(0); i++) { for (int j = 0; j < this.decorationBlocks.GetLength(1); j++) { if (this.isView[i, j]) { this.decorationBlocks[i, j].Draw(effect); } } } effect.End(); }
/// <summary> /// Draws the tree mesh using a given effect. /// You should set the proper parameters on the effect first, such as World, View, and Projection matrices. /// </summary> /// <param name="effect">Effect to draw with.</param> public void Draw(Effect effect) { device.VertexDeclaration = vdeclaration; device.Vertices[0].SetSource(vbuffer, 0, TreeVertex.SizeInBytes); device.Indices = ibuffer; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numvertices, 0, numtriangles); pass.End(); } effect.End(); }
private Texture2D DrawDepth(Effect VertexShader, Effect PixelShader) { DepthStencilBuffer OldDSBuffer = m_GraphicsDevice.DepthStencilBuffer; RenderTarget2D RTarget = new RenderTarget2D(m_GraphicsDevice, ShadowRes, ShadowRes, 0, SurfaceFormat.Single, RenderTargetUsage.PreserveContents); DepthStencilBuffer DSBuffer = new DepthStencilBuffer(m_GraphicsDevice, ShadowRes, ShadowRes, OldDSBuffer.Format); m_GraphicsDevice.DepthStencilBuffer = DSBuffer; m_GraphicsDevice.SetRenderTarget(0, RTarget); m_GraphicsDevice.Clear(Color.CornflowerBlue); VertexShader.Begin(); VertexShader.CurrentTechnique.Passes[1].Begin(); PixelShader.Begin(); PixelShader.CurrentTechnique.Passes[1].Begin(); m_GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, m_MeshTris); //draw depth texture of city mesh to render target to use for shadowing. VertexShader.CurrentTechnique.Passes[1].End(); VertexShader.End(); PixelShader.CurrentTechnique.Passes[1].End(); PixelShader.End(); m_GraphicsDevice.SetRenderTarget(0, null); m_GraphicsDevice.DepthStencilBuffer = OldDSBuffer; Texture2D Return = RTarget.GetTexture(); DSBuffer.Dispose(); //if we don't do this, the graphics memory gets overloaded pretty damn fast RTarget.Dispose(); return Return; }
void DrawBlur(float x, float y, Effect effectToUse, RenderTarget2D source, RenderTarget2D target) { SetBlurEffectParameters(x, y, effectToUse); GraphicsDevice.SetRenderTarget(0, target); spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None); effectToUse.Begin(); effectToUse.CurrentTechnique.Passes[0].Begin(); spriteBatch.Draw(source.GetTexture(), new Rectangle(0, 0, target.Width, target.Height), Color.White); spriteBatch.End(); effectToUse.CurrentTechnique.Passes[0].End(); effectToUse.End(); }
private void DrawTerrain(Effect effect) { effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); for (int i = 0; i < Patches.Count; ++i) { // Test the patch against frustum. BoundingBox transformedBBox = Transform(Patches[i].BoundingBox, World); if (Camera.Frustum.Contains(Patches[i].BoundingBox) != ContainmentType.Disjoint) { Patches[i].Draw(); ++DrawnPatchCount; } } pass.End(); } effect.End(); }
/// <summary> /// draw the world extents on-screen. /// </summary> /// <param name="device">Graphics Device</param> /// <param name="effect">An Effect to draw the lines with (should implement vertex color diffuse)</param> public void debugDrawMe(GraphicsDevice device, Effect effect) { if (mVertexDecl == null) { mVertexDecl = new VertexDeclaration(device, VertexPositionColor.VertexElements); } // draw the world limits. VertexPositionColor[] limits = new VertexPositionColor[5]; limits[0].Position = new Vector3(mWorldLimits.Min.X, mWorldLimits.Max.Y, 0); limits[0].Color = Color.SlateGray; limits[1].Position = new Vector3(mWorldLimits.Max.X, mWorldLimits.Max.Y, 0); limits[1].Color = Color.SlateGray; limits[2].Position = new Vector3(mWorldLimits.Max.X, mWorldLimits.Min.Y, 0); limits[2].Color = Color.SlateGray; limits[3].Position = new Vector3(mWorldLimits.Min.X, mWorldLimits.Min.Y, 0); limits[3].Color = Color.SlateGray; limits[4].Position = new Vector3(mWorldLimits.Min.X, mWorldLimits.Max.Y, 0); limits[4].Color = Color.SlateGray; device.VertexDeclaration = mVertexDecl; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, limits, 0, 4); pass.End(); } effect.End(); }
/// <summary> /// Test line rendering3D /// </summary> public static void TestLineRendering3D() { Matrix Projection = Matrix.Identity, View = Matrix.Identity; Vector3 pos1 = new Vector3(0, 0, 0), pos2 = new Vector3(100, 100, 100); VertexPositionColor[] lineVertices = new VertexPositionColor[2]; lineVertices[0] = new VertexPositionColor(pos1, Color.Red); lineVertices[1] = new VertexPositionColor(pos2, Color.Yellow); Effect effect = null; EffectParameter worldViewProj = null; TestGame.Start("TestLineRendering3D", delegate // init { float aspectRatio = (float)TestGame.Width / (float)TestGame.Height; Projection = Matrix.CreatePerspectiveFieldOfView( (float)Math.PI / 2, aspectRatio, 0.1f, 1000.0f); View = Matrix.CreateLookAt( new Vector3(0, 0, -50), Vector3.Zero, Vector3.Up); CompiledEffect compiledEffect = Effect.CompileEffectFromFile( "Shaders\\LineRendering.fx", null, null, CompilerOptions.None, TargetPlatform.Windows); effect = new Effect(TestGame.Device, compiledEffect.GetEffectCode(), CompilerOptions.None, null); worldViewProj = effect.Parameters["worldViewProj"]; }, delegate // update { }, delegate // render { // Start line shader effect.Begin(SaveStateMode.None); effect.Techniques[0].Passes["PassFor3D"].Begin(); // Render line worldViewProj.SetValue(View * Projection); BaseGame.Device.VertexDeclaration = new VertexDeclaration( BaseGame.Device, VertexPositionColor.VertexElements); BaseGame.Device.RenderState.CullMode = CullMode.CullClockwiseFace; BaseGame.Device.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.LineList, lineVertices, 0, 1); // End shader effect.Techniques[0].Passes["PassFor3D"].End(); effect.End(); }); }
/// <summary> /// draw the velocities of all PointMasses in the simulation on-screen in an orange/yellow color. /// </summary> /// <param name="device">GraphicsDevice</param> /// <param name="effect">An Effect to draw the lines with</param> public void debugDrawPointVelocities(GraphicsDevice device, Effect effect) { if (mVertexDecl == null) { mVertexDecl = new VertexDeclaration(device, VertexPositionColor.VertexElements); } for (int i = 0; i < mBodies.Count; i++) { VertexPositionColor[] vels = new VertexPositionColor[mBodies[i].PointMassCount * 2]; for (int pm = 0; pm < mBodies[i].PointMassCount; pm++) { vels[(pm * 2) + 0].Position = VectorTools.vec3FromVec2(mBodies[i].getPointMass(pm).Position); vels[(pm * 2) + 0].Color = Color.Yellow; vels[(pm * 2) + 1].Position = VectorTools.vec3FromVec2(mBodies[i].getPointMass(pm).Position + (mBodies[i].getPointMass(pm).Velocity * 0.25f)); vels[(pm * 2) + 1].Color = Color.Orange; } effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vels, 0, mBodies[i].PointMassCount); pass.End(); } effect.End(); } }
/// <summary> /// Helper for drawing a texture into the current rendertarget, /// using a custom shader to apply postprocessing effects. /// </summary> void DrawFullscreenQuad(Texture2D texture, int width, int height, Effect effect, IntermediateBuffer currentBuffer) { spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState); // Begin the custom effect, if it is currently enabled. If the user // has selected one of the show intermediate buffer options, we still // draw the quad to make sure the image will end up on the screen, // but might need to skip applying the custom pixel shader. if (showBuffer >= currentBuffer) { effect.Begin(); effect.CurrentTechnique.Passes[0].Begin(); } // Draw the quad. spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White); spriteBatch.End(); // End the custom effect. if (showBuffer >= currentBuffer) { effect.CurrentTechnique.Passes[0].End(); effect.End(); } }
/// <summary> /// Draws the primitive model, using the specified effect. Unlike the other /// Draw overload where you just specify the world/view/projection matrices /// and color, this method does not set any renderstates, so you must make /// sure all states are set to sensible values before you call it. /// </summary> public void Draw(Effect effect) { GraphicsDevice graphicsDevice = effect.GraphicsDevice; // Set our vertex declaration, vertex buffer, and index buffer. graphicsDevice.VertexDeclaration = vertexDeclaration; graphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionNormal.SizeInBytes); graphicsDevice.Indices = indexBuffer; // Draw the model, using the specified effect. effect.Begin(); foreach (EffectPass effectPass in effect.CurrentTechnique.Passes) { effectPass.Begin(); int primitiveCount = indices.Count / 3; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Count, 0, primitiveCount); effectPass.End(); } effect.End(); }
/// <summary> /// Execute shaders and show result on screen, Start(..) must have been /// called before and the scene should be rendered to sceneMapTexture. /// </summary> public void Show() { // Only apply post screen glow if texture is valid and effect is valid if (sceneMapTexture == null || Valid == false || started == false) return; started = false; // Resolve sceneMapTexture render target for Xbox360 support sceneMapTexture.Resolve(true); try { // Don't use or write to the z buffer BaseGame.Device.RenderState.DepthBufferEnable = false; BaseGame.Device.RenderState.DepthBufferWriteEnable = false; // Also don't use any kind of blending. BaseGame.Device.RenderState.AlphaBlendEnable = false; //unused: BaseGame.Device.RenderState.Lighting = false; if (windowSize != null) windowSize.SetValue(new float[] { sceneMapTexture.Width, sceneMapTexture.Height }); if (sceneMap != null) sceneMap.SetValue(sceneMapTexture.XnaTexture); if (downsampleMap != null) downsampleMap.SetValue(downsampleMapTexture.XnaTexture); if (blurMap1 != null) blurMap1.SetValue(blurMap1Texture.XnaTexture); if (blurMap2 != null) blurMap2.SetValue(blurMap2Texture.XnaTexture); if (radialSceneMap != null) radialSceneMap.SetValue(radialSceneMapTexture.XnaTexture); RadialBlurScaleFactor = //-0.0125f; // Warning: To big values will make the motion blur look to // stepy (we see each step and thats not good). -0.02 should be max. -(0.005f + Player.Speed * 0.015f); if (BaseGame.UsePS20) effect.CurrentTechnique = effect.Techniques["ScreenGlow20"]; else effect.CurrentTechnique = effect.Techniques["ScreenGlow"]; // We must have exactly 5 passes! if (effect.CurrentTechnique.Passes.Count != 5) throw new Exception("This shader should have exactly 5 passes!"); effect.Begin();//SaveStateMode.None); for (int pass = 0; pass < effect.CurrentTechnique.Passes.Count; pass++) { if (pass == 0) radialSceneMapTexture.SetRenderTarget(); else if (pass == 1) downsampleMapTexture.SetRenderTarget(); else if (pass == 2) blurMap1Texture.SetRenderTarget(); else if (pass == 3) blurMap2Texture.SetRenderTarget(); else // Do a full reset back to the back buffer RenderToTexture.ResetRenderTarget(true); EffectPass effectPass = effect.CurrentTechnique.Passes[pass]; effectPass.Begin(); // For first effect we use radial blur, draw it with a grid // to get cooler results (more blur at borders than in middle). if (pass == 0) VBScreenHelper.Render10x10Grid(); else VBScreenHelper.Render(); effectPass.End(); if (pass == 0) { radialSceneMapTexture.Resolve(false); if (radialSceneMap != null) radialSceneMap.SetValue(radialSceneMapTexture.XnaTexture); effect.CommitChanges(); } // if else if (pass == 1) { downsampleMapTexture.Resolve(false); if (downsampleMap != null) downsampleMap.SetValue(downsampleMapTexture.XnaTexture); effect.CommitChanges(); } // if else if (pass == 2) { blurMap1Texture.Resolve(false); if (blurMap1 != null) blurMap1.SetValue(blurMap1Texture.XnaTexture); effect.CommitChanges(); } // else if else if (pass == 3) { blurMap2Texture.Resolve(false); if (blurMap2 != null) blurMap2.SetValue(blurMap2Texture.XnaTexture); effect.CommitChanges(); } // else if } // for (pass, <, ++) } // try catch (Exception ex) { // Make effect invalid, continue rendering without this // post screen shader. effect = null; RenderToTexture.ResetRenderTarget(true); #if DEBUG throw ex; #else Log.Write("Failed to render post screen shader "+Filename+": "+ ex.ToString()); #endif } // catch finally { if (effect != null) effect.End(); // Restore z buffer state BaseGame.Device.RenderState.DepthBufferEnable = true; BaseGame.Device.RenderState.DepthBufferWriteEnable = true; } // finally }
private void RenderSpriteList(List<_2DSprite> sprites, Effect effect, EffectTechnique technique) { if (sprites.Count == 0) { return; } /** Group by texture **/ var groupByTexture = GroupByTexture(sprites); foreach (var group in groupByTexture) { var texture = group.Pixel; var depth = group.Depth; var numSprites = group.Sprites.Count; effect.Parameters["pixelTexture"].SetValue(texture); if (depth != null) { effect.Parameters["depthTexture"].SetValue(depth); } /** Build vertex data **/ var verticies = new _2DSpriteVertex[4 * numSprites]; var indices = new short[6 * numSprites]; var indexCount = 0; var vertexCount = 0; foreach (var sprite in group.Sprites) { var srcRectangle = sprite.SrcRect; var dstRectangle = sprite.AbsoluteDestRect; indices[indexCount++] = (short)(vertexCount + 0); indices[indexCount++] = (short)(vertexCount + 1); indices[indexCount++] = (short)(vertexCount + 3); indices[indexCount++] = (short)(vertexCount + 1); indices[indexCount++] = (short)(vertexCount + 2); indices[indexCount++] = (short)(vertexCount + 3); // add the new vertices if (sprite.FlipHorizontally) { verticies[vertexCount++] = new _2DSpriteVertex( new Vector3(dstRectangle.Left, dstRectangle.Top, 0) , GetUV(texture, srcRectangle.Right, srcRectangle.Top), sprite.AbsoluteWorldPosition); verticies[vertexCount++] = new _2DSpriteVertex( new Vector3(dstRectangle.Right, dstRectangle.Top, 0) , GetUV(texture, srcRectangle.Left, srcRectangle.Top), sprite.AbsoluteWorldPosition); verticies[vertexCount++] = new _2DSpriteVertex( new Vector3(dstRectangle.Right, dstRectangle.Bottom, 0) , GetUV(texture, srcRectangle.Left, srcRectangle.Bottom), sprite.AbsoluteWorldPosition); verticies[vertexCount++] = new _2DSpriteVertex( new Vector3(dstRectangle.Left, dstRectangle.Bottom, 0) , GetUV(texture, srcRectangle.Right, srcRectangle.Bottom), sprite.AbsoluteWorldPosition); } else { verticies[vertexCount++] = new _2DSpriteVertex( new Vector3(dstRectangle.Left, dstRectangle.Top, 0) , GetUV(texture, srcRectangle.Left, srcRectangle.Top), sprite.AbsoluteWorldPosition); verticies[vertexCount++] = new _2DSpriteVertex( new Vector3(dstRectangle.Right, dstRectangle.Top, 0) , GetUV(texture, srcRectangle.Right, srcRectangle.Top), sprite.AbsoluteWorldPosition); verticies[vertexCount++] = new _2DSpriteVertex( new Vector3(dstRectangle.Right, dstRectangle.Bottom, 0) , GetUV(texture, srcRectangle.Right, srcRectangle.Bottom), sprite.AbsoluteWorldPosition); verticies[vertexCount++] = new _2DSpriteVertex( new Vector3(dstRectangle.Left, dstRectangle.Bottom, 0) , GetUV(texture, srcRectangle.Left, srcRectangle.Bottom), sprite.AbsoluteWorldPosition); } } effect.CurrentTechnique = technique; effect.Begin(); EffectPassCollection passes = technique.Passes; for (int i = 0; i < passes.Count; i++) { EffectPass pass = passes[i]; pass.Begin(); Device.DrawUserIndexedPrimitives<_2DSpriteVertex>( PrimitiveType.TriangleList, verticies, 0, verticies.Length, indices, 0, indices.Length / 3); pass.End(); } effect.End(); } }
/// <summary> /// Test line rendering2D /// </summary> public static void TestLineRendering2D() { Matrix Projection = Matrix.Identity, View = Matrix.Identity; Point pos1 = new Point(0, 0), pos2 = new Point(500, 250); VertexPositionColor[] lineVertices = new VertexPositionColor[2]; Effect effect = null; EffectParameter worldViewProj = null; TestGame.Start("TestLineRendering2D", delegate // init { float aspectRatio = (float)TestGame.Width / (float)TestGame.Height; Projection = Matrix.CreatePerspectiveFieldOfView( (float)Math.PI / 2, aspectRatio, 0.1f, 1000.0f); View = Matrix.CreateLookAt( new Vector3(0, 0, -50), Vector3.Zero, Vector3.Up); lineVertices[0] = new VertexPositionColor( new Vector3( -1.0f + 2.0f * pos1.X / TestGame.Width, -(-1.0f + 2.0f * pos1.Y / TestGame.Height), 0), Color.Red); lineVertices[1] = new VertexPositionColor( new Vector3( -1.0f + 2.0f * pos2.X / TestGame.Width, -(-1.0f + 2.0f * pos2.Y / TestGame.Height), 0), Color.Green); CompiledEffect compiledEffect = Effect.CompileEffectFromFile( "Content\\LineRendering.fx", null, null, CompilerOptions.None, TargetPlatform.Windows); effect = new Effect(TestGame.Device, compiledEffect.GetEffectCode(), CompilerOptions.None, null); worldViewProj = effect.Parameters["worldViewProj"]; //Log.Write("techniques: " + effect.Techniques.Count); }, delegate // update { }, delegate // render { // Start line shader effect.CurrentTechnique = effect.Techniques["LineRendering2D"]; effect.Begin(SaveStateMode.None); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); // Render line worldViewProj.SetValue(View * Projection); TestGame.Device.VertexDeclaration = new VertexDeclaration( TestGame.Device, VertexPositionColor.VertexElements); TestGame.Device.RenderState.CullMode = CullMode.CullClockwiseFace; TestGame.Device.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.LineList, lineVertices, 0, 1); // End shader pass.End(); } // foreach (pass) effect.End(); }); }
//Draws a texture to a renderTarget with an effect, renderTarget null is the screen for output void DrawToRenderTarget(Texture2D texture, RenderTarget2D renderTarget, Effect effect) { int width, height; if (renderTarget != null) { device.SetRenderTarget(0, renderTarget); width = renderTarget.Width; height = renderTarget.Height; } else { width = device.Viewport.Width; height = device.Viewport.Height; } spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None); effect.Begin(); foreach (EffectPass p in effect.CurrentTechnique.Passes) { p.Begin(); // Draw spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White); p.End(); } effect.End(); spriteBatch.End(); device.SetRenderTarget(0, null); }
private void DrawFullscreenQuad(Texture2D texture, int width, int height, Effect effect) { this.ScreenManager.SpriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None); effect.Begin(); effect.CurrentTechnique.Passes[0].Begin(); this.ScreenManager.SpriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White); this.ScreenManager.SpriteBatch.End(); effect.CurrentTechnique.Passes[0].End(); effect.End(); }
/// <summary> /// Render all meshes that use this technique sorted by the materials. /// This method is only called if we got any meshes to render, /// which is determinated if NumberOfRenderMeshes is greater 0. /// </summary> /// <param name="effect">Effect</param> public void Render(Effect effect) { // Start effect for this technique effect.CurrentTechnique = technique; effect.Begin(SaveStateMode.None); // Render all pass (we always just have one) //obs: foreach (EffectPass pass in effect.CurrentTechnique.Passes) { EffectPass pass = effect.CurrentTechnique.Passes[0]; pass.Begin(); // Render all meshes sorted by all materials. //obs: foreach (MeshesPerMaterial list in meshesPerMaterials) for (int listNum = 0; listNum < meshesPerMaterials.Count; listNum++) { MeshesPerMaterial list = meshesPerMaterials[listNum]; if (list.NumberOfRenderMatrices > 0) list.Render(); } // for (listNum) pass.End(); } // foreach (pass) // End shader effect.End(); }
// ----------------------------------------------------------------- public void ApplyBlur( ref Effect effect ) { // apply blur to all scales of the original target // again, this is done manually and might be done in // an array // ps: the temporary targets are used, here // custom spritebatch vertexshader Vector2 Size; /* * copy Rendertargets to temporary buffers */ m_Device.SetRenderTarget( 0, m_TempTargets[ 5 ] ); m_Device.Clear( Color.Black ); m_SpriteBatch.Begin( ); m_SpriteBatch.Draw( m_DownSampleTargets[ 5 ].GetTexture( ), Vector2.Zero, Color.White ); m_SpriteBatch.End( ); m_Device.SetRenderTarget( 0, m_TempTargets[ 4 ] ); m_Device.Clear( Color.Black ); m_SpriteBatch.Begin( ); m_SpriteBatch.Draw( m_DownSampleTargets[ 4 ].GetTexture( ), Vector2.Zero, Color.White ); m_SpriteBatch.End( ); m_Device.SetRenderTarget( 0, m_TempTargets[ 3 ] ); m_Device.Clear( Color.Black ); m_SpriteBatch.Begin( ); m_SpriteBatch.Draw( m_DownSampleTargets[ 3 ].GetTexture( ), Vector2.Zero, Color.White ); m_SpriteBatch.End( ); m_Device.SetRenderTarget( 0, m_TempTargets[ 2 ] ); m_Device.Clear( Color.Black ); m_SpriteBatch.Begin( ); m_SpriteBatch.Draw( m_DownSampleTargets[ 2 ].GetTexture( ), Vector2.Zero, Color.White ); m_SpriteBatch.End( ); m_Device.SetRenderTarget( 0, m_TempTargets[ 1 ] ); m_Device.Clear( Color.Black ); m_SpriteBatch.Begin( ); m_SpriteBatch.Draw( m_DownSampleTargets[ 1 ].GetTexture( ), Vector2.Zero, Color.White ); m_SpriteBatch.End( ); m_Device.SetRenderTarget( 0, m_TempTargets[ 0 ] ); m_Device.Clear( Color.Black ); m_SpriteBatch.Begin( ); m_SpriteBatch.Draw( m_DownSampleTargets[ 0 ].GetTexture( ), Vector2.Zero, Color.White ); m_SpriteBatch.End( ); /* * render temporary buffers to downscaled targets */ Size.X = m_Width / 64; Size.Y = m_Height / 64; m_Device.SetRenderTarget( 0, m_DownSampleTargets[ 5 ] ); m_Device.Clear( Color.Black ); m_Device.Textures[ 0 ] = m_TempTargets[5].GetTexture( ); effect.CurrentTechnique = effect.Techniques[ BLUR_QUALITY ]; effect.Parameters[ "ViewportSize" ].SetValue( Size ); effect.Parameters[ "TextureSize" ].SetValue( Size ); effect.Parameters[ "MatrixTransform" ].SetValue( Matrix.Identity ); effect.Parameters[ "gScreenWidth" ].SetValue( Size.X ); effect.Parameters[ "gScreenHeight" ].SetValue( Size.Y ); effect.Parameters[ "gScaleFactor" ].SetValue( SCALE_FACTOR ); effect.Begin( ); EffectPass pass = effect.CurrentTechnique.Passes[ 0 ]; m_SpriteBatch.Begin( SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState ); pass.Begin( ); m_SpriteBatch.Draw( m_TempTargets[ 5 ].GetTexture( ), Vector2.Zero, Color.White ); pass.End( ); m_SpriteBatch.End( ); effect.End( ); Size.X = m_Width / 32; Size.Y = m_Height / 32; m_Device.SetRenderTarget( 0, m_DownSampleTargets[ 4 ] ); m_Device.Clear( Color.Black ); m_Device.Textures[ 0 ] = m_TempTargets[ 4 ].GetTexture( ); effect.CurrentTechnique = effect.Techniques[ BLUR_QUALITY ]; effect.Parameters[ "ViewportSize" ].SetValue( Size ); effect.Parameters[ "TextureSize" ].SetValue( Size ); effect.Parameters[ "MatrixTransform" ].SetValue( Matrix.Identity ); effect.Parameters[ "gScreenWidth" ].SetValue( Size.X ); effect.Parameters[ "gScreenHeight" ].SetValue( Size.Y ); effect.Parameters[ "gScaleFactor" ].SetValue( SCALE_FACTOR ); effect.Begin( ); pass = effect.CurrentTechnique.Passes[ 0 ]; m_SpriteBatch.Begin( SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState ); pass.Begin( ); m_SpriteBatch.Draw( m_TempTargets[ 4 ].GetTexture( ), Vector2.Zero, Color.White ); pass.End( ); m_SpriteBatch.End( ); effect.End( ); Size.X = m_Width / 16; Size.Y = m_Height / 16; m_Device.SetRenderTarget( 0, m_DownSampleTargets[ 3 ] ); m_Device.Clear( Color.Black ); m_Device.Textures[ 0 ] = m_TempTargets[ 3 ].GetTexture( ); effect.CurrentTechnique = effect.Techniques[ BLUR_QUALITY ]; effect.Parameters[ "ViewportSize" ].SetValue( Size ); effect.Parameters[ "TextureSize" ].SetValue( Size ); effect.Parameters[ "MatrixTransform" ].SetValue( Matrix.Identity ); effect.Parameters[ "gScreenWidth" ].SetValue( Size.X ); effect.Parameters[ "gScreenHeight" ].SetValue( Size.Y ); effect.Parameters[ "gScaleFactor" ].SetValue( SCALE_FACTOR ); effect.Begin( ); pass = effect.CurrentTechnique.Passes[ 0 ]; m_SpriteBatch.Begin( SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState ); pass.Begin( ); m_SpriteBatch.Draw( m_TempTargets[ 3 ].GetTexture( ), Vector2.Zero, Color.White ); pass.End( ); m_SpriteBatch.End( ); effect.End( ); Size.X = m_Width / 8; Size.Y = m_Height / 8; m_Device.SetRenderTarget( 0, m_DownSampleTargets[ 2 ] ); m_Device.Clear( Color.Black ); m_Device.Textures[ 0 ] = m_TempTargets[ 2 ].GetTexture( ); effect.CurrentTechnique = effect.Techniques[ BLUR_QUALITY ]; effect.Parameters[ "ViewportSize" ].SetValue( Size ); effect.Parameters[ "TextureSize" ].SetValue( Size ); effect.Parameters[ "MatrixTransform" ].SetValue( Matrix.Identity ); effect.Parameters[ "gScreenWidth" ].SetValue( Size.X ); effect.Parameters[ "gScreenHeight" ].SetValue( Size.Y ); effect.Parameters[ "gScaleFactor" ].SetValue( SCALE_FACTOR ); effect.Begin( ); pass = effect.CurrentTechnique.Passes[ 0 ]; m_SpriteBatch.Begin( SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState ); pass.Begin( ); m_SpriteBatch.Draw( m_TempTargets[ 2 ].GetTexture( ), Vector2.Zero, Color.White ); pass.End( ); m_SpriteBatch.End( ); effect.End( ); Size.X = m_Width / 4; Size.Y = m_Height / 4; m_Device.SetRenderTarget( 0, m_DownSampleTargets[ 1 ] ); m_Device.Clear( Color.Black ); m_Device.Textures[ 0 ] = m_TempTargets[ 1 ].GetTexture( ); effect.CurrentTechnique = effect.Techniques[ BLUR_QUALITY ]; effect.Parameters[ "ViewportSize" ].SetValue( Size ); effect.Parameters[ "TextureSize" ].SetValue( Size ); effect.Parameters[ "MatrixTransform" ].SetValue( Matrix.Identity ); effect.Parameters[ "gScreenWidth" ].SetValue( Size.X ); effect.Parameters[ "gScreenHeight" ].SetValue( Size.Y ); effect.Parameters[ "gScaleFactor" ].SetValue( SCALE_FACTOR ); effect.Begin( ); pass = effect.CurrentTechnique.Passes[ 0 ]; m_SpriteBatch.Begin( SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState ); pass.Begin( ); m_SpriteBatch.Draw( m_TempTargets[ 1 ].GetTexture( ), Vector2.Zero, Color.White ); pass.End( ); m_SpriteBatch.End( ); effect.End( ); Size.X = m_Width / 2; Size.Y = m_Height / 2; m_Device.SetRenderTarget( 0, m_DownSampleTargets[ 0 ] ); m_Device.Clear( Color.Black ); m_Device.Textures[ 0 ] = m_TempTargets[ 0 ].GetTexture( ); effect.CurrentTechnique = effect.Techniques[ BLUR_QUALITY ]; effect.Parameters[ "ViewportSize" ].SetValue( Size ); effect.Parameters[ "TextureSize" ].SetValue( Size ); effect.Parameters[ "MatrixTransform" ].SetValue( Matrix.Identity ); effect.Parameters[ "gScreenWidth" ].SetValue( Size.X ); effect.Parameters[ "gScreenHeight" ].SetValue( Size.Y ); effect.Parameters[ "gScaleFactor" ].SetValue( SCALE_FACTOR ); effect.Begin( ); pass = effect.CurrentTechnique.Passes[ 0 ]; m_SpriteBatch.Begin( SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState ); pass.Begin( ); m_SpriteBatch.Draw( m_TempTargets[ 0 ].GetTexture( ), Vector2.Zero, Color.White ); pass.End( ); m_SpriteBatch.End( ); effect.End( ); m_Device.SetRenderTarget( 0, null ); }