青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

高級著色語言HLSL入門(3)

新建網頁 1

SetMatrixTranspose—Used to set a transposed 4 × 4 matrix. Sample call:

               
       

        D3DXMATRIX M();

       

        D3DXMatrixTranspose(&M, &M);

       

        ConstTable->SetMatrixTranspose(Device, handle, &M);

Sets a transposed matrix.

HRESULT SetMatrixTranspose(  LPDIRECT3DDEVICE9 pDevice,  D3DXHANDLE hConstant,  CONST D3DXMATRIX* pMatrix);

Parameters

   
pDevice
   
[in] Pointer to an IDirect3DDevice9 interface,     representing the device associated with the constant table.
   
hConstant
   
[in] Unique identifier to the matrix of constants.   
   
pMatrix
   
[in] Pointer to a transposed matrix.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

 

SetMatrixTransposeArray—Used to set an array of 4 × 4 transposed matrices. Sample call:

               
       

        D3DXMATRIX M[4];

       

        //         ...Initialize matrices and transpose them.

       

        ConstTable->SetMatrixTransposeArray(Device, handle, M, 4);

Sets an array of transposed matrices.

HRESULT SetMatrixTransposeArray(  LPDIRECT3DDEVICE9 pDevice,  D3DXHANDLE hConstant, 
 CONST D3DXMATRIX* pMatrix,  UINT Count);

Parameters

   
pDevice
   
[in] Pointer to an IDirect3DDevice9 interface,     representing the device associated with the constant table.
   
hConstant
   
[in] Unique identifier to the array of matrix     constants.
   
pMatrix
   
[in] Array of transposed matrices.
   
Count
   
[in] Number of matrices in the array.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

 

SetMatrixTransposePointerArray—Used to set an array of pointers to 4 × 4 transposed matrices. Sample call:

               
       

        D3DXMATRIX* M[4];

       

        //         ...Allocate,initialize matrix pointers and transpose them.

       

        ConstTable->SetMatrixTransposePointerArray(Device, handle, M, 4);

Sets an array of pointers to transposed matrices.

HRESULT SetMatrixTransposePointerArray(  LPDIRECT3DDEVICE9 pDevice,  D3DXHANDLE hConstant,  
CONST D3DXMATRIX** ppMatrix,  UINT Count);

Parameters

   
pDevice
   
[in] Pointer to an IDirect3DDevice9 interface,     representing the device associated with the constant table.
   
hConstant
   
[in] Unique identifier to the array of matrix     constants.
   
ppMatrix
   
[in] Array of pointers to transposed matrices.   
   
Count
   
[in] Number of matrices in the array.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

Remarks

A transposed matrix contains column-major data; that is, each vector is contained in a column.

 

SetVector—Used to set a variable of type D3DXVECTOR4. Sample call:

               
       

        D3DXVECTOR4 v(1.0f, 2.0f, 3.0f, 4.0f);

       

        ConstTable->SetVector(Device, handle, &v);

Sets a 4D vector.

HRESULT SetVector(  LPDIRECT3DDEVICE9 pDevice,  D3DXHANDLE hConstant,  CONST D3DXVECTOR4* pVector);

Parameters

   
pDevice
   
[in] Pointer to an IDirect3DDevice9 interface,     representing the device associated with the constant table.
   
hConstant
   
[in] Unique identifier to the vector constant.   
   
pVector
   
[in] Pointer to a 4D vector.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

 

SetVectorArray—Used to set a variable that is a vector array. Sample call:

               
       

        D3DXVECTOR4 v[3];

       

        //         ...Initialize vectors

       

        ConstTable->SetVectorArray(Device, handle, v, 3);

Sets an array of 4D vectors.

HRESULT SetVectorArray(  LPDIRECT3DDEVICE9 pDevice,  D3DXHANDLE hConstant,  
CONST D3DXVECTOR4* pVector,  UINT Count);

