/** @author Barsi Attila @copyright BMGE Department of Control Engineering and Informatics @brief D3D Radiosity algorithm wrapper class. */ #pragma once #ifndef RADIOSITYALGORITHM_H #define RADIOSITYALGORITHM_H //#define DEBUG_SHADER class RadiosityAlgorithm{ public: /** Constructor. */ RadiosityAlgorithm(UINT textureWidth,UINT textureHeight,UINT mipMapLevels,_D3DFORMAT vismapFormat,_D3DFORMAT iterationVismapFormat,_D3DFORMAT renderTextureFormat,_D3DFORMAT mipmapFormat,_D3DFORMAT depthStencilFormat); /** Destructor. */ ~RadiosityAlgorithm(); /** Initializes objects. @param The current direct3d device. @return The error code. */ HRESULT initObjects(LPDIRECT3DDEVICE9 d3dDevice); /** Deletes objects. @return The error code. */ HRESULT deleteObjects(); /** Does the radiosity averaging pass. @param doDebugPicture If true, saves a debug picture. @param fileName The fileName to save the picture to. @param niteration The current iteration count. @return The error code. */ HRESULT doRadiosityAveragingPass(bool doDebugPicture,TCHAR* fileName,UINT niteration); /** Renders the emission to the texture atlas. @param doDebugPicture If true, saves a debug picture. @param fileName The fileName to save the picture to. @return The error code. */ HRESULT doEmissionMapPass(bool doDebugPicture,TCHAR* fileName); /** Renders the original visibility map to the texture atlas. @param doDebugPicture If true, saves a debug picture. @param fileName The fileName to save the picture to. @return The error code. */ HRESULT doOriginalVisibilityMapPass(bool doDebugPicture,TCHAR* fileName); /** Iterates the solution for a given number of times. @param niterations The number of iterations to compute. @param iterationToSave The iteration to save. @return The error code. */ HRESULT iterate(UINT niterations,UINT iterationToSave); /** Renders all mipmap levels of the radiosity texture. @param niteration The current iteration count. @return The error code. */ HRESULT createRadiosityMipMap(UINT niteration); /** Chooses a shooter based on the current radiosity map and iteration count. @param niteration The current iteration count. @return The error code. */ HRESULT chooseShooter(UINT iterations); /** Does the per iteration visibility map from the shooter. Visibility is calculated per hemicube side. @param doDebugPicture If true, saves a debug picture. @param fileName The fileName to save the picture to. @param center Center of the camera. @param dir Direction of the camera. @param up Up vector of the camera. @param fullscreen Render fullscreen or half screen (on hemicube sides.) @return The error code. */ HRESULT doIterationVisibilityMapPass(bool doDebugPicture,TCHAR* fileName,D3DXVECTOR3 center,D3DXVECTOR3 dir,D3DXVECTOR3 up,bool fullScreen); /** Renders the radiosity map. @param niteration The current iteration count. @param doDebugPicture If true, saves a debug picture. @param fileName The fileName to save the picture to. @return The error code. */ HRESULT doRadiosityMapPass(UINT iterations,bool doDebugPicture,TCHAR* fileName); /** Avarages the actual radiosity map. @param iterations The number of iterations computed in iterate(). @param doDebugPicture If true, saves a debug picture. @param fileName The fileName to save the picture to. @return The error code. */ HRESULT doRadiosityActualAveragingPass(UINT iterations,bool doDebugPicture,TCHAR* fileName); /** Renders the final picture. @param doDebugPicture If true, saves a debug picture. @param fileName The fileName to save the picture to. @return The error code. */ HRESULT doFinalPicturePass(bool doDebugPicture,TCHAR* fileName); /** Initializes the actual radiance map. @return The error code. */ HRESULT initActualRadianceMap(); /** Initializes the BRDF and Specular map. @return The error code. */ HRESULT initBRDFAndSpecularMap(); /** Moves the objects to a given location. @param x The coordinate x. @param y The coordinate y. @param z The coordinate z. @return The error code. */ HRESULT moveObjects(float x,float y,float z); /** Moves the camera (View matrix) to a given location. Up is calculated from eye and lookat. @param eyeX The X coordinate of the eye vector. @param eyeY The Y coordinate of the eye vector. @param eyeZ The Z coordinate of the eye vector. @param lookAtX The X coordinate of the look at vector. @param lookAtY The Y coordinate of the look at vector. @param lookAtZ The Z coordinate of the look at vector. @return The error code. */ HRESULT moveCamera(float eyeX,float eyeY,float eyeZ,float lookAtX,float lookAtY,float lookAtZ); private: /** Pointer to the direct3d device. */ LPDIRECT3DDEVICE9 d3dDevice; //ofstream* errLogger; /** The error code. */ HRESULT hr; /** The full screen quad vertex buffer. */ LPDIRECT3DVERTEXBUFFER9 pQuadVB; /** The on point vertex buffer. */ LPDIRECT3DVERTEXBUFFER9 pPointVB; /** The shooter disc. */ float shooterDisc; /** The py parameter of the shader. */ float py; /** The time before the start of the rendering. */ DWORD timeBefore; /** The time after the completion of the rendering. */ DWORD timeAfter; //Texture declaration. /** The original visibility texture. */ LPDIRECT3DTEXTURE9 pOrigVisibilityTexture; /** The iteration visibility texture. */ LPDIRECT3DTEXTURE9 pIterationVisibilityTexture; /** The radiosity texture. */ LPDIRECT3DTEXTURE9 pRadiosityTexture; /** The radiosity texture for swapping textures. */ LPDIRECT3DTEXTURE9 pRadiosityTexture2; /** The texture for accumulated actual radiance. */ LPDIRECT3DTEXTURE9 pActualRadianceTexture; /** An array for the radiosity mipmap textures. */ LPDIRECT3DTEXTURE9* mipmapTexturesArray; /** The texture for selecting the shooter. */ LPDIRECT3DTEXTURE9 shootTexture; /** The radiosity map copy texture. */ LPDIRECT3DTEXTURE9 radCopyTexture; /** The visibility map copy texture. */ LPDIRECT3DTEXTURE9 visCopyTexture; /** A temporal texture. */ LPDIRECT3DTEXTURE9 tempTexture; /** A texture to render shoot color to. */ LPDIRECT3DTEXTURE9 shootColorTexture; /** The original emission texture. */ LPDIRECT3DTEXTURE9 emissionTexture; /** Texture for the actual radiance. */ LPDIRECT3DTEXTURE9 pActualRadianceTexture2; /** Texture for the actual radiance to swap textures. */ LPDIRECT3DTEXTURE9 pActualRadianceTempTexture; /** Texture for BRDFs. */ LPDIRECT3DTEXTURE9 pBRDFTexture; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 pBRDFSurface; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 pActualRadianceTempSurface; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 pActualRadianceSurface2; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 emissionSurface; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 shootColorSurface; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 tempSurface; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 visCopySurface; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 radCopySurface; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 pRenderSurface; /** The original back buffer. */ LPDIRECT3DSURFACE9 pBackBuffer; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 pRadRenderSurface; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 pRadRenderSurface2; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 pActualRadianceSurface; /** Depth map for the render-to-surface passes. */ LPDIRECT3DSURFACE9 rttDepthSurface; /** The original depth map. */ LPDIRECT3DSURFACE9 origDepthSurface; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 pIterationVisibilityRenderSurface; /** An array of 0th level surfaces of the corresponding textures. */ LPDIRECT3DSURFACE9* pMipmapSurfaces; /** 0th surface of the corresponding texture. */ LPDIRECT3DSURFACE9 shootSurface; /** Matrices. Passed to various shaders. */ D3DXMATRIX matRotationY,matTranslation,matProjection,matViewWorldProjection,matOldProjection,inverseWorldMatrix; /** The current world matrix. */ D3DXMATRIX matWorld; /** The effect file of the shaders. */ LPD3DXEFFECT m_pEffect; /** The number of shader passes in a technique. */ UINT nPasses; /** The resolution indicator for the average calculation. */ float fiRes2; /** The previous resolution indicator for the average calculation. */ float fiOld; /** Vector to hold current shooter colors. */ D3DXVECTOR4 lShoot; /** Temporary for locking buffers. */ VOID* pData; /** Texture height. */ UINT textureHeight; /** Texture width. */ UINT textureWidth; /** Mipmap levels. */ UINT mipMapLevels; /** Visibility map texture format */ _D3DFORMAT vismapFormat; /** Iteration visibility map texture format */ _D3DFORMAT iterationVismapFormat; /** Radiosity maps texture format */ _D3DFORMAT renderTextureFormat; /** Format of render-to-surface depth stencil buffer. */ _D3DFORMAT depthStencilFormat; /** Format of radiosity mipmaps. */ _D3DFORMAT mipmapFormat; /** Vertex declaration for render */ IDirect3DVertexDeclaration9* textureDecl; /** The array of full screen quad vertices. */ D3DVERTEX_1* textureVertices1; /** One vertex for the point. */ D3DVERTEX_1 pointVertices; /** The data of the locked visibility map. */ D3DXFLOAT16* visMapData; /** The fileformat to save the pictures to. */ D3DXIMAGE_FILEFORMAT fileFormat; /** The reciproc of resolution. */ float recres2; /** Locked floating point image data. */ float* imageData; /** The index of the shooter in the visibility map. */ int index2; /** The locked rectangle structure of the visibility map. */ D3DLOCKED_RECT visRectangleToLock; /** The surface descriptor of the visibility map. */ D3DSURFACE_DESC visSurfaceDesc; /** The shooter face index. */ DWORD shooter; /** Locked rectangle structure. */ D3DLOCKED_RECT rectangleToLock; /** Surface descriptor. */ D3DSURFACE_DESC surfaceDesc; /** The colors float[4] of the shooter. */ float* shootcolors; /** From vector. */ D3DXVECTOR3 fromD3D; /** Up vector. */ D3DXVECTOR3 upD3D; /** Lookat vector. */ D3DXVECTOR3 lookatD3D; /** Direction vector. */ D3DXVECTOR3 dirD3D ; /** Camera eye position. */ D3DXVECTOR3 eyePos; /** Camera lookat vector. */ D3DXVECTOR3 camLookAt; /** Camera direction. */ D3DXVECTOR3 camDir; /** Pointer to a vector of ALIAS/WAVEFRONT Maya .obj objects. */ ObjectVector* objectVector; }; #endif