• <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游戲編程相關鏈接

            搜索

            最新評論

            国产毛片久久久久久国产毛片 | 人妻精品久久久久中文字幕69 | 国产精品伊人久久伊人电影| 女人香蕉久久**毛片精品| 久久婷婷综合中文字幕| 久久精品国产一区二区 | 久久久黄片| 蜜桃麻豆WWW久久囤产精品| 亚洲va中文字幕无码久久不卡 | 无码人妻久久一区二区三区蜜桃 | 国产亚洲美女精品久久久| 久久婷婷色综合一区二区| 午夜天堂av天堂久久久| 精品国产热久久久福利| 性高湖久久久久久久久| 久久久久亚洲AV成人网| 久久久久无码精品国产| 久久一区二区三区免费| 国产精品久久久久影院嫩草| 久久只有这里有精品4| 99国内精品久久久久久久 | 国产精品青草久久久久福利99| AV无码久久久久不卡蜜桃| 精品久久久久国产免费| 99久久精品国内| 亚洲色欲久久久综合网| 久久久噜噜噜久久中文字幕色伊伊| 国产精品9999久久久久| 婷婷久久久亚洲欧洲日产国码AV| 色8激情欧美成人久久综合电| 国产精品久久久久久| 久久91精品久久91综合| 久久久久99精品成人片直播| 色狠狠久久AV五月综合| 久久久久免费精品国产| 久久亚洲日韩看片无码| 久久精品国产一区二区| 亚洲国产精品狼友中文久久久| 久久综合精品国产一区二区三区| 日产久久强奸免费的看| 狠狠色丁香久久婷婷综合蜜芽五月|