Parameters

   
pDevice
   
[in] Pointer to an IDirect3DDevice9 interface,     representing the device associated with the constant table.
   
hConstant
   
[in] Unique identifier to the array of vector     constants.
   
pVector
   
[in] Array of 4D vectors.
   
Count
   
[in] Number of vectors in the array.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

 

SetValue—Used to set an arbitrarily sized type, such as a structure. In the sample call, we use SetValue to set a D3DXMATRIX:

               
       

        D3DXMATRIX M();

       

        ConstTable->SetValue(Device, handle, (void*)&M, sizeof(M));

Sets the contents of the buffer to the constant table.

HRESULT SetValue(  LPDIRECT3DDEVICE9 pDevice,  D3DXHANDLE hConstant,  LPCVOID pData,  UINT Bytes);

Parameters

   
pDevice
   
[in] Pointer to an IDirect3DDevice9 interface,     representing the device associated with the constant table.
   
hConstant
   
[in] Unique identifier to a constant.
   
pData
   
[in] Buffer containing data.
   
Bytes
   
[in] Size of the buffer, in bytes.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

 

16.2.1.3 設置常量默認值

下一個方法就是設置常量的默認值,這些默認值在聲明時初始化。這個方法應該在應用程序建立(setup)期間被調用一次 (called once)。

               
       

        HRESULT         ID3DXConstantTable::SetDefaults(

       

             LPDIRECT3DDEVICE9         pDevice

       

        );

pDevice——關聯到常量表的設備的指針。

Sets the constants to their default values. The default values are declared in the variable declarations in the shader.

HRESULT SetDefaults(  LPDIRECT3DDEVICE9 pDevice);

Parameters

   
pDevice
   
[in] Pointer to an IDirect3DDevice9 interface,     representing the device associated with the constant table.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

 

16.2.2 編譯HLSL著色器

我們可以編譯一個著色器——用我們已保存的著色器的文本文件——使用下列函數:

               
       

        HRESULT         D3DXCompileShaderFromFile(

       

             LPCSTR                       pSrcFile,

       

             CONST D3DXMACRO*             pDefines,

       

             LPD3DXINCLUDE                pInclude,

       

             LPCSTR                       pFunctionName,

       

             LPCSTR                       pTarget,

       

             DWORD                        Flags,

       

             LPD3DXBUFFER*                ppShader,

       

             LPD3DXBUFFER*                ppErrorMsgs,

       

             LPD3DXCONSTANTTABLE*         ppConstantTable

       

        );

 

pSrcFile——要編譯的包含著色器源代碼的文本文件的文件名

pDefines——參數可選,這里指定為空。

pInclude——ID3DXInclude接口指針。這個接口被設計成由應用程序實現,所以我們可以重載默認include的行為。通常默認行為就可以了,而且我們可以通過將其指定為空忽略此參數。

pFunctionName——指定入口點函數名的字符串。例如,如果著色器的入口點函數叫做Main,我們可以給此參數傳遞“Main”。

pTarget——指定要編譯成的HLSL著色器源文件的版本的字符串。有效的頂點著色器版本是:vs_1_1, vs_2_0, vs_2_sw。有效的像素著色器版本是2.0,我們可以給此參數傳遞vs_2_0

備注:有編譯不同版本著色器的能力,是HLSL與匯編語言比的主要優勢。用HLSL我們只需為需要的目標簡單的重新編譯,便可快速移植著色器到不同的版本。使用匯編,我們可能需要手動移植代碼。

Flags——可選的編譯標記,指定為0標識沒有標記。有效的選項是:

D3DXSHADER_DEBUG——通知編譯器寫入調試信息

D3DXSHADER_SKIPVALIDATION——通知編譯器不要做任何代碼檢查。此項僅用于你已知著色器能夠工作時。

