0001: //-------------------------------------------------------------
0002: // File: main.h
0003: //
0004: // Desc: Real-Time Global Illumination
0005: // Copyright (c) 2004 IMAGIRE Takashi. All rights reserved.
0006: //-------------------------------------------------------------
0007: #pragma once
0008: 
0009: #define DX9C
0010: 
0011: #ifdef DX9C
0012:     #define BEGIN_PASS(n) m_pEffect->BeginPass(n)
0013:     #define END_PASS()    m_pEffect->EndPass()
0014: #else// DX9C
0015:     #define BEGIN_PASS(n) m_pEffect->Pass(n)
0016:     #define END_PASS()
0017: #endif // DX9C
0018: 
0019: //-------------------------------------------------------------
0020: // Defines, and constants(定義や定数)
0021: //-------------------------------------------------------------
0022: 
0023: // Struct to store the current input state(現在の入力データを保存する構造体)
0024: struct UserInput
0025: {
0026:     BOOL bRotateUp;
0027:     BOOL bRotateDown;
0028:     BOOL bRotateLeft;
0029:     BOOL bRotateRight;
0030:     BOOL bZoomIn;
0031:     BOOL bZoomOut;
0032:     BOOL bChangeShader;
0033:     BOOL bDiffuseUp;
0034:     BOOL bDiffuseDown;
0035:     BOOL bSpecularUp;
0036:     BOOL bSpecularDown;
0037:     BOOL bTranslucentUp;
0038:     BOOL bTranslucentDown;
0039:     BOOL bPause;
0040: };
0041: 
0042: 
0043: 
0044: 
0045: //-------------------------------------------------------------
0046: // Name: class CMyD3DApplication
0047: // Desc: Main class to run this application. Most functionality is inherited
0048: //       from the CD3DApplication base class.
0049: //       (アプリケーションのクラス)
0050: //-------------------------------------------------------------
0051: class CMyD3DApplication : public CD3DApplication
0052: {
0053:     enum{
0054:         L_MAX = 1,                          // The maximum expansion degree(最大の計算次数)
0055:         TEX_MAX = ((L_MAX+1)*(L_MAX+1)+3)/4,// The number of texture for SH expansion(SHのテクスチャ枚数)
0056: 
0057:         REDUCTION_MAPS = 3,                 // The number of times of reduction(縮小回数)
0058:     };
0059:      
0060:     float                   m_fDiffuse;
0061:     float                   m_fSpecular;
0062:     float                   m_fTranslucent;
0063: 
0064:     // Scene management(シーン管理)
0065:     int                     m_iState;       // State(状態変数)
0066:     int                     m_iChangeState; // 
0067:     int                     m_iCount;       // Increment per rendering(状態変数管理用時間変数)
0068:     bool                    m_bPause;       // Pause
0069: 
0070:     // Model
0071:     CD3DMesh                *m_pMesh;
0072:     CD3DMesh                *m_pMeshBg;
0073:     CD3DMesh                *m_pMeshEnv;
0074:     
0075:     // Dynamics for a ball
0076:     D3DXVECTOR3             m_pos;          // Position(位置)
0077:     D3DXVECTOR3             m_vel;          // Velocity(速度)
0078:     D3DXVECTOR3             m_rot;          // Rotation(角度)
0079:     D3DXVECTOR3             m_omega;        // Angler velocity(角速度)
0080:     
0081:     D3DXVECTOR3             m_EnvRot[4];    // Rotation
0082:     FLOAT                   m_EnvRate;
0083:     D3DXMATRIX              m_mEnv;
0084: 
0085:     // Shader
0086:     int                     m_Shader;       // Type of shader(シェーダの種類)
0087:     LPD3DXEFFECT            m_pEffect;      // Effect for the sample(エフェクト)
0088:     D3DXHANDLE              m_hTechnique;   // Technique handle for RenderScene(テクニック)
0089:     D3DXHANDLE              m_hmWV;         // Handle for world+view matrix in effect(変換行列)
0090:     D3DXHANDLE              m_hmWVP;        // Handle for world+view+projection matrix in effect(変換行列)
0091:     D3DXHANDLE              m_htSrcTex;     // Handle for the scene texture in effect(テクスチャ)
0092:     D3DXHANDLE              m_fWidth;       // Handle for the texture width in effect(テクスチャ幅)
0093:     D3DXHANDLE              m_fHeight;      // Handle for the texture height in effect(テクスチャ高さ)
0094: 
0095:     // Rendering targets (レンダリングターゲット)
0096:     LPDIRECT3DSURFACE9      m_pMapZ;                    // Depth buffer
0097:     LPDIRECT3DTEXTURE9      m_pPosTex;                  // Height map(高さマップ)
0098:     LPDIRECT3DSURFACE9      m_pPosSurf;                 // 
0099:     LPDIRECT3DTEXTURE9      m_pPosLockTex;              // 
0100:     LPDIRECT3DSURFACE9      m_pPosLockSurf;             // 
0101:     LPDIRECT3DTEXTURE9      m_pNormalTex;               // Normal map(法線マップ)
0102:     LPDIRECT3DSURFACE9      m_pNormalSurf;              // 
0103:     LPDIRECT3DTEXTURE9      m_pNormalLockTex;           // 
0104:     LPDIRECT3DSURFACE9      m_pNormalLockSurf;          // 
0105: 
0106:     LPDIRECT3DTEXTURE9      m_pParaboloidTex[2];        // Environment map
0107:     LPDIRECT3DSURFACE9      m_pParaboloidSurf[2];
0108:     LPDIRECT3DTEXTURE9      m_pJacobianTex[TEX_MAX][2]; // SH coefficient of incoming light
0109: 
0110:     LPDIRECT3DTEXTURE9      m_pReductionTex [REDUCTION_MAPS];// Reduction buffer
0111:     LPDIRECT3DSURFACE9      m_pReductionSurf[REDUCTION_MAPS];
0112: 
0113:     LPDIRECT3DTEXTURE9      m_p64Tex ;// Reduction buffer
0114:     LPDIRECT3DSURFACE9      m_p64Surf;
0115:     LPDIRECT3DSURFACE9      m_p64Z;
0116:     LPDIRECT3DTEXTURE9      m_p64Tex2;// Reduction buffer
0117:     LPDIRECT3DSURFACE9      m_p64Surf2;
0118:     LPDIRECT3DTEXTURE9      m_p8Tex ;// Reduction buffer
0119:     LPDIRECT3DSURFACE9      m_p8Surf;
0120: 
0121:     LPDIRECT3DTEXTURE9      m_pFinalTex[TEX_MAX];// PRT テクスチャ
0122:     LPDIRECT3DSURFACE9      m_pFinalSurf[TEX_MAX];
0123:     LPDIRECT3DTEXTURE9      m_pFinalSSTex[TEX_MAX];// SS_PRT テクスチャ
0124:     LPDIRECT3DSURFACE9      m_pFinalSSSurf[TEX_MAX];
0125:     LPDIRECT3DTEXTURE9      m_pMaskTex;         // 係数計算
0126: 
0127:     // Geometry (通常の座標変換行列)
0128:     D3DXMATRIX              m_mWorld;       // World matrix
0129:     D3DXMATRIX              m_mView;        // View matrix
0130:     D3DXMATRIX              m_mProj;        // Projection matrix
0131: 
0132:     FLOAT                   m_fWorldRotX;   // World rotation state X-axis(X軸回転)
0133:     FLOAT                   m_fWorldRotY;   // World rotation state Y-axis(Y軸回転)
0134:     FLOAT                   m_fViewZoom;    // Distance to lookat (視点の距離)
0135: 
0136:     BOOL                    m_bLoadingApp;  // TRUE, if the app is loading(ロード中?)
0137:     CD3DFont*               m_pFont;        // Font for drawing text(フォント)
0138:     UserInput               m_UserInput;    // Struct for storing user input (入力データ)
0139: 
0140: protected:
0141:     virtual HRESULT OneTimeSceneInit();
0142:     virtual HRESULT InitDeviceObjects();
0143:     virtual HRESULT RestoreDeviceObjects();
0144:     virtual HRESULT InvalidateDeviceObjects();
0145:     virtual HRESULT DeleteDeviceObjects();
0146:     virtual HRESULT Render();
0147:     virtual HRESULT FrameMove();
0148:     virtual HRESULT FinalCleanup();
0149:     virtual HRESULT ConfirmDevice( D3DCAPS9*, DWORD, D3DFORMAT );
0150: 
0151:     int  FrameMoveCreateMap();
0152:     void RenderCreateMap();
0153:     int  FrameMovePRT();
0154:     void RenderPRT();
0155:     int  FrameMoveSSPRT();
0156:     void RenderSSPRT();
0157:     void RenderParaboloidMap();
0158: 
0159:     HRESULT RenderText();
0160: 
0161:     void    UpdateInput( UserInput* pUserInput );
0162: public:
0163:     LRESULT MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
0164:     CMyD3DApplication();
0165:     virtual ~CMyD3DApplication();
0166: };
0167: 
0168: