CCubeMapProcessor.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. //--------------------------------------------------------------------------------------
  2. //CCubeMapProcessor
  3. // Class for filtering and processing cubemaps
  4. //
  5. //
  6. //--------------------------------------------------------------------------------------
  7. // (C) 2005 ATI Research, Inc., All rights reserved.
  8. //--------------------------------------------------------------------------------------
  9. // Modified from original
  10. #pragma once
  11. #include <math.h>
  12. #include <stdio.h>
  13. #include <AzCore/std/parallel/thread.h>
  14. #include <AzCore/std/parallel/atomic.h>
  15. #include <AzCore/PlatformIncl.h>
  16. #include "VectorMacros.h"
  17. #include "CBBoxInt32.h"
  18. #include "CImageSurface.h"
  19. //has routines for saving .rgbe files
  20. #define CG_RGBE_SUPPORT
  21. #ifndef WCHAR // For non-windows platforms, for Windows-based platforms it will be defined through PlatformIncl.h
  22. #define WCHAR wchar_t
  23. #endif // WCHAR
  24. //used to index cube faces
  25. #define CP_FACE_X_POS 0
  26. #define CP_FACE_X_NEG 1
  27. #define CP_FACE_Y_POS 2
  28. #define CP_FACE_Y_NEG 3
  29. #define CP_FACE_Z_POS 4
  30. #define CP_FACE_Z_NEG 5
  31. //used to index image edges
  32. // NOTE.. the actual number corresponding to the edge is important
  33. // do not change these, or the code will break
  34. //
  35. // CP_EDGE_LEFT is u = 0
  36. // CP_EDGE_RIGHT is u = width-1
  37. // CP_EDGE_TOP is v = 0
  38. // CP_EDGE_BOTTOM is v = height-1
  39. #define CP_EDGE_LEFT 0
  40. #define CP_EDGE_RIGHT 1
  41. #define CP_EDGE_TOP 2
  42. #define CP_EDGE_BOTTOM 3
  43. //corners of CUBE map (P or N specifys if it corresponds to the
  44. // positive or negative direction each of X, Y, and Z
  45. #define CP_CORNER_NNN 0
  46. #define CP_CORNER_NNP 1
  47. #define CP_CORNER_NPN 2
  48. #define CP_CORNER_NPP 3
  49. #define CP_CORNER_PNN 4
  50. #define CP_CORNER_PNP 5
  51. #define CP_CORNER_PPN 6
  52. #define CP_CORNER_PPP 7
  53. //data types processed by cube map processor
  54. // note that UNORM data types use the full range
  55. // of the unsigned integer to represent the range [0, 1] inclusive
  56. // the float16 datatype is stored as D3Ds S10E5 representation
  57. #define CP_VAL_UNORM8 0
  58. #define CP_VAL_UNORM8_BGRA 1
  59. #define CP_VAL_UNORM16 10
  60. #define CP_VAL_FLOAT16 20
  61. #define CP_VAL_FLOAT32 30
  62. //return codes for thread execution
  63. // warning STILL_ACTIVE maps to 259, so the number 259 is reserved in this case
  64. // and should only be used for STILL_ACTIVE
  65. #define CP_THREAD_COMPLETED 0
  66. #define CP_THREAD_TERMINATED 15
  67. #define CP_THREAD_STILL_ACTIVE STILL_ACTIVE
  68. #define CP_MAX_PROGRESS_STRING 1024
  69. // Type of data used internally by cube map processor
  70. // just in case for any reason more preecision is needed,
  71. // this type can be changed down the road
  72. #define CP_ITYPE float
  73. // Filter type
  74. #define CP_FILTER_TYPE_DISC 0
  75. #define CP_FILTER_TYPE_CONE 1
  76. #define CP_FILTER_TYPE_COSINE 2
  77. #define CP_FILTER_TYPE_ANGULAR_GAUSSIAN 3
  78. #define CP_FILTER_TYPE_COSINE_POWER 4
  79. #define CP_FILTER_TYPE_GGX 5
  80. // Edge fixup type (how to perform smoothing near edge region)
  81. #define CP_FIXUP_NONE 0
  82. #define CP_FIXUP_PULL_LINEAR 1
  83. #define CP_FIXUP_PULL_HERMITE 2
  84. #define CP_FIXUP_AVERAGE_LINEAR 3
  85. #define CP_FIXUP_AVERAGE_HERMITE 4
  86. // Max potential cubemap size is limited to 65k (2^16 texels) on a side
  87. #define CP_MAX_MIPLEVELS 16
  88. //maximum number of threads running for cubemap processor is 2
  89. #define CP_MAX_FILTER_THREADS 2
  90. //initial number of filtering threads for cubemap processor
  91. #define CP_INITIAL_NUM_FILTER_THREADS 1
  92. //current status of cubemap processor
  93. #define CP_STATUS_READY 0
  94. #define CP_STATUS_PROCESSING 1
  95. #define CP_STATUS_FILTER_TERMINATED 2
  96. #define CP_STATUS_FILTER_COMPLETED 3
  97. #define CP_SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
  98. #define CP_SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } }
  99. namespace ImageProcessingAtom
  100. {
  101. //information about cube maps neighboring face after traversing
  102. // across an edge
  103. struct CPCubeMapNeighbor
  104. {
  105. uint8 m_Face; //index of neighboring face
  106. uint8 m_Edge; //edge in neighboring face that abuts this face
  107. };
  108. //--------------------------------------------------------------------------------------------------
  109. //structure used to store current progress of the filtering
  110. //--------------------------------------------------------------------------------------------------
  111. struct SFilterProgress
  112. {
  113. //status of current cube map processing
  114. int32 m_CurrentFace;
  115. int32 m_CurrentRow;
  116. int32 m_CurrentMipLevel;
  117. int32 m_StartFace;
  118. int32 m_EndFace;
  119. float m_FractionCompleted; //Approximate fraction of work completed for this thread
  120. };
  121. //--------------------------------------------------------------------------------------------------
  122. //structure used to pass filtering parameters for Thread 0
  123. //--------------------------------------------------------------------------------------------------
  124. struct SThreadOptionsThread0
  125. {
  126. class CCubeMapProcessor *m_cmProc;
  127. float m_BaseFilterAngle;
  128. float m_InitialMipAngle;
  129. float m_MipAnglePerLevelScale;
  130. float m_GlossScale;
  131. float m_GlossBias;
  132. int32 m_FilterType;
  133. int32 m_FixupType;
  134. int32 m_FixupWidth;
  135. int32 m_SampleCountGGX;
  136. bool m_bUseSolidAngle;
  137. };
  138. //--------------------------------------------------------------------------------------------------
  139. //structure used to pass filtering parameters to the process for Thread 1 (if used)
  140. //--------------------------------------------------------------------------------------------------
  141. struct SThreadOptionsThread1
  142. {
  143. class CCubeMapProcessor *m_cmProc;
  144. CImageSurface *m_SrcCubeMap;
  145. CImageSurface *m_DstCubeMap;
  146. float m_FilterConeAngle;
  147. int32 m_FilterType;
  148. bool m_bUseSolidAngle;
  149. int32 m_FaceIdxStart;
  150. int32 m_FaceIdxEnd;
  151. int32 m_ThreadIdx;
  152. };
  153. //--------------------------------------------------------------------------------------------------
  154. //Class to filter, perform edge fixup, and build a mip chain for a cubemap
  155. //--------------------------------------------------------------------------------------------------
  156. class CCubeMapProcessor
  157. {
  158. public:
  159. //cubemap processor status
  160. int32 m_Status;
  161. //information about threads actively processing the cubemap
  162. int32 m_NumFilterThreads;
  163. bool m_bThreadInitialized[CP_MAX_FILTER_THREADS];
  164. AZStd::thread m_ThreadHandle[CP_MAX_FILTER_THREADS];
  165. AZ::u32 m_ThreadID[CP_MAX_FILTER_THREADS];
  166. SFilterProgress m_ThreadProgress[CP_MAX_FILTER_THREADS];
  167. WCHAR m_ProgressString[CP_MAX_PROGRESS_STRING];
  168. //filtering parameters last used for filtering
  169. float m_BaseFilterAngle;
  170. float m_InitialMipAngle;
  171. float m_MipAnglePerLevelScale;
  172. int32 m_InputSize; //input cubemap size (e.g. face width and height of topmost mip level)
  173. int32 m_OutputSize; //output cubemap size (e.g. face width and height of topmost mip level)
  174. int32 m_NumMipLevels; //number of output mip levels
  175. int32 m_NumChannels; //number of channels in cube map processor
  176. CP_ITYPE *m_FilterLUT; //filter weight lookup table (scale dot product 0-1 range to index into it)
  177. int32 m_NumFilterLUTEntries; //number of filter lookup table entries
  178. CImageSurface m_NormCubeMap[6]; //normalizer cube map and solid angle lookup table
  179. CImageSurface m_InputSurface[CP_MAX_MIPLEVELS][6]; //input faces for all mip levels
  180. CImageSurface m_OutputSurface[CP_MAX_MIPLEVELS][6]; //output faces for all mip levels
  181. private:
  182. //==========================================================================================================
  183. //BuildNormalizerCubemap(int32 a_Size, CImageSurface *a_Surface );
  184. // Builds a normalizer cubemap of size a_Size. This routine deallocates the CImageSurfaces passed
  185. // into the the function and reallocates them with the correct size and 3 channels to store the
  186. // normalized vector for each texel.
  187. //
  188. // a_Size [in] size of normalizer cubemap
  189. // a_Surface [out] Pointer to array of 6 CImageSurfaces where normalizer cube faces will be stored
  190. //
  191. //==========================================================================================================
  192. void BuildNormalizerCubemap(int32 a_Size, CImageSurface *a_Surface);
  193. //==========================================================================================================
  194. //void BuildNormalizerSolidAngleCubemap(int32 a_Size, CImageSurface *a_Surface );
  195. // Builds a normalizer|solid angle cubemap of size a_Size. This routine deallocates the CImageSurfaces
  196. // passed into the the function and reallocates them with the correct size and 4 channels to store the
  197. // normalized vector, and solid angle for each texel.
  198. //
  199. // a_Size [in]
  200. // a_Surface [out] Pointer to array of 6 CImageSurfaces where normalizer cube faces will be stored
  201. //
  202. //==========================================================================================================
  203. void BuildNormalizerSolidAngleCubemap(int32 a_Size, CImageSurface *a_Surface);
  204. //==========================================================================================================
  205. //Clears filter extent bounding boxes for each face of the cubemap
  206. //
  207. // a_FilterExtents [in] Array of 6 bounding boxes (corresponding to the 6 cubemap faces) to clear
  208. //==========================================================================================================
  209. void ClearFilterExtents(CBBoxInt32 *a_FilterExtents);
  210. //==========================================================================================================
  211. //void DetermineFilterExtents(float *a_CenterTapDir, int32 a_SrcSize, int32 a_BBoxSize,
  212. // CBBoxInt32 *a_FilterExtents);
  213. //
  214. //Determines bounding boxes for each cube face for a single kernels angular extent
  215. // a_CenterTapDir [in] Vector of 3 float32s specifying the center tap direction
  216. // a_SrcSize [in] Source cubemap size (for the miplevel used as input to the filtering)
  217. // a_BBoxSize [in] Maximum length in texels of the bbox extent derived from the filtering
  218. // cone angle
  219. // a_FilterExtents [out] Array of 6 bounding boxes (corresponding to the 6 cubemap faces) to clear
  220. //==========================================================================================================
  221. void DetermineFilterExtents(float *a_CenterTapDir, int32 a_SrcSize, int32 a_BBoxSize, CBBoxInt32 *a_FilterExtents);
  222. //==========================================================================================================
  223. //void ProcessFilterExtents(float *a_CenterTapDir, float a_DotProdThresh, CBBoxInt32 *a_FilterExtents,
  224. // CImageSurface *a_NormCubeMap, CImageSurface *a_SrcCubeMap, CP_ITYPE *a_DstVal, uint32 a_FilterType,
  225. // bool a_bUseSolidAngle );
  226. //
  227. //Processes all the texels within the bounding boxes in order to accumulate all the weighted taps to
  228. // compute a single fitered texel value.
  229. //
  230. //a_CenterTapDir [in] Center tap directions
  231. //a_DotProdThresh [in] Threshhold on dot product between center tap and
  232. //a_FilterExtents [in] array of 6 bounding boxes describing rough filter extents for each face
  233. //a_NormCubeMap [in] normalizer|solid angle cubemap
  234. //a_SrcCubeMap [in] array of 6 faces comprising the miplevel of the source cubemap the filter is
  235. // generated from
  236. //a_DstVal [out] resulting filtered texel color
  237. //a_FilterType [in] filter type: Choose one of the following options: CP_FILTER_TYPE_DISC,
  238. // CP_FILTER_TYPE_CONE, CP_FILTER_TYPE_COSINE, CP_FILTER_TYPE_ANGULAR_GAUSSIAN
  239. //a_bUseSolidAngle [in] Set this to true in order to incorporate the solid angle subtended
  240. // each texel in the filter kernel in the filtering.
  241. //
  242. //==========================================================================================================
  243. void ProcessFilterExtents(float *a_CenterTapDir, float a_DotProdThresh, CBBoxInt32 *a_FilterExtents,
  244. CImageSurface *a_NormCubeMap, CImageSurface *a_SrcCubeMap, CP_ITYPE *a_DstVal, uint32 a_FilterType,
  245. bool a_bUseSolidAngle, float a_SpecularPower);
  246. //==========================================================================================================
  247. //void FixupCubeEdges(CImageSurface *a_CubeMap, int32 a_FixupType, int32 a_FixupWidth);
  248. //
  249. //Apply edge fixup to a cubemap mip level.
  250. //
  251. //a_CubeMap [in/out] Array of 6 images comprising cubemap miplevel to apply edge fixup to.
  252. //a_FixupType [in] Specifies the technique used for edge fixup. Choose one of the following,
  253. // CP_FIXUP_NONE, CP_FIXUP_PULL_LINEAR, CP_FIXUP_PULL_HERMITE, CP_FIXUP_AVERAGE_LINEAR,
  254. // CP_FIXUP_AVERAGE_HERMITE
  255. //a_FixupWidth [in] Fixup width in texels
  256. //
  257. //==========================================================================================================
  258. void FixupCubeEdges(CImageSurface *a_CubeMap, int32 a_FixupType, int32 a_FixupWidth);
  259. //==========================================================================================================
  260. //void BuildAngleWeightLUT(int32 a_NumFilterLUTEntries, int32 a_FilterType, float a_FilterAngle);
  261. //
  262. // Builds filter weight lookup table in order to quickly evaluate the weight of a particular texel
  263. // for the Cone and Angular Gaussian fiter types. This lookup table is quickly indexed using the
  264. // same dot product between the center tap and current texel that is used to determine whether a
  265. // texel is inside or outside the filtering kernel.
  266. //
  267. //a_NumFilterLUTEntries [in] Number of entries in filter weight lookup table
  268. //a_FilterType [in] Filter type
  269. //a_FilterAngle [in] Filtering half cone angle
  270. //==========================================================================================================
  271. void BuildAngleWeightLUT(int32 a_NumFilterLUTEntries, int32 a_FilterType, float a_FilterAngle);
  272. //==========================================================================================================
  273. //void PrecomputeFilterLookupTables(uint32 a_FilterType, int32 a_SrcCubeMapWidth, float a_FilterConeAngle);
  274. //
  275. // Builds the following lookup tables prior to filtering:
  276. // -normalizer cube map
  277. // -filter weight lookup table
  278. //
  279. //a_FilterType [in] Filter type
  280. //a_SrcCubeMapWidth [in] source cubemap size
  281. //a_FilterConeAngle [in] Filtering half cone angle
  282. //==========================================================================================================
  283. void PrecomputeFilterLookupTables(uint32 a_FilterType, int32 a_SrcCubeMapWidth, float a_FilterConeAngle);
  284. //==========================================================================================================
  285. //void EstimateFilterThreadProgress(SFilterProgress *a_FilterProgress);
  286. //
  287. // Estimates percentage complete for a filtering thread for the current tap that is being filtered
  288. //
  289. //a_FilterProgress [in/out] Information about the filtereing thread's current position, and range of faces
  290. // that it will process.
  291. //==========================================================================================================
  292. void EstimateFilterThreadProgress(SFilterProgress *a_FilterProgress);
  293. public:
  294. //==========================================================================================================
  295. //note that these functions are only public so that they can be called from within the global scope
  296. // from the thread starting point functions. These should not be called by any other functions external
  297. // to the class.
  298. //==========================================================================================================
  299. void FilterCubeMapMipChain(float a_BaseFilterAngle, float a_InitialMipAngle, float a_MipAnglePerLevelScale,
  300. int32 a_FilterType, int32 a_FixupType, int32 a_FixupWidth, bool a_bUseSolidAngle, float a_GlossScale, float a_GlossBias,
  301. int32 a_SampleCountGGX);
  302. void FilterCubeSurfaces(CImageSurface *a_SrcCubeMap, CImageSurface *a_DstCubeMap, float a_FilterConeAngle,
  303. int32 a_FilterType, bool a_bUseSolidAngle, int32 a_FaceIdxStart, int32 a_FaceIdxEnd, int32 aThreadIdx,
  304. float a_SpecularPower = 1.0f);
  305. void FilterCubeSurfacesGGX(int32 a_MipIdx, int32 a_SampleCount, int32 a_FaceIdxStart, int32 a_FaceIdxEnd, int32 aThreadIdx);
  306. public:
  307. CCubeMapProcessor(void);
  308. ~CCubeMapProcessor();
  309. //==========================================================================================================
  310. // void Init(int32 a_InputSize, int32 a_OutputSize, int32 a_NumMipLevels, int32 a_NumChannels);
  311. //
  312. // Initializes cube map processor class
  313. //
  314. // a_InputSize [in] Size of the input cubemap
  315. // a_OutputSize [in] Size of the input cubemap
  316. // a_NumMipLevels [in] Number of miplevels in the output cubemap
  317. // a_NumChannels [in] Number of color channels (internally) in the input and output cubemap
  318. //==========================================================================================================
  319. void Init(int32 a_InputSize, int32 a_OutputSize, int32 a_NumMipLevels, int32 a_NumChannels);
  320. //==========================================================================================================
  321. // void GetInputFaceData(int32 a_FaceIdx, int32 a_DstType, int32 a_DstNumChannels, int32 a_DstPitch,
  322. // void *a_DstDataPtr, float a_Scale, float a_Gamma);
  323. //
  324. // Copies image data from the input cube map into a destination image. These routine describe the output
  325. // image layout using a pitch and a pointer so that the image can be copied from a subrect of a locked
  326. // D3D surface easily. Note that when reading out the image data, the intensity scale is applied first,
  327. // and then degamma.
  328. //
  329. // a_FaceIdx [in] Index (0-5) of the input cubemap cube face to read the image data from.
  330. // a_DstType [in] Data type for the image data being copied out the input cube map.
  331. // choose one of the following: CP_VAL_UNORM8, CP_VAL_UNORM8_BGRA, CP_VAL_UNORM16
  332. // CP_VAL_FLOAT16, CP_VAL_FLOAT32.
  333. // a_DstNumChannels [in] Number of channels in the destination image.
  334. // a_DstPitch [in] Pitch in bytes of the destination image.
  335. // a_DstDataPtr [in] Pointer to the top-left pixel in the destination image.
  336. // a_Scale [in] Scale factor to apply to intensities.
  337. // a_Gamma [in] Degamma to apply to intensities.
  338. //
  339. //==========================================================================================================
  340. void GetInputFaceData(int32 a_FaceIdx, int32 a_MipIdx, int32 a_DstType, int32 a_DstNumChannels, int32 a_DstPitch,
  341. void *a_DstDataPtr, float a_Scale, float a_Gamma);
  342. //==========================================================================================================
  343. // void SetInputFaceData(int32 a_FaceIdx, int32 a_SrcType, int32 a_SrcNumChannels, int32 a_SrcPitch,
  344. // void *a_SrcDataPtr, float a_MaxClamp, float a_Scale, float a_Gamma );
  345. //
  346. // Copies image data from a source image into one of the faces in the input cubemap in the cubemap.
  347. // processor. These routines describe the output image layout using a pitch and a pointer so that the image
  348. // can be copied from a subrect of a locked D3D surface easily. Note that the clamping is applied first,
  349. // followed by the scale and then gamma.
  350. //
  351. // a_FaceIdx [in] Index (0-5) of the input cubemap cube face to write the image data into
  352. // a_SrcType [in] Data type for the image data being copied into the cube map processor.
  353. // choose one of the following: CP_VAL_UNORM8, CP_VAL_UNORM8_BGRA, CP_VAL_UNORM16
  354. // CP_VAL_FLOAT16, CP_VAL_FLOAT32.
  355. // a_SrcNumChannels [in] Number of channels in the source image.
  356. // a_SrcPitch [in] Pitch in bytes of the source image.
  357. // a_SrcDataPtr [in] Pointer to the top-left pixel in the source image.
  358. // a_MaxClamp [in] Max value to clamp the input intensity values to.
  359. // a_Degamma [in] Degamma to apply to input intensities.
  360. // a_Scale [in] Scale factor to apply to input intensities.
  361. //
  362. //==========================================================================================================
  363. void SetInputFaceData(int32 a_FaceIdx, int32 a_MipIdx, int32 a_SrcType, int32 a_SrcNumChannels, int32 a_SrcPitch,
  364. void *a_SrcDataPtr, float a_MaxClamp, float a_Degamma, float a_Scale);
  365. //==========================================================================================================
  366. // void GetOutputFaceData(int32 a_FaceIdx, int32 a_Level, int32 a_DstType, int32 a_DstNumChannels, int32 a_DstPitch,
  367. // void *a_DstDataPtr, float a_Scale, float a_Gamma );
  368. //
  369. // a_FaceIdx [in] Index (0-5) of the output cubemap cube face to read the image data from.
  370. // a_Level [in] Miplevel of the output cubemap to read from
  371. // a_DstType [in] Data type for the image data being copied out the input cube map.
  372. // choose one of the following: CP_VAL_UNORM8, CP_VAL_UNORM8_BGRA, CP_VAL_UNORM16
  373. // CP_VAL_FLOAT16, CP_VAL_FLOAT32
  374. // a_DstNumChannels [in] Number of channels in the destination image.
  375. // a_DstPitch [in] Pitch in bytes of the destination image.
  376. // a_DstDataPtr [in] Pointer to the top-left pixel in the destination image.
  377. // a_Scale [in] Scale factor to apply to intensities.
  378. // a_Gamma [in] Degamma to apply to intensities.
  379. //
  380. //==========================================================================================================
  381. void GetOutputFaceData(int32 a_FaceIdx, int32 a_Level, int32 a_DstType, int32 a_DstNumChannels, int32 a_DstPitch,
  382. void *a_DstDataPtr, float a_Scale, float a_Gamma);
  383. //==========================================================================================================
  384. //void InitiateFiltering(float a_BaseFilterAngle, float a_InitialMipAngle, float a_MipAnglePerLevelScale,
  385. // int32 a_FilterType, int32 a_FixupType, int32 a_FixupWidth, bool a_bUseSolidAngle );
  386. //
  387. // Starts filtering the cubemap.
  388. // If the number of filter threads is zero, the function does not return until the filtering is complete
  389. // If the number of filter threads is non-zero, a filtering thread (or multiple threads) are started and
  390. // the function returns immediately, with the threads running in the background.
  391. //
  392. // The cube map filtereing is specified using a number of parameters:
  393. // Filtering per miplevel is specified using 2D cone angle (in degrees) that
  394. // indicates the region of the hemisphere to filter over for each tap.
  395. //
  396. // Note that the top mip level is also a filtered version of the original input images
  397. // as well in order to create mip chains for diffuse environment illumination.
  398. // The cone angle for the top level is specified by a_BaseAngle. This can be used to
  399. // generate mipchains used to store the results of preintegration across the hemisphere.
  400. //
  401. // The angle for the subsequent levels of the mip chain are specified by their parents
  402. // filtering angle and a per-level scale and bias
  403. // newAngle = oldAngle * a_MipAnglePerLevelScale;
  404. //
  405. // a_BaseFilterAngle [in] Base filter angle
  406. // a_InitialMipAngle [in] Mip angle used to generate the next level of the mip chain from the base level
  407. // a_MipAnglePerLevelScale [in] Scale factor to iteratively apply to the filtering angle to filter subsequent
  408. // mip-levels.
  409. // a_FilterType [in] Specifies the filtering type for angular extent filtering. Choose one of the
  410. // following options: CP_FILTER_TYPE_DISC, CP_FILTER_TYPE_CONE,
  411. // CP_FILTER_TYPE_COSINE, CP_FILTER_TYPE_ANGULAR_GAUSSIAN
  412. // a_FixupType [in] Specifies the technique used for edge fixup. Choose one of the following,
  413. // CP_FIXUP_NONE, CP_FIXUP_PULL_LINEAR, CP_FIXUP_PULL_HERMITE,
  414. // CP_FIXUP_AVERAGE_LINEAR, CP_FIXUP_AVERAGE_HERMITE
  415. // a_FixupWidth [in] Width in texels of the fixup region.
  416. // a_bUseSolidAngle [in] Set this to true in order to incorporate the solid angle subtended
  417. // each texel in the filter kernel in the filtering.
  418. //==========================================================================================================
  419. void InitiateFiltering(float a_BaseFilterAngle, float a_InitialMipAngle, float a_MipAnglePerLevelScale,
  420. int32 a_FilterType, int32 a_FixupType, int32 a_FixupWidth, bool a_bUseSolidAngle,
  421. float a_GlossScale, float a_GlossBias, int32 a_SampleCountGGX);
  422. //==========================================================================================================
  423. // void WriteMipLevelIntoAlpha(void)
  424. //
  425. // Encodes the miplevel in the alpha channel of the output cubemap.
  426. // The miplevel is encoded as (miplevel * 16.0f / 255.0f) so that the miplevel has an exact encoding in an
  427. // 8-bit or 16-bit UNORM representation.
  428. //
  429. //==========================================================================================================
  430. void WriteMipLevelIntoAlpha(void);
  431. //==========================================================================================================
  432. // Horizontally flips all the faces in the input cubemap
  433. //
  434. //==========================================================================================================
  435. void FlipInputCubemapFaces(void);
  436. //==========================================================================================================
  437. // Horizontally flips all the faces in the output cubemap
  438. //
  439. //==========================================================================================================
  440. void FlipOutputCubemapFaces(void);
  441. //==========================================================================================================
  442. // Allows for in-place color channel swapping of the input cubemap. This routine can be useful for
  443. // converting RGBA format data to BGRA format data.
  444. //
  445. // a_Channel0Src [in] Index of the color channel used as the source for the new channel 0
  446. // a_Channel1Src [in] Index of the color channel used as the source for the new channel 1
  447. // a_Channel2Src [in] Index of the color channel used as the source for the new channel 0
  448. // a_Channel3Src [in] Index of the color channel used as the source for the new channel 1
  449. //
  450. //==========================================================================================================
  451. void ChannelSwapInputFaceData(int32 a_Channel0Src, int32 a_Channel1Src, int32 a_Channel2Src, int32 a_Channel3Src);
  452. //==========================================================================================================
  453. // Allows for in-place color channel swapping of the output cubemap. This routine can be useful for
  454. // converting RGBA format data to BGRA format data.
  455. //
  456. // a_Channel0Src [in] Index of the color channel used as the source for the new channel 0
  457. // a_Channel1Src [in] Index of the color channel used as the source for the new channel 1
  458. // a_Channel2Src [in] Index of the color channel used as the source for the new channel 0
  459. // a_Channel3Src [in] Index of the color channel used as the source for the new channel 1
  460. //==========================================================================================================
  461. void ChannelSwapOutputFaceData(int32 a_Channel0Src, int32 a_Channel1Src, int32 a_Channel2Src, int32 a_Channel3Src);
  462. //==========================================================================================================
  463. // Resets the current cubemap processor, and deallocates the input and output cubemaps.
  464. //
  465. // This function is automatically called by destructor.
  466. //==========================================================================================================
  467. void Clear(void);
  468. //==========================================================================================================
  469. // Terminates any active filtering threads. This stops the filtering of the current cubemap.
  470. //
  471. //==========================================================================================================
  472. void TerminateActiveThreads(void);
  473. //==========================================================================================================
  474. // Gets the current filtering progress string
  475. //
  476. //==========================================================================================================
  477. WCHAR *GetFilterProgressString(void);
  478. //==========================================================================================================
  479. // Checks to see if either of the filtering threads is active
  480. //
  481. //==========================================================================================================
  482. bool IsFilterThreadActive(uint32 a_ThreadIdx);
  483. //==========================================================================================================
  484. // Gets the current status of the cubemap processing threads. The possible return values and their
  485. // associated meanings are:
  486. //
  487. // CP_STATUS_READY: The cubemap processor is currently ready to change settings, and to load a
  488. // new input cubemap.
  489. // CP_STATUS_PROCESSING: The cubemap processor is currently filtering a cubemap
  490. // CP_STATUS_FILTER_TERMINATED: The cubemap processor was terminated before the filtering was completed.
  491. // CP_STATUS_FILTER_COMPLETED: The cubemap processor fully completed filtering the cubemap.
  492. //
  493. //==========================================================================================================
  494. int32 GetStatus(void);
  495. //==========================================================================================================
  496. // This signifies to the cubemap processor that you have acknowledged a
  497. // CP_STATUS_FILTER_TERMINATED or CP_STATUS_FILTER_COMPLETED status code, and would like to
  498. // reset the cubemap processor to CP_STATUS_READY.
  499. //==========================================================================================================
  500. void RefreshStatus(void);
  501. AZStd::atomic_bool m_shutdownWorkerThreadSignal; ///< Signals the worker threads to stop.
  502. };
  503. } // namespace ImageProcessingAtom