D3DXSHADER_SKIPOPTIMIZATION——通知編譯器不要執行任何代碼優化。實踐中,這個選項應該僅用于調試,因為這種情況下你不希望編譯器以任何方式修改代碼。

ppShader——返回已編譯的著色器代碼的ID3DXBuffer指針。這個已編譯過的著色器代碼將作為另一個實際創建頂點/像素著色器函數的參數。

ppErrorMsgs——返回包含錯誤碼和錯誤消息字符串的ID3DXBuffer指針

ppConstantTable——返回包含此著色器常量表數據的ID3DXConstantTable指針

Compile a shader file.

HRESULT D3DXCompileShaderFromFile(  LPCSTR pSrcFile,  CONST D3DXMACRO* pDefines,  LPD3DXINCLUDE pInclude,  
LPCSTR pFunctionName,  LPCSTR pProfile,  DWORD Flags,  LPD3DXBUFFER* ppShader, 
LPD3DXBUFFER *
ppErrorMsgs,  LPD3DXCONSTANTTABLE * ppConstantTable);

Parameters

   
pSrcFile
   
[in] Pointer to a string that specifies the     filename.
   
pDefines
   
[in] An optional NULL terminated array of     D3DXMACRO structures. This value may be NULL.
   
pInclude
   
[in] Optional interface pointer, ID3DXInclude, to     use for handling #include directives. If this value is NULL, #includes will     either be honored when compiling from a file or will cause an error when     compiled from a resource or memory.
   
pFunctionName
   
[in] Pointer to the shader entry point function     where execution begins.
   
pProfile
   
[in] Pointer to a shader profile which determines     the shader instruction set. See D3DXGetVertexShaderProfile or     D3DXGetPixelShaderProfile for a list of the profiles available.
   
Flags
   
[in] Compile options identified by various flags.     The Direct3D 10 HLSL compiler is now the default. See D3DXSHADER Flags for     details.
   
ppShader
   
[out] Returns a buffer containing the created     shader. This buffer contains the compiled shader code, as well as any     embedded debug and symbol table information.
   
ppErrorMsgs
   
[out] Returns a buffer containing a listing of     errors and warnings that were encountered during the compile. These are the     same messages the debugger displays when running in debug mode. This value     may be NULL.
   
ppConstantTable
   
[out] Returns an ID3DXConstantTable interface,     which can be used to access shader constants. This value may be NULL.    

Return Values

If the function succeeds, the return value is D3D_OK. If the function fails, the return value can be one of the following: D3DERR_INVALIDCALL, D3DXERR_INVALIDDATA, E_OUTOFMEMORY.

這里是一個調用D3DXCompileShaderFromFile的例子:

        // compile shader
   

        ID3DXBuffer*    shader_buffer;
        ID3DXBuffer*    error_buffer;
   
        HRESULT hr = D3DXCompileShaderFromFile("VertexShader.cxx", NULL, NULL, "main", "vs_1_1", D3DXSHADER_DEBUG,
                                               &shader_buffer, &error_buffer, &g_constant_table);
   
        
// output any error messages
   
    if(error_buffer)
        {
            MessageBox(NULL, (
char*)error_buffer->GetBufferPointer(), "ERROR", MB_OK);
            safe_release<ID3DXBuffer*>(error_buffer);
        }
   
        
if(FAILED(hr))
        {
            MessageBox(NULL, "D3DXCreateEffectFromFile() - FAILED", "ERROR", MB_OK);
            
return false;
        }

示例截圖:


執行程序:

      /**************************************************************************************************
      Demonstrates transforming an object by the view and projection matrices, and setting 
      the vertex color using a vertex shader.  
   
      You will have to switch to the REF device if your hardware does not support shaders.  
      Or you can use software vertex processing: D3DCREATE_SOFTWARE_VERTEXPROCESSING. 
     **************************************************************************************************/

   
    #include "d3dUtility.h"
   
    #pragma warning(disable : 4100)
   
   
const int WIDTH  = 640;
   
