• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當自強而不息

            DXUT源碼分析 ---- 類CDXUTMesh(5)

            最后一類是渲染函數,類CDXUTMesh重載了兩個渲染函數Render(),其作用都是用來渲染當前的網格模型。所不同的是,第一個函數用在固定函數流水線中,第二個函數用在可編程流水線技術中,這兩個函數的最后兩個參數用于指定是否渲染網格模型中的不透明和半透明部分。

            首先來看第一個Render()函數:

            HRESULT CDXUTMesh::Render( LPDIRECT3DDEVICE9 pd3dDevice, bool bDrawOpaqueSubsets, bool bDrawAlphaSubsets )
            {
                
            if( NULL == m_pMesh )
                    
            return E_FAIL;

                
            // Frist, draw the subsets without alpha
                if( bDrawOpaqueSubsets )
                {
                    
            for( DWORD i=0; i<m_dwNumMaterials; i++ )
                    {
                        
            if( m_bUseMaterials )
                        {
                            
            if( m_pMaterials[i].Diffuse.a < 1.0f )
                                
            continue;

                            pd3dDevice
            ->SetMaterial( &m_pMaterials[i] );
                            pd3dDevice
            ->SetTexture( 0, m_pTextures[i] );
                        }

                        m_pMesh
            ->DrawSubset( i );
                    }
                }

                
            // Then, draw the subsets with alpha
                if( bDrawAlphaSubsets && m_bUseMaterials )
                {
                    
            for( DWORD i=0; i<m_dwNumMaterials; i++ )
                    {
                        
            if( m_pMaterials[i].Diffuse.a == 1.0f )
                            
            continue;

                        
            // Set the material and texture
                        pd3dDevice->SetMaterial( &m_pMaterials[i] );
                        pd3dDevice
            ->SetTexture( 0, m_pTextures[i] );
                        m_pMesh
            ->DrawSubset( i );
                    }
                }

                
            return S_OK;
            }

             

            代碼簡潔明了,首先繪制不透明的網格(alpha == 1.0f),接著繪制半透明的網格(alpha != 1.0f)。

             

            接著來看第二個Render()函數:

            HRESULT CDXUTMesh::Render( ID3DXEffect *pEffect,
                                       D3DXHANDLE hTexture,  D3DXHANDLE hDiffuse,  D3DXHANDLE hAmbient,
                                       D3DXHANDLE hSpecular, D3DXHANDLE hEmissive, D3DXHANDLE hPower,
                                       
            bool bDrawOpaqueSubsets, bool bDrawAlphaSubsets )
            {
                
            if( NULL == m_pMesh )
                    
            return E_FAIL;

                UINT cPasses;

                
            // Frist, draw the subsets without alpha
                if( bDrawOpaqueSubsets )
                {
                    pEffect
            ->Begin( &cPasses, 0 );

                    
            for( UINT p = 0; p < cPasses; ++p )
                    {
                        pEffect
            ->BeginPass( p );

                        
            for( DWORD i=0; i<m_dwNumMaterials; i++ )
                        {
                            
            if( m_bUseMaterials )
                            {
                                
            if( m_pMaterials[i].Diffuse.a < 1.0f )
                                    
            continue;

                                
            if( hTexture )
                                    pEffect
            ->SetTexture( hTexture, m_pTextures[i] );

                                
            // D3DCOLORVALUE and D3DXVECTOR4 are data-wise identical.
                                
            // No conversion is needed.

                                
            if( hDiffuse )
                                    pEffect
            ->SetVector( hDiffuse, (D3DXVECTOR4*)&m_pMaterials[i].Diffuse );

                                
            if( hAmbient )
                                    pEffect
            ->SetVector( hAmbient, (D3DXVECTOR4*)&m_pMaterials[i].Ambient );

                                
            if( hSpecular )
                                    pEffect
            ->SetVector( hSpecular, (D3DXVECTOR4*)&m_pMaterials[i].Specular );

                                
            if( hEmissive )
                                    pEffect
            ->SetVector( hEmissive, (D3DXVECTOR4*)&m_pMaterials[i].Emissive );

                                
            if( hPower )
                                    pEffect
            ->SetFloat( hPower, m_pMaterials[i].Power );

                                pEffect
            ->CommitChanges();
                            }

                            m_pMesh
            ->DrawSubset( i );
                        }

                        pEffect
            ->EndPass();
                    }

                    pEffect
            ->End();
                }

                
            // Then, draw the subsets with alpha
                if( bDrawAlphaSubsets )
                {
                    pEffect
            ->Begin( &cPasses, 0 );

                    
            for( UINT p = 0; p < cPasses; ++p )
                    {
                        pEffect
            ->BeginPass( p );

                        
            for( DWORD i=0; i<m_dwNumMaterials; i++ )
                        {
                            
            if( m_bUseMaterials )
                            {
                                
            if( m_pMaterials[i].Diffuse.a == 1.0f )
                                    
            continue;

                                
            if( hTexture )
                                    pEffect
            ->SetTexture( hTexture, m_pTextures[i] );

                                
            // D3DCOLORVALUE and D3DXVECTOR4 are data-wise identical.
                                
            // No conversion is needed.

                                
            if( hDiffuse )
                                    pEffect
            ->SetVector( hDiffuse, (D3DXVECTOR4*)&m_pMaterials[i].Diffuse );

                                
            if( hAmbient )
                                    pEffect
            ->SetVector( hAmbient, (D3DXVECTOR4*)&m_pMaterials[i].Ambient );

                                
            if( hSpecular )
                                    pEffect
            ->SetVector( hSpecular, (D3DXVECTOR4*)&m_pMaterials[i].Specular );

                                
            if( hEmissive )
                                    pEffect
            ->SetVector( hEmissive, (D3DXVECTOR4*)&m_pMaterials[i].Emissive );

                                
            if( hPower )
                                    pEffect
            ->SetFloat( hPower, m_pMaterials[i].Power );

                                pEffect
            ->CommitChanges();
                            }

                            m_pMesh
            ->DrawSubset( i );
                        }

                        pEffect
            ->EndPass();
                    }

                    pEffect
            ->End();
                }

                
            return S_OK;
            }

             

            代碼也是相當簡潔明了,首先繪制不透明網格,接著繪制半透明網格。在繪制時遍歷所有的通道,并設置紋理,材質的漫反射光、環境光、鏡面反射光、自發光、鏡面反射光指數。

            posted on 2008-05-31 11:36 lovedday 閱讀(511) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            国产成人精品久久免费动漫| 国产精品久久久久免费a∨| 久久国产精品一区二区| 精品乱码久久久久久久| 免费观看久久精彩视频| a级毛片无码兔费真人久久| 精品久久久久久无码免费| 日本五月天婷久久网站| 99久久国产综合精品麻豆| 国产精品无码久久久久| 久久这里都是精品| 久久青草国产精品一区| 97精品伊人久久大香线蕉| 国产精品美女久久久| 四虎国产精品免费久久| 国产成人久久精品激情| 亚洲国产成人精品久久久国产成人一区二区三区综 | 青青青青久久精品国产h| 欧美精品一区二区久久| 成人综合伊人五月婷久久| 久久婷婷五月综合色99啪ak| 久久本道伊人久久| 久久无码高潮喷水| 欧美午夜精品久久久久久浪潮| 久久精品黄AA片一区二区三区| 欧美国产成人久久精品| 久久无码av三级| 国产亚洲欧美精品久久久| 久久99久久99精品免视看动漫| 久久国产香蕉视频| 青青草国产精品久久久久| 国产美女久久精品香蕉69| 亚洲AV成人无码久久精品老人| 伊人久久成人成综合网222| 国产亚洲美女精品久久久| 久久超乳爆乳中文字幕| 亚洲精品乱码久久久久66| 亚洲精品美女久久久久99| 久久久久亚洲av无码专区导航| 日韩精品久久无码中文字幕| 久久精品国产精品亚洲精品|