随笔 - 505  文章 - 1034  trackbacks - 0
<2008年3月>
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345


子曾经曰过:编程无他,唯手熟尔!

常用链接

留言簿(94)

随笔分类(649)

随笔档案(505)

相册

BCB

Crytek

  • crymod
  • Crytek's Offical Modding Portal

Game Industry

OGRE

other

Programmers

Qt

WOW Stuff

搜索

  •  

积分与排名

  • 积分 - 894699
  • 排名 - 14

最新随笔

最新评论

阅读排行榜

评论排行榜


截图:





LPDIRECT3DVERTEXSHADER9         g_pVertexShader = NULL;
LPD3DXCONSTANTTABLE             g_pConstantTable 
= NULL;
LPDIRECT3DVERTEXDECLARATION9    g_pVertexDeclaration 
= NULL;


OnCreateDevice


    D3DVERTEXELEMENT9 decl[] =
    {
        { 
00, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
        D3DDECL_END()
    };

    V_RETURN( pd3dDevice
->CreateVertexDeclaration( decl, &g_pVertexDeclaration ) );

创建vertex shader

    // Assemble the vertex shader from the file
    V_RETURN( D3DXCompileShaderFromFile( strPath, NULL, NULL, "Ripple",
                                         
"vs_2_0", dwShaderFlags, &pCode,
                                         NULL, 
&g_pConstantTable ) );

    
// Create the vertex shader
    hr = pd3dDevice->CreateVertexShader( ( DWORD* )pCode->GetBufferPointer(),
                                         
&g_pVertexShader );



每帧设置shader里面的常量
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext )
{
    
// Update the camera's position based on user input 
    g_Camera.FrameMove( fElapsedTime );

    
// Set up the vertex shader constants
    D3DXMATRIXA16 mWorldViewProj;
    D3DXMATRIXA16 mWorld;
    D3DXMATRIXA16 mView;
    D3DXMATRIXA16 mProj;

    mWorld 
= *g_Camera.GetWorldMatrix();
    mView 
= *g_Camera.GetViewMatrix();
    mProj 
= *g_Camera.GetProjMatrix();

    mWorldViewProj 
= mWorld * mView * mProj;

    g_pConstantTable
->SetMatrix( DXUTGetD3D9Device(), "mWorldViewProj"&mWorldViewProj );
    g_pConstantTable
->SetFloat( DXUTGetD3D9Device(), "fTime", ( float
 )fTime );
}


Vertex Shader代码

HLSLwithoutEffects.vsh
float4x4 mWorldViewProj;  // World * View * Projection transformation
float fTime;              // Time parameter. This keeps increasing


//-----------------------------------------------------------------------------
// Vertex shader output structure
//-----------------------------------------------------------------------------
struct VS_OUTPUT
{
    float4 Position   : POSITION;   
// vertex position 
    float4 Diffuse    : COLOR0;     // vertex diffuse color
};


//-----------------------------------------------------------------------------
// Name: Ripple
// Type: Vertex shader                                      
// Desc: This shader ripples the vertices
//-----------------------------------------------------------------------------
VS_OUTPUT Ripple( in float2 vPosition : POSITION )
{
    VS_OUTPUT Output;
    
    
float fSin, fCos;   
    
float x = length( vPosition ) * sin( fTime ) * 15.0f;
    
    
// This HLSL intrinsic computes returns both the sine and cosine of x
    sincos( x, fSin, fCos );

    
// Change the y of the vertex position based on a function of time 
    
// and transform the vertex into projection space. 
    Output.Position = mul( float4( vPosition.x, fSin * 0.1f, vPosition.y, 1.0f ), mWorldViewProj );
    
    
// Output the diffuse color as function of time and 
    
// the vertex's object space position
    Output.Diffuse = 0.5f - 0.5f * fCos;
    
    
return Output;
}



posted on 2008-11-18 14:33 七星重剑 阅读(930) 评论(0)  编辑 收藏 引用 所属分类: Game GraphicsHLSL&ShaderMonkey

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理