• <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++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              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 閱讀(459) 評論(0)  編輯 收藏 引用 所屬分類: c++
            久久久久国产精品熟女影院| 久久成人精品| 亚洲欧美国产日韩综合久久| 亚洲中文字幕久久精品无码喷水| 亚洲婷婷国产精品电影人久久| 伊人久久五月天| 精品一区二区久久| 色欲综合久久躁天天躁| 国内精品久久国产大陆| 亚洲国产成人久久精品99 | 国产精品一区二区久久国产| 久久人人爽人人爽人人片AV麻豆| 99国产欧美久久久精品蜜芽| 久久国产劲爆AV内射—百度| 国产精品嫩草影院久久| 国产69精品久久久久777| 久久久久99精品成人片牛牛影视| 久久久久久人妻无码| 国产免费久久精品99久久| 人人狠狠综合久久88成人| 精品伊人久久久| 国内精品久久久久影院亚洲| 久久夜色tv网站| 久久国产精品二国产精品| 丰满少妇人妻久久久久久| 亚洲国产精品无码久久久秋霞2 | 99精品久久精品| 精品综合久久久久久98| 狠狠色丁香久久婷婷综合图片 | 国产国产成人久久精品| 国内精品久久久久久99蜜桃| 久久亚洲精精品中文字幕| 日韩人妻无码精品久久免费一| 国产精品乱码久久久久久软件| 亚洲欧洲精品成人久久曰影片| 99久久精品久久久久久清纯| 久久国产精品成人免费| 99久久成人国产精品免费| AV狠狠色丁香婷婷综合久久| 99久久精品午夜一区二区| 国产精品久久久久久|