const int HEIGHT = 480;
   
    IDirect3DDevice9*        g_device;
    ID3DXMesh*                g_teapot;
    IDirect3DVertexShader9* g_vertex_shader;
    ID3DXConstantTable*        g_constant_table;
   
    D3DXHANDLE                g_view_proj_handle;
    D3DXMATRIX                g_proj_matrix;
   
   
    ////////////////////////////////////////////////////////////////////////////////////////////////////
   

   
bool setup()
    {    
        D3DXCreateTeapot(g_device, &g_teapot, NULL);
   
        
// compile shader
   

        ID3DXBuffer*    shader_buffer;
        ID3DXBuffer*    error_buffer;
   
        HRESULT hr = D3DXCompileShaderFromFile("VertexShader.cxx", NULL, NULL, "main", "vs_1_1", D3DXSHADER_DEBUG,
                                               &shader_buffer, &error_buffer, &g_constant_table);
   
        
// output any error messages
   
    if(error_buffer)
        {
            MessageBox(NULL, (
char*)error_buffer->GetBufferPointer(), "ERROR", MB_OK);
            safe_release<ID3DXBuffer*>(error_buffer);
        }
   
        
if(FAILED(hr))
        {
            MessageBox(NULL, "D3DXCreateEffectFromFile() - FAILED", "ERROR", MB_OK);
            
return false;
        }
   
        hr = g_device->CreateVertexShader((DWORD*) shader_buffer->GetBufferPointer(), &g_vertex_shader);
   
        
if(FAILED(hr))
        {
            MessageBox(NULL, "CreateVertexShader - FAILED", "ERROR", MB_OK);
            
return false;
        }
   
        safe_release<ID3DXBuffer*>(shader_buffer);
   
        g_view_proj_handle = g_constant_table->GetConstantByName(NULL, "g_view_proj_matrix");
        g_constant_table->SetDefaults(g_device);
   
        
// set the projection matrix
   
        D3DXMatrixPerspectiveFovLH(&g_proj_matrix, D3DX_PI/4.0f, (float)WIDTH/HEIGHT, 1.0f, 1000.0f);
        
        g_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
        
        
return true;
    }
   
   
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
   

   
void cleanup()
    {    
        safe_release<ID3DXMesh*>(g_teapot);
        safe_release<IDirect3DVertexShader9*>(g_vertex_shader);
        safe_release<ID3DXConstantTable*>(g_constant_table);
    }
   
   
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
   

   
bool display(float time_delta)
    {    
        
static float angle  = (3.0f * D3DX_PI) / 2.0f;
        
static float height = 5.0f;
   
        
if(GetAsyncKeyState(VK_LEFT) & 0x8000f)
            angle -= 0.5f * time_delta;
   
        
if(GetAsyncKeyState(VK_RIGHT) & 0x8000f)
            angle += 0.5f * time_delta;
   
        
if(GetAsyncKeyState(VK_UP) & 0x8000f)
            height += 5.0f * time_delta;
   
        
if(GetAsyncKeyState(VK_DOWN) & 0x8000f)
            height -= 5.0f * time_delta;
   
        D3DXVECTOR3 position(cosf(angle) * 10.0f, height, sinf(angle) * 10.0f);
        D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
        D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
   
        D3DXMATRIX view_matrix;
        D3DXMatrixLookAtLH(&view_matrix, &position, &target, &up);
        
        D3DXMATRIX view_proj_matrix = view_matrix * g_proj_matrix;
        g_constant_table->SetMatrix(g_device, g_view_proj_handle, &view_proj_matrix);
        
        
// render now
   

        g_device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
   
        g_device->BeginScene();
   
        g_device->SetVertexShader(g_vertex_shader);
        g_teapot->DrawSubset(0);
        
        g_device->EndScene();
   
        g_device->Present(NULL, NULL, NULL, NULL);
   
        
return true;
    }
   
   
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
   

    LRESULT CALLBACK wnd_proc(HWND hwnd, UINT msg, WPARAM word_param, LPARAM long_param)
    {
        
switch(msg)
        {
        
case WM_DESTROY:
            PostQuitMessage(0);
            
break;
   
        
case WM_KEYDOWN:
            
if(word_param == VK_ESCAPE)
                DestroyWindow(hwnd);
   
            
break;
        }
   
        
return DefWindowProc(hwnd, msg, word_param, long_param);
    }
   
   
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
   

   
int WINAPI WinMain(HINSTANCE inst, HINSTANCE, PSTR cmd_line, int cmd_show)
    {
        
if(! init_d3d(inst, WIDTH, HEIGHT, true, D3DDEVTYPE_HAL, &g_device))
        {
            MessageBox(NULL, "init_d3d() - failed.", 0, MB_OK);
            
return 0;
        }
   
        
if(! setup())
        {
            MessageBox(NULL, "Steup() - failed.", 0, MB_OK);
            
return 0;
        }
   
        enter_msg_loop(display);
   
        cleanup();
        g_device->Release();
   
        
return 0;
    }

