游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3599|回复: 3

问一下,在DX8中,如何对Texture进行半透时运算.

[复制链接]

45

主题

222

帖子

229

积分

中级会员

Rank: 3Rank: 3

积分
229
发表于 2003-11-11 10:58:00 | 显示全部楼层 |阅读模式
问一下,在DX8中,如何对Texture进行半透时运算.
最好不要再用DX7中的lock取数据作+-*/运算,太慢了.
DX8SDK中有一段代码,是c++的,我看不懂.


以下是DX8 SDK中的代码.Blend Two Textures Using a Constant Color
This example blends two texture maps, using the vertex color, to determine how much of each texture map color to use. The differences between this example and the previous example are as follows:

The vertex data structure, the FVF macro, and the vertex data include a second set of texture coordinates because there is a second texture. SetTexture is also called twice, using two texture stage states.
The shader file declares two texture registers and uses the linear interpolate (lrp) instruction to blend the two textures. The values of the diffuse colors determine the ratio of texture0 to texture1 in the output color.
Here is the sample code.

struct CUSTOMVERTEX
{
    FLOAT x, y, z;
        DWORD color;
    FLOAT tu1, tv1;
    FLOAT tu2, tv2;             // a second set of texture coordinates
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3D_FVF_DIFFUSE|D3DFVF_TEX2|D3DFVF_TEXCOORDSIZE4(0))

static CUSTOMVERTEX g_Vertices[]=
{
    //  x      y     z     color       u1    v1    u2    v2
    { -1.0f, -1.0f, 0.0f, 0xff0000ff, 1.0f, 1.0f, 1.0f, 1.0f },
    { +1.0f, -1.0f, 0.0f, 0xffff0000, 0.0f, 1.0f, 0.0f, 1.0f },
    { +1.0f, +1.0f, 0.0f, 0xffffff00, 0.0f, 0.0f, 0.0f, 0.0f },
    { -1.0f, +1.0f, 0.0f, 0xffffffff, 1.0f, 0.0f, 1.0f, 0.0f },
};

// Create a texture. This file is in the DirectX 8.1 media from the SDK download.
TCHAR  strPath[512];
LPDIRECT3DTEXTURE8      m_pTexture0, m_pTexture1;
DXUtil_FindMediaFile( strPath, _T("DX5_Logo.bmp"));
D3DUtil_CreateTexture( m_pd3dDevice, strPath, &m_pTexture0, D3DFMT_R5G6B5 );
DXUtil_FindMediaFile( strPath, _T("snow2.jpg"));
D3DUtil_CreateTexture( m_pd3dDevice, strPath, &m_pTexture1, D3DFMT_R5G6B5 );

// Load the textures stages.
m_pd3dDevice->SetTexture( 0, m_pTexture0 );
m_pd3dDevice->SetTexture( 1, m_pTexture1 );        // Use a second texture stage.

m_pd3dDevice->SetStreamSource( 0, m_pQuadVB, sizeof(CUSTOMVERTEX) );
m_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
m_pd3dDevice->SetPixelShader( m_hPixelShader );
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );

Contents of the file &quotixelShader5.txt"
ps.1.0              // pixel shader version
tex t0              // texture register t0 is loaded from texture stage 0
tex t1              // texture register t1 is loaded from texture stage 1
mov r1, t1          // move texture register1 into output register r1
lrp r0, v0, t0, r1  // linearly interpolate between t0 and r1 by a proportion
                    // specified in v0

The resulting output is as follows:

(这里省略结果图,是两张重叠的半透明图片.)

140

主题

1228

帖子

1233

积分

金牌会员

Rank: 6Rank: 6

积分
1233
QQ
发表于 2003-11-11 11:31:00 | 显示全部楼层

Re:问一下,在DX8中,如何对Texture进行半透时运算.

问个问题先!用alpha混合不行吗!好像d3d都有啊。

你贴得这段什么也没做,从PixelShader5.txt中创建并编译了一个pixelshader.
通知device使用pixelshader处理所有的点。绘图。完了。
pixelshader将设置的贴图0和贴图1混合。
采用的pixelshader才是完成的关键。

这个例子的关键是pixelshader.
不过我认为alpha混合也可以完成。
vb的billborad例子使用了alpha混合。

45

主题

222

帖子

229

积分

中级会员

Rank: 3Rank: 3

积分
229
 楼主| 发表于 2003-11-11 13:20:00 | 显示全部楼层

Re:问一下,在DX8中,如何对Texture进行半透时运算.

我就是看不懂程序的原理才问的.我只知道他的结果是两张图片混合了.

看来我也只好去看dx8的例子.
我试了场景的alpha的各种参数,都没做好alpha的效果出来.

140

主题

1228

帖子

1233

积分

金牌会员

Rank: 6Rank: 6

积分
1233
QQ
发表于 2003-11-11 14:55:00 | 显示全部楼层

Re:问一下,在DX8中,如何对Texture进行半透时运算.

呵呵!努力吧!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-4-27 22:13

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表