• <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>

            4D星宇

            c++

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              57 隨筆 :: 0 文章 :: 39 評論 :: 0 Trackbacks

            有Effect版:
                DWORD         g_dwShaderFlags; // Shader compilate and link flags
                  LPD3DXBUFFER  g_pCompiledFragments = NULL; 

                D3DXGatherFragmentsFromFile( L"FragmentLinker.fx", NULL,
                            NULL, g_dwShaderFlags, &g_pCompiledFragments, NULL );

            D3DXGatherFragmentsFromFile requires the .fx file, pointers to the #define and #include handlers (both set to NULL in this example), and the shader compile flags. The method returns a buffer which contains the compiled shader fragment. The method can return a second buffer with compile errors, which is set to NULL in this example because it is not used. D3DXGatherFragments is overloaded to handle loading fragments from a string, a file, or a resource.

            Set your debugger to break on this method to look for compile errors in the debugger. The compiler can catch errors in syntax, but it cannot check for registers that are shared incorrectly due to the fact that it has no way to predict which parameters a user may want to share between fragments.

            You need a fragment linker to manage the compiled fragments. Create the fragment linker by calling D3DXCreateFragmentLinker:

            ID3DXFragmentLinker* g_pFragmentLinker = NULL;     // Fragment linker interface
            IDirect3DDevice9*    pd3dDevice        = NULL;

                // Initialize the device before using it
             ...
             
                // Create the fragment linker interface
                D3DXCreateFragmentLinker( pd3dDevice, 0, &g_pFragmentLinker );

            Then simply add the compiled fragments to the fragment linker using ID3DXFragmentLinker::AddFragments.

                // Add the compiled fragments to a list
                g_pFragmentLinker->AddFragments(    
                          (DWORD*)g_pCompiledFragments->GetBufferPointer() );

            ID3DXFragmentLinker::AddFragments requires a pointer to the DWORD stream that contains the compiled shader.

            After compiling fragments and creating a fragment linker, there are several ways to link fragments. One way to link a vertex shader fragment is to call ID3DXFragmentLinker::LinkVertexShader. Here is an example that links two vertex shader fragments:

                // Get a handle to each fragment   
                D3DXHANDLE fragmentHandle[2];
             fragmentHandle[0] =
                 (D3DXHANDLE)g_pFragmentLinker->GetFragmentHandleByName("Ambient");
             fragmentHandle[1] =
                 (D3DXHANDLE)g_pFragmentLinker->GetFragmentHandleByName("AmbientDiffuseFragment");
               
                // Link the fragments together to form a vertex shader
                IDirect3DVertexShader9* pVertexShader = NULL;
                g_pFragmentLinker->LinkVertexShader( "vs_1_1", g_dwShaderFlags,
                       fragmentHandle, 2, &pVertexShader, NULL );

            This requires a shader compile target, the shader compile and link flags, and a handle to each of the fragments to link. If the fragments are successfully linked, ID3DXFragmentLinker::LinkVertexShader returns a vertex shader (IDirect3DVertexShader9). The vertex shader needs to be set in the effect before rendering. But before this, here's how the shader is declared in the effect:

            VertexShader MyVertexShader; // Vertex shader set by the application

            The effect technique contains all the state set for a pass. This pass specifies the vertex shader like this:

            technique RenderScene
            {
                pass P0
                {
                    VertexShader = <MyVertexShader>;   
                    PixelShader = compile ps_1_1 ModulateTexture();   
                }

            With the effect's vertex shader created and initialized, the render code also sets the uniform constants and calls the render loop. Set the uniform constants similar to this:

                // Update the uniform shader constants.
                g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection );
                g_pEffect->SetMatrix( "g_mWorld", &mWorld );
                g_pEffect->SetFloat( "g_fTime", (float)fTime );   
            Then render the effect by setting the current technique and pass:

                // Render the scene
                if( SUCCEEDED( pd3dDevice->BeginScene() ) )
                { 
                    // Apply the technique contained in the effect
                    UINT cPasses, iPass;
                    g_pEffect->Begin(&cPasses, 0);

                    for (iPass = 0; iPass < cPasses; iPass++)
                    {
                        g_pEffect->BeginPass(iPass);

                        // Render the mesh with the applied technique
                        g_pMesh->DrawSubset(0);

                        g_pEffect->EndPass();
                    }
                    g_pEffect->End();

                    pd3dDevice->EndScene();
                }

            When setting uniform shader constants, it is more efficient to cache a handle to the parameter by calling ID3DXBaseEffect::GetParameterByName. This avoids the string lookup that is necessary when calling effect methods like ID3DXBaseEffect::SetMatrix.

              // Instead of setting a uniform constant like this in the render loop
              g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection );

              // Get a handle to a uniform constant outside of the render loop
              D3DXHANDLE hParameter;
              GetParameterByName( hParameter,"g_mWorldViewProjection");

              ...
             
              // Use the handle to set the uniform constant in the render loop
              g_pEffect->SetMatrix(hParameter);

            無Effect版:
             LPD3DXCONSTANTTABLE pConstantTable;
                LPD3DXBUFFER pShaderBuf;
                IDirect3DVertexShader9* pVertexShader = NULL;

                // Compile the fragments to a buffer.
                D3DXGatherFragmentsFromFile( L"FragmentLinker.fx", NULL, NULL,
                     g_dwShaderFlags, &g_pCompiledFragments, NULL );
               
                g_pFragmentLinker->AddFragments((DWORD*)g_pCompiledFragments->GetBufferPointer());
                g_pFragmentLinker->LinkShader(
                 "vs_1_1",
                 g_dwShaderFlags,
                 aHandles,
                 NUM_FRAGMENTS,
                 &pShaderBuf,
                 NULL);
                D3DXGetShaderConstantTable(
                 (DWORD*)pShaderBuf->GetBufferPointer(),
                 &pConstantTable );
               
                pDevice->CreateVertexShader(
                 (DWORD*)pShaderBuf->GetBufferPointer(),
                 &pVertexShader);
                RELEASE(pShaderBuf);

            posted on 2008-05-12 19:51 bloodbao 閱讀(457) 評論(0)  編輯 收藏 引用 所屬分類: c++
            午夜福利91久久福利| 日本久久中文字幕| 国产欧美一区二区久久| 久久香蕉一级毛片| 精品国产青草久久久久福利| 99精品国产免费久久久久久下载| 99久久精品免费看国产一区二区三区 | 26uuu久久五月天| 亚洲精品高清一二区久久| 无码人妻久久久一区二区三区| 91精品国产色综久久 | 99久久久久| 久久久国产打桩机| 久久综合久久久| 久久影视综合亚洲| 久久久久国产精品| 99久久精品免费看国产一区二区三区| 久久综合综合久久97色| 久久精品aⅴ无码中文字字幕不卡| 久久青草国产精品一区| 人妻无码中文久久久久专区| 久久99精品久久久久久噜噜| 亚洲av日韩精品久久久久久a| 久久影视国产亚洲| 精品无码久久久久久久动漫| 国产一级做a爰片久久毛片| 精品久久久久久久国产潘金莲 | 精品欧美一区二区三区久久久| 亚洲第一极品精品无码久久| 国产免费久久精品99re丫y| 久久天天躁狠狠躁夜夜不卡| 国产成人久久精品二区三区| 一级a性色生活片久久无少妇一级婬片免费放 | 亚洲国产一成人久久精品| 一本色综合久久| 国产精品亚洲综合久久| 国产精品成人久久久| 亚洲国产成人乱码精品女人久久久不卡 | 国产亚洲精久久久久久无码77777| 亚洲人成网站999久久久综合| 久久精品国产精品亚洲下载 |