phystexproject.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/phystexproject.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 1/11/02 7:06p $*
  31. * *
  32. * $Revision:: 14 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * PhysTexProjectClass::PhysTexProjectClass -- Constructor *
  37. * PhysTexProjectClass::~PhysTexProjectClass -- Destructor *
  38. * PhysTexProjectClass::Compute_Perspective_Projection -- compute projection of a Phys objec *
  39. * PhysTexProjectClass::Compute_Ortho_Projection -- Compute projection of a Phys object *
  40. * PhysTexProjectClass::Compute_Texture -- Render the given Phys object to texture *
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #include "phystexproject.h"
  43. #include "pscene.h"
  44. #include "phys.h"
  45. #include "rinfo.h"
  46. #include "vertmaterial.h"
  47. #include "lightenvironment.h"
  48. /***********************************************************************************************
  49. * PhysTexProjectClass::PhysTexProjectClass -- Constructor *
  50. * *
  51. * INPUT: *
  52. * *
  53. * OUTPUT: *
  54. * *
  55. * WARNINGS: *
  56. * *
  57. * HISTORY: *
  58. * 3/30/2000 gth : Created. *
  59. *=============================================================================================*/
  60. PhysTexProjectClass::PhysTexProjectClass(void)
  61. {
  62. }
  63. /***********************************************************************************************
  64. * PhysTexProjectClass::~PhysTexProjectClass -- Destructor *
  65. * *
  66. * INPUT: *
  67. * *
  68. * OUTPUT: *
  69. * *
  70. * WARNINGS: *
  71. * *
  72. * HISTORY: *
  73. * 3/30/2000 gth : Created. *
  74. *=============================================================================================*/
  75. PhysTexProjectClass::~PhysTexProjectClass(void)
  76. {
  77. }
  78. /***********************************************************************************************
  79. * PhysTexProjectClass::Compute_Perspective_Projection -- compute projection of a Phys object *
  80. * *
  81. * INPUT: *
  82. * *
  83. * OUTPUT: *
  84. * *
  85. * WARNINGS: *
  86. * *
  87. * HISTORY: *
  88. * 3/30/2000 gth : Created. *
  89. *=============================================================================================*/
  90. bool PhysTexProjectClass::Compute_Perspective_Projection
  91. (
  92. PhysClass * obj,
  93. const Vector3 & lightpos,
  94. float nearz,
  95. float farz
  96. )
  97. {
  98. RenderObjClass * model = obj->Peek_Model();
  99. if (model == NULL) {
  100. WWDEBUG_SAY(("Attempting to generate projection for a NULL model\r\n"));
  101. return false;
  102. }
  103. AABoxClass box;
  104. model->Get_Obj_Space_Bounding_Box(box);
  105. const Matrix3D & tm = model->Get_Transform();
  106. return TexProjectClass::Compute_Perspective_Projection(box,tm,lightpos,nearz,farz);
  107. }
  108. /***********************************************************************************************
  109. * PhysTexProjectClass::Compute_Ortho_Projection -- Compute projection of a Phys object *
  110. * *
  111. * INPUT: *
  112. * *
  113. * OUTPUT: *
  114. * *
  115. * WARNINGS: *
  116. * *
  117. * HISTORY: *
  118. * 3/30/2000 gth : Created. *
  119. *=============================================================================================*/
  120. bool PhysTexProjectClass::Compute_Ortho_Projection
  121. (
  122. PhysClass * obj,
  123. const Vector3 & lightdir,
  124. float nearz,
  125. float farz
  126. )
  127. {
  128. RenderObjClass * model = obj->Peek_Model();
  129. if (model == NULL) {
  130. WWDEBUG_SAY(("Attempting to generate projection for a NULL model\r\n"));
  131. return false;
  132. }
  133. AABoxClass box;
  134. model->Get_Obj_Space_Bounding_Box(box);
  135. const Matrix3D & tm = model->Get_Transform();
  136. return TexProjectClass::Compute_Ortho_Projection(box,tm,lightdir,nearz,farz);
  137. }
  138. /***********************************************************************************************
  139. * PhysTexProjectClass::Compute_Texture -- Render the given Phys object to texture *
  140. * *
  141. * INPUT: *
  142. * *
  143. * OUTPUT: *
  144. * *
  145. * WARNINGS: *
  146. * *
  147. * HISTORY: *
  148. * 3/30/2000 gth : Created. *
  149. *=============================================================================================*/
  150. bool PhysTexProjectClass::Compute_Texture(PhysClass * obj,bool additive_projection)
  151. {
  152. /*
  153. ** Grab the shadow render context and the render object
  154. */
  155. RenderObjClass * model = obj->Peek_Model();
  156. if (model == NULL) {
  157. return false;
  158. }
  159. int tex_size = Get_Texture_Size();
  160. SpecialRenderInfoClass * context = PhysicsSceneClass::Get_Instance()->Get_Shadow_Render_Context(tex_size,tex_size);
  161. if (context == NULL) {
  162. return false;
  163. }
  164. /*
  165. ** Set up the render context
  166. */
  167. bool pushed_mtls = false;
  168. LightEnvironmentClass lenv;
  169. if (!additive_projection) {
  170. lenv.Reset(Vector3(0,0,0),Vector3(0,0,0)); // light env that makes everything black
  171. MaterialPassClass * shadow_mtl = PhysicsSceneClass::Get_Instance()->Get_Shadow_Material_Pass();
  172. if (shadow_mtl) {
  173. pushed_mtls = true;
  174. context->Push_Material_Pass(shadow_mtl);
  175. context->Push_Override_Flags((RenderInfoClass::RINFO_OVERRIDE_FLAGS)(RenderInfoClass::RINFO_OVERRIDE_ADDITIONAL_PASSES_ONLY | RenderInfoClass::RINFO_OVERRIDE_SHADOW_RENDERING));
  176. REF_PTR_RELEASE(shadow_mtl);
  177. }
  178. } else {
  179. lenv.Reset(Vector3(0,0,0),Vector3(1,1,1)); // light env of pure ambient
  180. }
  181. context->light_environment = &lenv;
  182. /*
  183. ** Pass on to our parent class function
  184. */
  185. bool success = TexProjectClass::Compute_Texture(model,context);
  186. /*
  187. ** Cleanup
  188. */
  189. if (pushed_mtls) {
  190. context->Pop_Override_Flags();
  191. context->Pop_Material_Pass();
  192. }
  193. return success;
  194. }