• <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 閱讀(458) 評論(0)  編輯 收藏 引用 所屬分類: c++
            国产999精品久久久久久| 亚洲欧美日韩中文久久| 99久久婷婷国产一区二区| 成人国内精品久久久久一区| 99精品久久久久中文字幕| 99久久免费国产精品| 精品久久人人爽天天玩人人妻| 亚洲国产成人精品女人久久久 | 亚洲人成网站999久久久综合 | 精品久久人人妻人人做精品| 色悠久久久久久久综合网| 久久精品中文无码资源站| 麻豆精品久久久久久久99蜜桃| 久久成人国产精品| 香蕉久久久久久狠狠色| 亚洲国产精品成人久久| 久久国产精品久久久| 久久精品国产清自在天天线| 亚洲日韩欧美一区久久久久我 | 中文字幕成人精品久久不卡| 久久香综合精品久久伊人| 久久夜色tv网站| 中文字幕精品无码久久久久久3D日动漫| 国色天香久久久久久久小说| 日本高清无卡码一区二区久久 | 香蕉久久影院| 香蕉久久夜色精品国产小说| 亚洲中文字幕久久精品无码APP| 精品国产91久久久久久久a| 2021精品国产综合久久| 中文无码久久精品| 亚洲精品美女久久久久99小说 | 伊人久久大香线焦综合四虎| 色妞色综合久久夜夜| 亚洲精品第一综合99久久| 天天久久狠狠色综合| 国内精品九九久久久精品| 久久久久久精品免费看SSS| 伊人久久无码精品中文字幕| 久久综合久久性久99毛片| 亚洲日本va午夜中文字幕久久|