[1808] | 1 | /**
|
---|
| 2 | @author Barsi Attila
|
---|
| 3 | @copyright BMGE Department of Control Engineering and Informatics
|
---|
| 4 | @brief D3D Radiosity algorithm wrapper class.
|
---|
| 5 | */
|
---|
| 6 | #pragma once
|
---|
| 7 | #ifndef RADIOSITYALGORITHM_H
|
---|
| 8 | #define RADIOSITYALGORITHM_H
|
---|
| 9 |
|
---|
| 10 | //#define DEBUG_SHADER
|
---|
| 11 |
|
---|
| 12 | class RadiosityAlgorithm{
|
---|
| 13 | public:
|
---|
| 14 | /**
|
---|
| 15 | Constructor.
|
---|
| 16 | */
|
---|
| 17 | RadiosityAlgorithm(UINT textureWidth,UINT textureHeight,UINT mipMapLevels,_D3DFORMAT vismapFormat,_D3DFORMAT iterationVismapFormat,_D3DFORMAT renderTextureFormat,_D3DFORMAT mipmapFormat,_D3DFORMAT depthStencilFormat);
|
---|
| 18 | /**
|
---|
| 19 | Destructor.
|
---|
| 20 | */
|
---|
| 21 | ~RadiosityAlgorithm();
|
---|
| 22 | /**
|
---|
| 23 | Initializes objects.
|
---|
| 24 | @param The current direct3d device.
|
---|
| 25 | @return The error code.
|
---|
| 26 | */
|
---|
| 27 | HRESULT initObjects(LPDIRECT3DDEVICE9 d3dDevice);
|
---|
| 28 | /**
|
---|
| 29 | Deletes objects.
|
---|
| 30 | @return The error code.
|
---|
| 31 | */
|
---|
| 32 | HRESULT deleteObjects();
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | Does the radiosity averaging pass.
|
---|
| 36 | @param doDebugPicture If true, saves a debug picture.
|
---|
| 37 | @param fileName The fileName to save the picture to.
|
---|
| 38 | @param niteration The current iteration count.
|
---|
| 39 | @return The error code.
|
---|
| 40 | */
|
---|
| 41 |
|
---|
| 42 | HRESULT doRadiosityAveragingPass(bool doDebugPicture,TCHAR* fileName,UINT niteration);
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | Renders the emission to the texture atlas.
|
---|
| 46 | @param doDebugPicture If true, saves a debug picture.
|
---|
| 47 | @param fileName The fileName to save the picture to.
|
---|
| 48 | @return The error code.
|
---|
| 49 | */
|
---|
| 50 |
|
---|
| 51 | HRESULT doEmissionMapPass(bool doDebugPicture,TCHAR* fileName);
|
---|
| 52 |
|
---|
| 53 | /**
|
---|
| 54 | Renders the original visibility map to the texture atlas.
|
---|
| 55 | @param doDebugPicture If true, saves a debug picture.
|
---|
| 56 | @param fileName The fileName to save the picture to.
|
---|
| 57 | @return The error code.
|
---|
| 58 | */
|
---|
| 59 |
|
---|
| 60 | HRESULT doOriginalVisibilityMapPass(bool doDebugPicture,TCHAR* fileName);
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
| 63 | Iterates the solution for a given number of times.
|
---|
| 64 | @param niterations The number of iterations to compute.
|
---|
| 65 | @param iterationToSave The iteration to save.
|
---|
| 66 | @return The error code.
|
---|
| 67 | */
|
---|
| 68 |
|
---|
| 69 | HRESULT iterate(UINT niterations,UINT iterationToSave);
|
---|
| 70 | /**
|
---|
| 71 | Renders all mipmap levels of the radiosity texture.
|
---|
| 72 | @param niteration The current iteration count.
|
---|
| 73 | @return The error code.
|
---|
| 74 | */
|
---|
| 75 | HRESULT createRadiosityMipMap(UINT niteration);
|
---|
| 76 | /**
|
---|
| 77 | Chooses a shooter based on the current radiosity map and iteration count.
|
---|
| 78 | @param niteration The current iteration count.
|
---|
| 79 | @return The error code.
|
---|
| 80 | */
|
---|
| 81 | HRESULT chooseShooter(UINT iterations);
|
---|
| 82 | /**
|
---|
| 83 | Does the per iteration visibility map from the shooter. Visibility is calculated per hemicube side.
|
---|
| 84 | @param doDebugPicture If true, saves a debug picture.
|
---|
| 85 | @param fileName The fileName to save the picture to.
|
---|
| 86 | @param center Center of the camera.
|
---|
| 87 | @param dir Direction of the camera.
|
---|
| 88 | @param up Up vector of the camera.
|
---|
| 89 | @param fullscreen Render fullscreen or half screen (on hemicube sides.)
|
---|
| 90 | @return The error code.
|
---|
| 91 | */
|
---|
| 92 | HRESULT doIterationVisibilityMapPass(bool doDebugPicture,TCHAR* fileName,D3DXVECTOR3 center,D3DXVECTOR3 dir,D3DXVECTOR3 up,bool fullScreen);
|
---|
| 93 | /**
|
---|
| 94 | Renders the radiosity map.
|
---|
| 95 | @param niteration The current iteration count.
|
---|
| 96 | @param doDebugPicture If true, saves a debug picture.
|
---|
| 97 | @param fileName The fileName to save the picture to.
|
---|
| 98 | @return The error code.
|
---|
| 99 | */
|
---|
| 100 | HRESULT doRadiosityMapPass(UINT iterations,bool doDebugPicture,TCHAR* fileName);
|
---|
| 101 | /**
|
---|
| 102 | Avarages the actual radiosity map.
|
---|
| 103 | @param iterations The number of iterations computed in iterate().
|
---|
| 104 | @param doDebugPicture If true, saves a debug picture.
|
---|
| 105 | @param fileName The fileName to save the picture to.
|
---|
| 106 | @return The error code.
|
---|
| 107 | */
|
---|
| 108 | HRESULT doRadiosityActualAveragingPass(UINT iterations,bool doDebugPicture,TCHAR* fileName);
|
---|
| 109 | /**
|
---|
| 110 | Renders the final picture.
|
---|
| 111 | @param doDebugPicture If true, saves a debug picture.
|
---|
| 112 | @param fileName The fileName to save the picture to.
|
---|
| 113 | @return The error code.
|
---|
| 114 | */
|
---|
| 115 | HRESULT doFinalPicturePass(bool doDebugPicture,TCHAR* fileName);
|
---|
| 116 | /**
|
---|
| 117 | Initializes the actual radiance map.
|
---|
| 118 | @return The error code.
|
---|
| 119 | */
|
---|
| 120 | HRESULT initActualRadianceMap();
|
---|
| 121 | /**
|
---|
| 122 | Initializes the BRDF and Specular map.
|
---|
| 123 | @return The error code.
|
---|
| 124 | */
|
---|
| 125 | HRESULT initBRDFAndSpecularMap();
|
---|
| 126 | /**
|
---|
| 127 | Moves the objects to a given location.
|
---|
| 128 | @param x The coordinate x.
|
---|
| 129 | @param y The coordinate y.
|
---|
| 130 | @param z The coordinate z.
|
---|
| 131 | @return The error code.
|
---|
| 132 | */
|
---|
| 133 | HRESULT moveObjects(float x,float y,float z);
|
---|
| 134 | /**
|
---|
| 135 | Moves the camera (View matrix) to a given location. Up is calculated from eye and lookat.
|
---|
| 136 | @param eyeX The X coordinate of the eye vector.
|
---|
| 137 | @param eyeY The Y coordinate of the eye vector.
|
---|
| 138 | @param eyeZ The Z coordinate of the eye vector.
|
---|
| 139 | @param lookAtX The X coordinate of the look at vector.
|
---|
| 140 | @param lookAtY The Y coordinate of the look at vector.
|
---|
| 141 | @param lookAtZ The Z coordinate of the look at vector.
|
---|
| 142 | @return The error code.
|
---|
| 143 | */
|
---|
| 144 | HRESULT moveCamera(float eyeX,float eyeY,float eyeZ,float lookAtX,float lookAtY,float lookAtZ);
|
---|
| 145 |
|
---|
| 146 | private:
|
---|
| 147 | /**
|
---|
| 148 | Pointer to the direct3d device.
|
---|
| 149 | */
|
---|
| 150 | LPDIRECT3DDEVICE9 d3dDevice;
|
---|
| 151 |
|
---|
| 152 | //ofstream* errLogger;
|
---|
| 153 | /**
|
---|
| 154 | The error code.
|
---|
| 155 | */
|
---|
| 156 | HRESULT hr;
|
---|
| 157 | /**
|
---|
| 158 | The full screen quad vertex buffer.
|
---|
| 159 | */
|
---|
| 160 | LPDIRECT3DVERTEXBUFFER9 pQuadVB;
|
---|
| 161 | /**
|
---|
| 162 | The on point vertex buffer.
|
---|
| 163 | */
|
---|
| 164 | LPDIRECT3DVERTEXBUFFER9 pPointVB;
|
---|
| 165 | /**
|
---|
| 166 | The shooter disc.
|
---|
| 167 | */
|
---|
| 168 | float shooterDisc;
|
---|
| 169 | /**
|
---|
| 170 | The py parameter of the shader.
|
---|
| 171 | */
|
---|
| 172 | float py;
|
---|
| 173 | /**
|
---|
| 174 | The time before the start of the rendering.
|
---|
| 175 | */
|
---|
| 176 | DWORD timeBefore;
|
---|
| 177 | /**
|
---|
| 178 | The time after the completion of the rendering.
|
---|
| 179 | */
|
---|
| 180 | DWORD timeAfter;
|
---|
| 181 |
|
---|
| 182 | //Texture declaration.
|
---|
| 183 |
|
---|
| 184 | /**
|
---|
| 185 | The original visibility texture.
|
---|
| 186 | */
|
---|
| 187 | LPDIRECT3DTEXTURE9 pOrigVisibilityTexture;
|
---|
| 188 | /**
|
---|
| 189 | The iteration visibility texture.
|
---|
| 190 | */
|
---|
| 191 | LPDIRECT3DTEXTURE9 pIterationVisibilityTexture;
|
---|
| 192 | /**
|
---|
| 193 | The radiosity texture.
|
---|
| 194 | */
|
---|
| 195 | LPDIRECT3DTEXTURE9 pRadiosityTexture;
|
---|
| 196 | /**
|
---|
| 197 | The radiosity texture for swapping textures.
|
---|
| 198 | */
|
---|
| 199 | LPDIRECT3DTEXTURE9 pRadiosityTexture2;
|
---|
| 200 | /**
|
---|
| 201 | The texture for accumulated actual radiance.
|
---|
| 202 | */
|
---|
| 203 | LPDIRECT3DTEXTURE9 pActualRadianceTexture;
|
---|
| 204 |
|
---|
| 205 |
|
---|
| 206 | /**
|
---|
| 207 | An array for the radiosity mipmap textures.
|
---|
| 208 | */
|
---|
| 209 | LPDIRECT3DTEXTURE9* mipmapTexturesArray;
|
---|
| 210 | /**
|
---|
| 211 | The texture for selecting the shooter.
|
---|
| 212 | */
|
---|
| 213 | LPDIRECT3DTEXTURE9 shootTexture;
|
---|
| 214 | /**
|
---|
| 215 | The radiosity map copy texture.
|
---|
| 216 | */
|
---|
| 217 | LPDIRECT3DTEXTURE9 radCopyTexture;
|
---|
| 218 | /**
|
---|
| 219 | The visibility map copy texture.
|
---|
| 220 | */
|
---|
| 221 | LPDIRECT3DTEXTURE9 visCopyTexture;
|
---|
| 222 | /**
|
---|
| 223 | A temporal texture.
|
---|
| 224 | */
|
---|
| 225 | LPDIRECT3DTEXTURE9 tempTexture;
|
---|
| 226 | /**
|
---|
| 227 | A texture to render shoot color to.
|
---|
| 228 | */
|
---|
| 229 | LPDIRECT3DTEXTURE9 shootColorTexture;
|
---|
| 230 | /**
|
---|
| 231 | The original emission texture.
|
---|
| 232 | */
|
---|
| 233 | LPDIRECT3DTEXTURE9 emissionTexture;
|
---|
| 234 | /**
|
---|
| 235 | Texture for the actual radiance.
|
---|
| 236 | */
|
---|
| 237 | LPDIRECT3DTEXTURE9 pActualRadianceTexture2;
|
---|
| 238 | /**
|
---|
| 239 | Texture for the actual radiance to swap textures.
|
---|
| 240 | */
|
---|
| 241 | LPDIRECT3DTEXTURE9 pActualRadianceTempTexture;
|
---|
| 242 | /**
|
---|
| 243 | Texture for BRDFs.
|
---|
| 244 | */
|
---|
| 245 | LPDIRECT3DTEXTURE9 pBRDFTexture;
|
---|
| 246 | /**
|
---|
| 247 | 0th surface of the corresponding texture.
|
---|
| 248 | */
|
---|
| 249 | LPDIRECT3DSURFACE9 pBRDFSurface;
|
---|
| 250 | /**
|
---|
| 251 | 0th surface of the corresponding texture.
|
---|
| 252 | */
|
---|
| 253 | LPDIRECT3DSURFACE9 pActualRadianceTempSurface;
|
---|
| 254 | /**
|
---|
| 255 | 0th surface of the corresponding texture.
|
---|
| 256 | */
|
---|
| 257 | LPDIRECT3DSURFACE9 pActualRadianceSurface2;
|
---|
| 258 | /**
|
---|
| 259 | 0th surface of the corresponding texture.
|
---|
| 260 | */
|
---|
| 261 | LPDIRECT3DSURFACE9 emissionSurface;
|
---|
| 262 | /**
|
---|
| 263 | 0th surface of the corresponding texture.
|
---|
| 264 | */
|
---|
| 265 | LPDIRECT3DSURFACE9 shootColorSurface;
|
---|
| 266 | /**
|
---|
| 267 | 0th surface of the corresponding texture.
|
---|
| 268 | */
|
---|
| 269 | LPDIRECT3DSURFACE9 tempSurface;
|
---|
| 270 | /**
|
---|
| 271 | 0th surface of the corresponding texture.
|
---|
| 272 | */
|
---|
| 273 | LPDIRECT3DSURFACE9 visCopySurface;
|
---|
| 274 | /**
|
---|
| 275 | 0th surface of the corresponding texture.
|
---|
| 276 | */
|
---|
| 277 | LPDIRECT3DSURFACE9 radCopySurface;
|
---|
| 278 | /**
|
---|
| 279 | 0th surface of the corresponding texture.
|
---|
| 280 | */
|
---|
| 281 | LPDIRECT3DSURFACE9 pRenderSurface;
|
---|
| 282 | /**
|
---|
| 283 | The original back buffer.
|
---|
| 284 | */
|
---|
| 285 | LPDIRECT3DSURFACE9 pBackBuffer;
|
---|
| 286 | /**
|
---|
| 287 | 0th surface of the corresponding texture.
|
---|
| 288 | */
|
---|
| 289 | LPDIRECT3DSURFACE9 pRadRenderSurface;
|
---|
| 290 | /**
|
---|
| 291 | 0th surface of the corresponding texture.
|
---|
| 292 | */
|
---|
| 293 | LPDIRECT3DSURFACE9 pRadRenderSurface2;
|
---|
| 294 | /**
|
---|
| 295 | 0th surface of the corresponding texture.
|
---|
| 296 | */
|
---|
| 297 | LPDIRECT3DSURFACE9 pActualRadianceSurface;
|
---|
| 298 | /**
|
---|
| 299 | Depth map for the render-to-surface passes.
|
---|
| 300 | */
|
---|
| 301 | LPDIRECT3DSURFACE9 rttDepthSurface;
|
---|
| 302 | /**
|
---|
| 303 | The original depth map.
|
---|
| 304 | */
|
---|
| 305 | LPDIRECT3DSURFACE9 origDepthSurface;
|
---|
| 306 | /**
|
---|
| 307 | 0th surface of the corresponding texture.
|
---|
| 308 | */
|
---|
| 309 | LPDIRECT3DSURFACE9 pIterationVisibilityRenderSurface;
|
---|
| 310 | /**
|
---|
| 311 | An array of 0th level surfaces of the corresponding textures.
|
---|
| 312 | */
|
---|
| 313 | LPDIRECT3DSURFACE9* pMipmapSurfaces;
|
---|
| 314 | /**
|
---|
| 315 | 0th surface of the corresponding texture.
|
---|
| 316 | */
|
---|
| 317 | LPDIRECT3DSURFACE9 shootSurface;
|
---|
| 318 | /**
|
---|
| 319 | Matrices. Passed to various shaders.
|
---|
| 320 | */
|
---|
| 321 | D3DXMATRIX matRotationY,matTranslation,matProjection,matViewWorldProjection,matOldProjection,inverseWorldMatrix;
|
---|
| 322 | /**
|
---|
| 323 | The current world matrix.
|
---|
| 324 | */
|
---|
| 325 | D3DXMATRIX matWorld;
|
---|
| 326 | /**
|
---|
| 327 | The effect file of the shaders.
|
---|
| 328 | */
|
---|
| 329 | LPD3DXEFFECT m_pEffect;
|
---|
| 330 | /**
|
---|
| 331 | The number of shader passes in a technique.
|
---|
| 332 | */
|
---|
| 333 | UINT nPasses;
|
---|
| 334 |
|
---|
| 335 | /**
|
---|
| 336 | The resolution indicator for the average calculation.
|
---|
| 337 | */
|
---|
| 338 | float fiRes2;
|
---|
| 339 | /**
|
---|
| 340 | The previous resolution indicator for the average calculation.
|
---|
| 341 | */
|
---|
| 342 | float fiOld;
|
---|
| 343 | /**
|
---|
| 344 | Vector to hold current shooter colors.
|
---|
| 345 | */
|
---|
| 346 | D3DXVECTOR4 lShoot;
|
---|
| 347 |
|
---|
| 348 | /**
|
---|
| 349 | Temporary for locking buffers.
|
---|
| 350 | */
|
---|
| 351 | VOID* pData;
|
---|
| 352 | /**
|
---|
| 353 | Texture height.
|
---|
| 354 | */
|
---|
| 355 | UINT textureHeight;
|
---|
| 356 | /**
|
---|
| 357 | Texture width.
|
---|
| 358 | */
|
---|
| 359 | UINT textureWidth;
|
---|
| 360 | /**
|
---|
| 361 | Mipmap levels.
|
---|
| 362 | */
|
---|
| 363 | UINT mipMapLevels;
|
---|
| 364 | /**
|
---|
| 365 | Visibility map texture format
|
---|
| 366 | */
|
---|
| 367 | _D3DFORMAT vismapFormat;
|
---|
| 368 | /**
|
---|
| 369 | Iteration visibility map texture format
|
---|
| 370 | */
|
---|
| 371 | _D3DFORMAT iterationVismapFormat;
|
---|
| 372 | /**
|
---|
| 373 | Radiosity maps texture format
|
---|
| 374 | */
|
---|
| 375 | _D3DFORMAT renderTextureFormat;
|
---|
| 376 | /**
|
---|
| 377 | Format of render-to-surface depth stencil buffer.
|
---|
| 378 | */
|
---|
| 379 | _D3DFORMAT depthStencilFormat;
|
---|
| 380 | /**
|
---|
| 381 | Format of radiosity mipmaps.
|
---|
| 382 | */
|
---|
| 383 | _D3DFORMAT mipmapFormat;
|
---|
| 384 | /**
|
---|
| 385 | Vertex declaration for render
|
---|
| 386 | */
|
---|
| 387 | IDirect3DVertexDeclaration9* textureDecl;
|
---|
| 388 | /**
|
---|
| 389 | The array of full screen quad vertices.
|
---|
| 390 | */
|
---|
| 391 | D3DVERTEX_1* textureVertices1;
|
---|
| 392 | /**
|
---|
| 393 | One vertex for the point.
|
---|
| 394 | */
|
---|
| 395 | D3DVERTEX_1 pointVertices;
|
---|
| 396 | /**
|
---|
| 397 | The data of the locked visibility map.
|
---|
| 398 | */
|
---|
| 399 | D3DXFLOAT16* visMapData;
|
---|
| 400 | /**
|
---|
| 401 | The fileformat to save the pictures to.
|
---|
| 402 | */
|
---|
| 403 | D3DXIMAGE_FILEFORMAT fileFormat;
|
---|
| 404 | /**
|
---|
| 405 | The reciproc of resolution.
|
---|
| 406 | */
|
---|
| 407 | float recres2;
|
---|
| 408 | /**
|
---|
| 409 | Locked floating point image data.
|
---|
| 410 | */
|
---|
| 411 | float* imageData;
|
---|
| 412 | /**
|
---|
| 413 | The index of the shooter in the visibility map.
|
---|
| 414 | */
|
---|
| 415 | int index2;
|
---|
| 416 | /**
|
---|
| 417 | The locked rectangle structure of the visibility map.
|
---|
| 418 | */
|
---|
| 419 | D3DLOCKED_RECT visRectangleToLock;
|
---|
| 420 | /**
|
---|
| 421 | The surface descriptor of the visibility map.
|
---|
| 422 | */
|
---|
| 423 | D3DSURFACE_DESC visSurfaceDesc;
|
---|
| 424 | /**
|
---|
| 425 | The shooter face index.
|
---|
| 426 | */
|
---|
| 427 | DWORD shooter;
|
---|
| 428 | /**
|
---|
| 429 | Locked rectangle structure.
|
---|
| 430 | */
|
---|
| 431 | D3DLOCKED_RECT rectangleToLock;
|
---|
| 432 | /**
|
---|
| 433 | Surface descriptor.
|
---|
| 434 | */
|
---|
| 435 | D3DSURFACE_DESC surfaceDesc;
|
---|
| 436 | /**
|
---|
| 437 | The colors float[4] of the shooter.
|
---|
| 438 | */
|
---|
| 439 | float* shootcolors;
|
---|
| 440 | /**
|
---|
| 441 | From vector.
|
---|
| 442 | */
|
---|
| 443 | D3DXVECTOR3 fromD3D;
|
---|
| 444 | /**
|
---|
| 445 | Up vector.
|
---|
| 446 | */
|
---|
| 447 | D3DXVECTOR3 upD3D;
|
---|
| 448 | /**
|
---|
| 449 | Lookat vector.
|
---|
| 450 | */
|
---|
| 451 | D3DXVECTOR3 lookatD3D;
|
---|
| 452 | /**
|
---|
| 453 | Direction vector.
|
---|
| 454 | */
|
---|
| 455 | D3DXVECTOR3 dirD3D ;
|
---|
| 456 | /**
|
---|
| 457 | Camera eye position.
|
---|
| 458 | */
|
---|
| 459 | D3DXVECTOR3 eyePos;
|
---|
| 460 | /**
|
---|
| 461 | Camera lookat vector.
|
---|
| 462 | */
|
---|
| 463 | D3DXVECTOR3 camLookAt;
|
---|
| 464 | /**
|
---|
| 465 | Camera direction.
|
---|
| 466 | */
|
---|
| 467 | D3DXVECTOR3 camDir;
|
---|
| 468 | /**
|
---|
| 469 | Pointer to a vector of ALIAS/WAVEFRONT Maya .obj objects.
|
---|
| 470 | */
|
---|
| 471 | ObjectVector* objectVector;
|
---|
| 472 |
|
---|
| 473 | };
|
---|
| 474 | #endif |
---|