Direct3D Samples 阅读笔记之 BasicHLSL

来源:互联网 发布:中银淘宝信用卡怎么样 编辑:程序博客网 时间:2024/06/05 11:52

BasicHLSL Sample

Overview: This sample simply loads a mesh, creates an effect from a file, and then uses the effect to render the mesh. The effect that is used is a  simple vertex shader that animates the vertices based time.

要点:

回调函数OnFrameRender()中。

1. 清除renderTarget和zbuffer.

2. 绘制场景:pd3dDevice->BeginScene();

  {

    1. 计算MVP矩阵;

    2. 绘制指示光线方向的箭头,同时从UI控件中获取参数:光线方向 和 diffuse color;

    3. 将 光线方向、diffuse color、MVP、M、Time、Material Diffuse Color传入shader.

    4. 根据开启光线的数目选择相应的technique.

    5. 应用technique:

        {

        1. g_pEffect->Begin() 获取pass数目

        2. from 0 to passNum

            g_pEffect->BeginPass( i );

            g_pMesh->DrawSubset(0);

            g_pEffect->EndPass();

        }

        3. g_pEffect->End();

}

3. 结束绘制:pd3dDevice->EndScene()

----------------------------------------------------------------

fx文件:

vertex shader: This shader computes standard transform and lighting.

1. 基于时间和法线方向计算模型空间中顶点偏移后的位置;

2. 变换顶点坐标到齐次投影空间;

3. 变换法向量到世界空间;

4. 计算平行光照;

5. 传uv

pixel shader

1. 纹理查询

2. 计算最终输出颜色

0 0
原创粉丝点击