Effects 3D.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /******************************************************************************
  2. This is a set of special effects.
  3. /******************************************************************************/
  4. struct Decal // Decal
  5. {
  6. Bool terrain_only; // if affect only the terrain mesh, true/false, default=false
  7. Vec4 color ; // decal color , default=Vec4(1, 1, 1, 1)
  8. Matrix matrix ; // decal matrix , default=MatrixIdentity
  9. // get / set
  10. Decal& material (C MaterialPtr &material); C MaterialPtr& material()C {return _material;} // set/get material
  11. Decal& setMatrix(C Matrix &object_world_matrix, C Matrix &decal_world_matrix); // set matrix to be used as animated matrix from current 'object_world_matrix' and desired 'decal_world_matrix'
  12. #if EE_PRIVATE
  13. void setShader();
  14. void zero ();
  15. void del ();
  16. #endif
  17. // draw
  18. void drawStatic ( Flt alpha=1)C; // draw as static decal , 'alpha'=opacity, automatically uses Frustum culling, can be called in following render modes : RM_OVERLAY, RM_BLEND, RM_PALETTE, RM_PALETTE1
  19. void drawAnimated(C Matrix &object_world_matrix, Flt alpha=1)C; // draw with given object matrix, 'alpha'=opacity, automatically uses Frustum culling, can be called in following render modes : RM_OVERLAY, RM_BLEND, RM_PALETTE, RM_PALETTE1
  20. // io
  21. Bool save(File &f)C; // save, false on fail
  22. Bool load(File &f) ; // load, false on fail
  23. Decal();
  24. private:
  25. MaterialPtr _material;
  26. Shader *_shader[2][2]; // [F][P] F-Fullscreen, P-Palette
  27. };
  28. /******************************************************************************/
  29. struct ElectricityFx // Electricity Effect
  30. {
  31. Color color , // color , default=Color(64, 96, 176, 255), here alpha is the glow amount
  32. middle_color ; // color rendered in the middle of lines , default=WHITE , here alpha is the glow amount
  33. Flt middle_exponent, // middle color exponent , default=5
  34. radius , // 3d line radius , default=0.008 m
  35. random_step , // distance between newly created random points, default=0.1 m
  36. random_radius , // how far points can be randomly moved , default=0.1 m
  37. frequency ; // time intervals between position updates , default=0.03 s
  38. Memc<Vec> original ; // original control points
  39. void update();
  40. void draw (); // draw using active matrix, this should be called in RM_SOLID and RM_AMBIENT modes
  41. ElectricityFx();
  42. private:
  43. Flt time;
  44. Memc<Vec> randomized;
  45. };
  46. /******************************************************************************/
  47. struct BlendObject // extendable class for depth-sorted rendering of graphics in RM_BLEND rendering mode
  48. {
  49. void scheduleDrawBlend(C VecD &pos); // call this method inside RM_PREPARE rendering mode to schedule automatic call to 'drawBlend' method, 'pos'=object position (used for correct depth-sorting calculation)
  50. virtual void drawBlend() {} // extend this method to draw custom graphics for RM_BLEND rendering mode, this method will be automatically called inside RM_BLEND rendering mode if 'scheduleDrawBlend' was called previously
  51. };
  52. /******************************************************************************/
  53. void DrawLaser(C Color &color, C Color &middle_color, Flt middle_exponent, Flt radius, Bool sharp_ending, C MemPtr<Vec> &points); // draw laser effect using active matrix onto the screen, 'points'=array of laser points, this should be called in RM_SOLID and RM_AMBIENT modes
  54. /******************************************************************************/
  55. void DrawVelocityBlur(Flt power, C Ball &ball); // draw velocity blur to the screen, this is used for blurring explosion effects when using motion blur, this can be called only in RM_BLEND mode
  56. /******************************************************************************/