• <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 閱讀(456) 評論(0)  編輯 收藏 引用 所屬分類: c++
            色综合久久天天综线观看| 久久国产精品-久久精品| 久久久久久人妻无码| 99久久人妻无码精品系列| 久久精品无码一区二区三区免费| 久久婷婷五月综合97色直播| 97r久久精品国产99国产精| 久久国内免费视频| 色综合久久中文综合网| 无码国内精品久久人妻| 久久久久亚洲?V成人无码| 亚洲精品乱码久久久久久蜜桃图片| 色欲久久久天天天综合网| 精品久久久久久久| 2021国产精品久久精品| 久久亚洲中文字幕精品一区四| 久久无码高潮喷水| 久久久久亚洲AV无码专区桃色| 人妻久久久一区二区三区| 久久国产香蕉视频| 久久综合九色综合97_久久久| 久久无码中文字幕东京热| 国产综合精品久久亚洲| 久久九九有精品国产23百花影院| 久久精品无码免费不卡| 999久久久国产精品| 久久久久久国产a免费观看不卡| 亚洲精品乱码久久久久久蜜桃图片| 国产一区二区三精品久久久无广告| 久久九九兔免费精品6| 2020久久精品亚洲热综合一本| 久久国产视屏| 久久久WWW成人| 色婷婷狠狠久久综合五月| 99久久夜色精品国产网站| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久这里有精品视频| 伊人久久大香线蕉精品| 四虎国产永久免费久久| 精品免费久久久久国产一区| 精品久久久久久国产三级 |