SpecialEffectsRenderer.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace OpenVIII.World
  9. {
  10. class SpecialEffectsRenderer
  11. {
  12. //FX SYSTEM EXPLAINED
  13. /*
  14. * So in vanilla ff8 when you move through the forest for example it spawns the texture
  15. * and that texture shrinks to 0% then is destroyed.
  16. * The fxWalkDuration should be incremented every bHasMoved until X then spawn texture at player position
  17. * with 100% scale and spriteId until it gets to 0% and is destroyed
  18. *
  19. */
  20. private static float fxWalkDuration = 0;
  21. private static int lastFxBushSpriteId = 0;
  22. struct worldFx
  23. {
  24. public Vector3 fxLocation;
  25. public float scale;
  26. public int atlasId;
  27. }
  28. private static List<worldFx> worldEffects = new List<worldFx>();
  29. /// <summary>
  30. /// Takes care of drawing shadows and additional FX when needed (like in forest). [WIP]
  31. /// </summary>
  32. public static void DrawCharacterShadowSpecialEffects()
  33. {
  34. Module_world_debug.worldCharacterInstances[Module_world_debug.currentControllableEntity].bDraw = true; //always draw and later test the cases
  35. if (Module_world_debug.activeCollidePolygon == null)
  36. return;
  37. if ((Module_world_debug.activeCollidePolygon.Value.vertFlags & Module_world_debug.TRIFLAGS_FORESTTEST) > 0) //shadow
  38. {
  39. var shadowGeom = Extended.GetShadowPlane(Module_world_debug.playerPosition + new Vector3(-2.2f, .1f, -2.2f), 4f);
  40. Module_world_debug.ate.Texture = (Texture2D)Module_world_debug.wmset.GetWorldMapTexture(Wmset.Section38_textures.shadowBig, 0);
  41. Module_world_debug.ate.Alpha = .25f;
  42. foreach (var pass in Module_world_debug.ate.CurrentTechnique.Passes)
  43. {
  44. pass.Apply();
  45. Module_world_debug.ate.GraphicsDevice.DepthStencilState = DepthStencilState.None;
  46. Memory.Graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, shadowGeom, 0, shadowGeom.Length / 3);
  47. }
  48. Module_world_debug.ate.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
  49. Module_world_debug.ate.Alpha = 1f;
  50. }
  51. else if ((Module_world_debug.activeCollidePolygon.Value.vertFlags & Module_world_debug.TRIFLAGS_FORESTTEST) == 0 && Module_world_debug.activeCollidePolygon.Value.texFlags == 0
  52. && Module_world_debug.activeCollidePolygon.Value.groundtype <= 5) //forest
  53. {
  54. Module_world_debug.ate.Alpha = 1f;
  55. Module_world_debug.worldCharacterInstances[Module_world_debug.currentControllableEntity].bDraw = false;
  56. if (Module_world_debug.bHasMoved && fxWalkDuration > 0.25f)
  57. {
  58. fxWalkDuration = 0f;
  59. lastFxBushSpriteId %= 4;
  60. worldEffects.Add(new worldFx()
  61. {
  62. fxLocation = Module_world_debug.playerPosition,
  63. scale = 1.00f, atlasId = lastFxBushSpriteId++
  64. });
  65. }
  66. else fxWalkDuration += 0.05f;
  67. }
  68. for (int i = worldEffects.Count - 1; i > 0; i--)
  69. {
  70. VertexPositionTexture[] shadowGeom = Extended.GetShadowPlane(worldEffects[i].fxLocation +
  71. new Vector3(-2.2f, .1f, -2.2f), 12f * worldEffects[i].scale);
  72. Extended.ConvertToSprite(ref shadowGeom, 4, worldEffects[i].atlasId);
  73. Module_world_debug.ate.Texture = (Texture2D)Module_world_debug.wmset.GetWorldMapTexture(Wmset.Section38_textures.wmfx_bush,
  74. MathHelper.Clamp(GetLeavesFxClut(Module_world_debug.activeCollidePolygon), 0, 5)); //this is wrong
  75. Module_world_debug.ate.Alpha = 0.75f;
  76. foreach (EffectPass pass in Module_world_debug.ate.CurrentTechnique.Passes)
  77. {
  78. pass.Apply();
  79. Module_world_debug.ate.GraphicsDevice.DepthStencilState = DepthStencilState.None;
  80. Memory.Graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, shadowGeom, 0, shadowGeom.Length / 3);
  81. }
  82. //ate.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
  83. worldFx currentFx = worldEffects[i];
  84. currentFx.scale -= 0.005f;
  85. if (currentFx.scale < 0.8)
  86. worldEffects.RemoveAt(i);
  87. else
  88. worldEffects[i] = currentFx;
  89. }
  90. }
  91. private static int GetLeavesFxClut(Module_world_debug.Polygon? activeCollidePolygon)
  92. {
  93. switch (activeCollidePolygon.Value.groundtype)
  94. {
  95. case 0:
  96. return 5;
  97. case 1:
  98. return 3;
  99. case 2:
  100. return 1;
  101. case 3:
  102. return 4;
  103. case 4:
  104. return 0;
  105. case 5:
  106. return 2;
  107. default:
  108. return 0;
  109. }
  110. }
  111. }
  112. }