texproject.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/texproject.h $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 9/19/01 3:30p $*
  31. * *
  32. * $Revision:: 7 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if defined(_MSC_VER)
  38. #pragma once
  39. #endif
  40. #ifndef TEXPROJECT_H
  41. #define TEXPROJECT_H
  42. #include "always.h"
  43. #include "matrix3d.h"
  44. #include "matrix4.h"
  45. #include "obbox.h"
  46. #include "matpass.h"
  47. #include "matrixmapper.h"
  48. #include "cullsys.h"
  49. #include "multilist.h"
  50. #include "projector.h"
  51. class SpecialRenderInfoClass;
  52. class RenderObjClass;
  53. class MaterialPassClass;
  54. class SurfaceClass;
  55. /**
  56. ** TexProjectClass
  57. ** This class is used to project textures onto object in the world. It contains
  58. ** a pointer to the texture to be projected, a bounding volume for the projection,
  59. ** and a material pass which can perform the projection.
  60. **
  61. ** Design Goals:
  62. ** - Texture Projectors should be easy to place in the world and move around.
  63. ** solution: Store the bounding volume and any other parameters in a coordinate
  64. ** system local to the projector. Update the world-space cache whenever needed.
  65. ** The automatically generated shadow texture projectors are a special case subset
  66. ** of the general texture projection code. For this reason, a local bounding
  67. ** volume will be stored and its world-space equivalent will be updated whenever
  68. ** needed.
  69. **
  70. ** - Texture projectors need to be compatible with the culling systems.
  71. ** solution: inherit the Cullable interface.
  72. **
  73. ** - Texture projectors need to be quickly pulled in and out of many lists during
  74. ** the rendering process.
  75. ** solution: list system similar to PhysListClass? I really need to templatize this.
  76. ** - done: MultiListClass!
  77. **
  78. ** - Dynamic Texture projectors need to be updated in stages. Update/recompute only the
  79. ** bounding volume first, then defer computing the actual texture until it is
  80. ** determined that the volume falls into the frustum and is applied to at least one
  81. ** object.
  82. ** solution: Code the bounding volume/projection paramter generation separate from
  83. ** the texture generation code. A derived texture projection object. Let texture
  84. ** projectors know about the object they are projecting so that they can have that
  85. ** object rendered from the desired viewpoint. Need a 'Dirty' flag and a pointer to
  86. ** a 'parent' object. Perhaps separate this code into a ShadowProjectClass since shadows
  87. ** are the only case I can think of that need the ability to re-render their 'parent'
  88. ** object. Everything else should be a static texture-map either generated 'artistically'
  89. ** or generated off-line.
  90. **
  91. */
  92. class TexProjectClass : public ProjectorClass, public CullableClass, public MultiListObjectClass
  93. {
  94. public:
  95. TexProjectClass(void);
  96. virtual ~TexProjectClass(void);
  97. /*
  98. ** Material settings
  99. */
  100. void Set_Texture_Size(int size);
  101. int Get_Texture_Size(void);
  102. void Init_Multiplicative(void);
  103. void Init_Additive(void);
  104. void Set_Intensity(float intensity,bool immediate = false); // 1.0 = on 100%, 0.0 = 'off'
  105. float Get_Intensity(void);
  106. bool Is_Intensity_Zero(void);
  107. void Set_Attenuation(float attenuation); // 1.0 = on, 0.0 = off
  108. float Get_Attenuation(void);
  109. void Enable_Attenuation(bool onoff);
  110. bool Is_Attenuation_Enabled(void);
  111. MaterialPassClass * Peek_Material_Pass(void);
  112. /*
  113. ** Options
  114. */
  115. void Enable_Affect_Dynamic_Objects(bool onoff) { Set_Flag(AFFECT_DYNAMIC_OBJS,onoff); }
  116. bool Is_Affect_Dynamic_Objects_Enabled(void) { return Get_Flag(AFFECT_DYNAMIC_OBJS); }
  117. void Enable_Affect_Static_Objects(bool onoff) { Set_Flag(AFFECT_STATIC_OBJS,onoff); }
  118. bool Is_Affect_Static_Objects_Enabled(void) { return Get_Flag(AFFECT_STATIC_OBJS); }
  119. void Enable_Depth_Gradient(bool onoff);
  120. bool Is_Depth_Gradient_Enabled(bool onoff);
  121. /*
  122. ** Manual initialization of a TexProjectClass
  123. ** 1 - call ProjectorClass::Set_Transform
  124. ** 2 - call Set_Projection_Perspective -or- Set_Projection_Ortho
  125. ** 3 - call Set_Texture.
  126. */
  127. virtual void Set_Perspective_Projection(float hfov,float vfov,float znear,float zfar);
  128. virtual void Set_Ortho_Projection(float xmin,float xmax,float ymin,float ymax,float znear,float zfar);
  129. void Set_Texture(TextureClass * texture);
  130. TextureClass * Get_Texture(void) const;
  131. TextureClass * Peek_Texture(void) const;
  132. /*
  133. ** Automatic initialization of a TexProjectClass.
  134. ** First set up your projection parameters, give the projector a render target, then call Compute_Texture
  135. */
  136. bool Compute_Perspective_Projection(RenderObjClass * obj,const Vector3 & lightpos,float znear=-1.0f,float zfar=-1.0f);
  137. bool Compute_Perspective_Projection(const AABoxClass & obj_box,const Matrix3D & tm,const Vector3 & lightpos,float znear=-1.0f,float zfar=-1.0f);
  138. bool Compute_Ortho_Projection(RenderObjClass * obj,const Vector3 & lightdir,float znear=-1.0f,float zfar=-1.0f);
  139. bool Compute_Ortho_Projection(const AABoxClass & obj_box,const Matrix3D & tm,const Vector3 & lightdir,float znear=-1.0f,float zfar=-1.0f);
  140. bool Needs_Render_Target(void);
  141. void Set_Render_Target(TextureClass * render_target);
  142. TextureClass * Peek_Render_Target(void);
  143. bool Compute_Texture(RenderObjClass * model,SpecialRenderInfoClass * context);
  144. /*
  145. ** Prep for rendering, called by the scene prior to usage.
  146. */
  147. virtual void Pre_Render_Update(const Matrix3D & camera);
  148. /*
  149. ** virtual interface for getting the pointer of the object that generated this shadow.
  150. ** defaults to returning NULL. This is implemented by some derived classes and used by
  151. ** the system to prevent a projection from being applied to the object that generated
  152. ** the projection...
  153. ** (gth) feels kludgy, this got a little messy when I moved this code into WW3D from WWPhys
  154. */
  155. virtual void * Get_Projection_Object_ID(void) const { return NULL; }
  156. protected:
  157. void Set_Flag(uint32 flag,bool onoff);
  158. bool Get_Flag(uint32 flag) const;
  159. virtual void Update_WS_Bounding_Volume(void);
  160. void Configure_Camera(CameraClass & camera);
  161. enum FlagsType
  162. {
  163. PERSPECTIVE = 0x00000001, // PERSPECTIVE or ORTHO
  164. ADDITIVE = 0x00000002, // ADDITIVE or MULTIPLICATIVE
  165. TEXTURE_DIRTY = 0x00000004, // used by derived DynTexProjectClass
  166. VOLATILE = 0x00000008, // this is a volatile texture.
  167. ATTENUATE = 0x00000010, // this projector should be attenuated based on distance to viewer
  168. AFFECT_DYNAMIC_OBJS = 0x00000020, // this projector affects dynamic objects
  169. AFFECT_STATIC_OBJS = 0x00000040, // this projector affects static objects
  170. USE_DEPTH_GRADIENT = 0x00000080, // fade the projection as a function of depth
  171. HAS_RENDER_TARGET = 0x00000100, // the texture we have can be a render target
  172. SIZE_MASK = 0xFFF00000, // desired texture size stored in upper 3 nibbles
  173. SIZE_SHIFT = 20,
  174. DEFAULT_FLAGS = ATTENUATE | AFFECT_DYNAMIC_OBJS | AFFECT_STATIC_OBJS
  175. };
  176. uint32 Flags;
  177. /*
  178. ** Intensity Controls
  179. */
  180. float DesiredIntensity; // last input desired intensity.
  181. float Intensity; // basic shadow intensity. value between 0 and 1
  182. float Attenuation; // attenuation factor based on distance from camera. value between 0 and 1
  183. /*
  184. ** Material pass to be added to any object that intersects the volume
  185. */
  186. MaterialPassClass * MaterialPass;
  187. MatrixMapperClass * Mapper1;
  188. TextureClass * RenderTarget;
  189. /*
  190. ** I have to remember all of these values so that I can properly initialize a CameraClass
  191. ** when we do render-to-texture. Some day we will merge CameraClass and ProjectorClass.
  192. */
  193. float HFov; // horizontal fov (for perspective mode)
  194. float VFov; // vertical fov (for perspective mode)
  195. float XMin; // left x clip plane (for ortho)
  196. float XMax; // right x clip plane (for ortho)
  197. float YMin; // bottom y clip plane (for ortho)
  198. float YMax; // top y clip plane (for ortho)
  199. float ZNear,ZFar; // z clip planes (for both modes)
  200. };
  201. /*
  202. ** Texture Projector Lists
  203. */
  204. typedef RefMultiListClass<TexProjectClass> TexProjListClass;
  205. typedef RefMultiListIterator<TexProjectClass> TexProjListIterator;
  206. #endif