下載源程序


posted on 2008-04-05 16:45 lovedday 閱讀(3213) 評論(0)  編輯 收藏 引用

公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美国产91| 亚洲国产日本| 伊人激情综合| 亚洲国产老妈| 亚洲黄色免费| 99精品视频免费观看视频| 日韩视频在线一区| 牛人盗摄一区二区三区视频| 久久久久久网址| 另类国产ts人妖高潮视频| 另类天堂av| 欧美色精品在线视频| 国产精品爽爽ⅴa在线观看| 国产亚洲一区二区三区在线观看 | 欧美日韩精品中文字幕| 国产精品第13页| 国产自产2019最新不卡| 亚洲精品网址在线观看| 欧美亚洲色图校园春色| 美腿丝袜亚洲色图| 中国成人亚色综合网站| 欧美在线视频不卡| 欧美人与禽猛交乱配| 蜜臀a∨国产成人精品| 亚洲国产综合91精品麻豆| 精品1区2区3区4区| 亚洲久久一区二区| 欧美中文字幕在线观看| 欧美成人激情在线| 中文欧美日韩| 欧美国产专区| 黄色国产精品一区二区三区| 亚洲深夜福利视频| 欧美国产日韩在线| 欧美影院视频| 国产精品久久久久久久免费软件| 国产一区二区中文| 亚洲大胆视频| 久久国产精品久久国产精品| 亚洲精品中文字幕在线| 欧美亚洲免费高清在线观看| 农夫在线精品视频免费观看| 国产欧美日韩在线播放| 一本色道久久88精品综合| 久久中文精品| 久久精品道一区二区三区| 国产精品久久久久久久久久直播| 亚洲毛片播放| 噜噜噜在线观看免费视频日韩| 久久久精品国产免大香伊| 欧美日韩mv| 伊人久久大香线蕉综合热线 | 亚洲国产成人av| 国产精品青草综合久久久久99| 国产精品一区二区黑丝| 最新国产成人av网站网址麻豆| 久久免费视频一区| 欧美一区二区大片| 国产精品亚洲一区二区三区在线| 亚洲精品在线视频| 欧美激情成人在线视频| 免费观看欧美在线视频的网站| 悠悠资源网亚洲青| 欧美激情欧美狂野欧美精品| 久久久精品国产免大香伊 | 亚洲欧美日韩国产精品| 欧美三级免费| 亚洲欧美日韩国产中文| 亚洲伊人色欲综合网| 国产精品国产三级国产aⅴ浪潮 | 99一区二区| 亚洲人被黑人高潮完整版| 免费看成人av| 一区二区日韩免费看| 在线中文字幕不卡| 国产美女诱惑一区二区| 久久久久成人网| 久久久久99| 亚洲国产欧美一区二区三区久久 | 亚洲黄网站在线观看| 欧美激情一区二区三区蜜桃视频| 99精品99| 亚洲欧美电影院| 韩国一区电影| 亚洲精品老司机| 国产精品乱码妇女bbbb| 久久一区二区三区av| 欧美国产日产韩国视频| 性娇小13――14欧美| 久久手机精品视频| 亚洲无限乱码一二三四麻| 欧美一区二区三区视频免费播放| 亚洲第一视频| 国产精品99久久99久久久二8 | 在线观看91精品国产麻豆| 亚洲电影在线看| 国产精品外国| 亚洲精品国产视频| 国产视频观看一区| 亚洲国产视频一区二区| 国产欧美va欧美va香蕉在| 亚洲福利在线视频| 国产亚洲欧美一区在线观看| 亚洲欧洲综合| 亚洲第一福利视频| 欧美一区二区黄| 国产精品一二一区| 欧美成人免费在线视频| 国产精品九九| 欧美黄色一级视频| 国产在线精品二区| 亚洲一区黄色| 亚洲图片自拍偷拍| 欧美ed2k| 玖玖在线精品| 国产农村妇女精品| 亚洲夜晚福利在线观看| 日韩午夜高潮| 久久综合一区二区| 久久国产精品久久w女人spa| 欧美午夜免费影院| 亚洲久久在线| 亚洲麻豆av| 欧美国产成人精品| 欧美粗暴jizz性欧美20| 一区二区三区无毛| 欧美专区中文字幕| 久久激情中文| 国产自产女人91一区在线观看| 亚洲色图制服丝袜| 亚洲在线观看免费| 国产精品久久久一本精品| 一区二区免费在线观看| 亚洲伊人第一页| 国产精品丝袜91| 亚洲欧美成人一区二区三区| 亚洲尤物在线视频观看| 欧美色道久久88综合亚洲精品| 日韩一区二区精品视频| 亚洲伊人久久综合| 国产精品一区免费视频| 午夜欧美精品| 免费成人高清| 亚洲精品久久久久| 欧美日韩亚洲视频一区| 亚洲在线日韩| 久久久久久国产精品mv| 一区福利视频| 欧美精品成人| 一区二区三区欧美日韩| 欧美在线观看视频| 亚洲成人在线视频播放| 欧美不卡高清| 一卡二卡3卡四卡高清精品视频| 这里只有精品视频在线| 国产精品久久久一本精品| 亚洲欧美日韩视频一区| 久久影视精品| 日韩亚洲一区在线播放| 国产精品男女猛烈高潮激情| 亚洲伊人久久综合| 女同性一区二区三区人了人一| 最新国产成人av网站网址麻豆 | 在线观看国产成人av片| 欧美精品色一区二区三区| 在线视频亚洲一区| 久久精品一级爱片| 日韩一级黄色av| 国产伦理一区| 欧美不卡视频一区发布| 亚洲午夜免费福利视频| 猫咪成人在线观看| 亚洲永久网站| 91久久久一线二线三线品牌| 国产精品日韩在线一区| 免费看的黄色欧美网站| 亚洲一区网站| 99视频日韩| 黄色工厂这里只有精品| 欧美网站大全在线观看| 久久琪琪电影院| 亚洲综合精品四区| 91久久在线| 免费成人激情视频| 性欧美在线看片a免费观看| 日韩午夜av电影| 亚洲国产成人精品女人久久久 | 久久精品视频在线免费观看| 99精品欧美一区二区蜜桃免费| 久久久免费av| 亚洲欧美中文日韩在线| 亚洲精品久久久蜜桃| 一区在线观看视频| 国产伦精品一区二区三区四区免费 | 欧美成人精品一区二区| 欧美在线免费视频| 亚洲一区二区综合| 一区二区高清在线| 999在线观看精品免费不卡网站| 欧美黄色日本|