Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. Main.cs, main draw call:
  2. protected override void Draw(GameTime gameTime)
  3. {
  4. #region Draw World
  5. //begin and end calls are taken care of inside world.Draw
  6. world?.Draw(batch);
  7.  
  8. world?.DrawExtraEntity(batch, "outline");
  9. CompoundShaderDraw.Draw(batch, entityTarget, effectCompoundTarget, Color.Transparent, BlendState.AlphaBlend, outlineEffects);
  10.  
  11. GraphicsDevice.SetRenderTarget(worldTarget);
  12. GraphicsDevice.Clear(Color.Black);
  13. batch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, null, null, null);
  14.  
  15. batch.Draw(bgTilesTarget, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
  16. batch.Draw(entityTarget, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
  17. batch.Draw(fgTilesTarget, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
  18.  
  19. batch.End();
  20. #endregion
  21.  
  22. world?.DrawExtraEntity(batch, "cutout");
  23.  
  24. #region Draw UI
  25. GraphicsDevice.SetRenderTarget(uiTarget);
  26. GraphicsDevice.Clear(Color.Transparent);
  27.  
  28. batch.Begin(SpriteSortMode.FrontToBack, BlendState.NonPremultiplied, SamplerState.PointWrap, DepthStencilState.DepthRead, null, null, null);
  29.  
  30. batch.DrawRectangle(new RectangleF(0, 0, width, height * (screenCoverPercent / 2f)), Color.Black);
  31. batch.DrawRectangle(new RectangleF(0, height - (height * (screenCoverPercent / 2f)), width, height * (screenCoverPercent / 2f)), Color.Black);
  32.  
  33. menuManager.Draw(batch);
  34. dialogueManager.Draw(batch);
  35. batch.End();
  36. #endregion
  37.  
  38. #region Draw Final
  39. GraphicsDevice.SetRenderTarget(finalTarget);
  40. GraphicsDevice.Clear(Color.Black);
  41.  
  42. batch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, null, null, null);
  43. batch.Draw(worldTarget, Vector2.Zero, null, Color.White, 0, Vector2.Zero, new Vector2(ScaleX, ScaleY), SpriteEffects.None, 0);
  44.  
  45. batch.End();
  46.  
  47. BlendState bs = new BlendState()
  48. {
  49. AlphaDestinationBlend = Blend.One,
  50. ColorDestinationBlend = Blend.InverseSourceColor,
  51. ColorBlendFunction = BlendFunction.Add,
  52. AlphaSourceBlend = Blend.Zero,
  53. ColorSourceBlend = Blend.Zero,
  54. };
  55.  
  56. batch.Begin(SpriteSortMode.FrontToBack, bs, SamplerState.PointClamp, DepthStencilState.None, null, null, null);
  57. batch.Draw(cutoutTarget, Vector2.Zero, null, Color.White, 0, Vector2.Zero, Scale, SpriteEffects.None, 0);
  58. batch.End();
  59. batch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, null, null, null);
  60. batch.Draw(uiTarget, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);/**/
  61. batch.End();
  62. #endregion
  63.  
  64. #region Draw Final To Backbuffer
  65. GraphicsDevice.SetRenderTarget(null);
  66. GraphicsDevice.Clear(Color.Black);
  67.  
  68. batch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.PointWrap, DepthStencilState.DepthRead, null, null, null);
  69. batch.Draw(finalTarget, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
  70. batch.End();
  71. #endregion
  72.  
  73. base.Draw(gameTime);
  74. }
  75.  
  76. World.cs:
  77. public virtual void DrawExtraEntity(SpriteBatch batch, string mode)
  78. {
  79. if (mode == "outline")
  80. {
  81. batch.GraphicsDevice.SetRenderTarget(Main.Instance.outlineTarget);
  82. batch.GraphicsDevice.Clear(Color.Transparent);
  83.  
  84. batch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, null, null, null);
  85.  
  86. for (int i = 0; i < maxEntities; i++)
  87. {
  88. Entity e = entities[i];
  89. e.DrawExtra(batch, mode);
  90. }
  91.  
  92. batch.End();
  93. }
  94. else if (mode == "cutout")
  95. {
  96. batch.GraphicsDevice.SetRenderTarget(Main.Instance.cutoutTarget);
  97. batch.GraphicsDevice.Clear(Color.Orange);
  98.  
  99. batch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, null, null, null);
  100.  
  101. for (int i = 0; i < maxEntities; i++)
  102. {
  103. Entity e = entities[i];
  104. e.DrawExtra(batch, mode);
  105. }
  106.  
  107. batch.End();
  108. }
  109. }
  110.  
  111. Player.cs:
  112. public override void DrawExtra(SpriteBatch batch, string mode)
  113. {
  114. base.DrawExtra(batch, mode);
  115.  
  116. if (mode == "cutout")
  117. batch.Draw(Main.assetsManager.GetAsset<Texture2D>("circle"), Entity.position - Main.cameraPos, null, Color.Black, 0, new Vector2(512), 0.25f, SpriteEffects.None, 0);
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement