游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2034|回复: 5

关于纹理坐标转换的一个问题,请赐教.

[复制链接]

30

主题

126

帖子

126

积分

注册会员

Rank: 2

积分
126
发表于 2007-1-20 11:51:00 | 显示全部楼层 |阅读模式
这是DX9帮助文件中d3d教程教程5中的一段代码(DirectX Graphics->Direct3D9->Tutorials and Samples->Tutorials->Tutorial 5: Using Texture Maps->Step 3 - Rendering the Scene
):
// Setup texture. Using textures introduces the texture stage states, which
    //   govern how textures get blended together (in the case of multiple
    //   textures) and lighting information. In this case, you are modulating
    //   (blending) your texture with the diffuse color of the vertices.
    g_pd3dDevice->SetTexture( 0, g_pTexture );
    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );

#ifdef SHOW_HOW_TO_USE_TCI
    // Note: To use Direct3D texture coordinate generation, use the stage state
    // D3DTSS_TEXCOORDINDEX, as shown below. In this example, you are using
    // the position of the vertex in camera space to generate texture
    // coordinates. The tex coord index (TCI) parameters are passed into a
    // texture transform, which is a 4x4 matrix that transforms the x,y,z
    // TCI coordinates into tu, tv texture coordinates.

    // In this example, the texture matrix is set up to
    // transform the texture from (-1,+1) position coordinates to (0,1)
    // texture coordinate space:
    //    tu =  0.5*x + 0.5
    //    tv = -0.5*y + 0.5
    D3DXMATRIXA16 mat;
    mat._11 = 0.25f; mat._12 = 0.00f; mat._13 = 0.00f; mat._14 = 0.00f;
    mat._21 = 0.00f; mat._22 =-0.25f; mat._23 = 0.00f; mat._24 = 0.00f;
    mat._31 = 0.00f; mat._32 = 0.00f; mat._33 = 1.00f; mat._34 = 0.00f;
    mat._41 = 0.50f; mat._42 = 0.50f; mat._43 = 0.00f; mat._44 = 1.00f;

    g_pd3dDevice->SetTransform( D3DTS_TEXTURE0, &mat );
    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS,
                    D3DTTFF_COUNT2 );
    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX,
                    D3DTSS_TCI_CAMERASPACEPOSITION );
#endif

提问:
1.为何要进行transform the texture from (-1,+1) position coordinates to (0,1) 操作?什么时侯需要进行这种转换工作?上文所指的 (-1,+1) position coordinates 是什么东西?找了一上午的资料,还是没搞明白。
2.请问各位有没有纹理、多重纹理、纹理混合方面的资料啊,书上和帮助文件里基本上都用简短的代码来讲一些概念。大家有没有好一点的这方面的资料啊,从昨天郁闷到现在,我现在相当郁闷哪。
如能赐教,本人感激不尽。

30

主题

126

帖子

126

积分

注册会员

Rank: 2

积分
126
 楼主| 发表于 2007-1-20 17:14:00 | 显示全部楼层

Re:关于纹理坐标转换的一个问题,请赐教.

谁能给点提示啊.UP!

30

主题

126

帖子

126

积分

注册会员

Rank: 2

积分
126
 楼主| 发表于 2007-1-20 21:18:00 | 显示全部楼层

Re:关于纹理坐标转换的一个问题,请赐教.

现在人怎么这么少啊,知道的请提示一下,plz!

8

主题

284

帖子

296

积分

中级会员

Rank: 3Rank: 3

积分
296
QQ
发表于 2007-1-21 17:47:00 | 显示全部楼层

Re:关于纹理坐标转换的一个问题,请赐教.

我以为,转换到0,1空间是为了方便投影纹理到屏幕空间。
详细的请看DX SDK文档——Texture Coordinates

你实例的例子就去找找DX8.1 的一个例子叫“MFC TEX”。

35

主题

1735

帖子

1739

积分

金牌会员

Rank: 6Rank: 6

积分
1739
QQ
发表于 2007-1-21 19:56:00 | 显示全部楼层

Re:关于纹理坐标转换的一个问题,请赐教.

DX9也有这个例子的。

1

主题

15

帖子

25

积分

注册会员

Rank: 2

积分
25
发表于 2007-1-22 13:09:00 | 显示全部楼层

Re:关于纹理坐标转换的一个问题,请赐教.

注释的意思大概就是:把(-1,+1)的位置坐标转换成(0,1)的纹理坐标。因为纹理坐标值都是必须在(0,1)范围内的。
我也是初学,不知讲的对否?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-1-26 06:56

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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