游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3567|回复: 11

Introduction to Vertex Shaders(请知道的提点小弟一下)

[复制链接]

4

主题

12

帖子

12

积分

新手上路

Rank: 1

积分
12
发表于 2004-12-15 13:10:00 | 显示全部楼层 |阅读模式
  
Microsoft DirectX 8.0 (C++)
Introduction to Vertex Shaders
Vertex shaders control the loading and processing of vertices. Microsoft® Direct3D® for Microsoft DirectX® 8.0 supports two types of vertex processing: programmable vertex processing and fixed-function vertex processing. In DirectX 8.0 documentation, the term vertex shader most often applies to the programmable mode, although the vertex shader API mechanism encompasses both types of functionality. Vertex shaders are defined at creation as using programmable vertex processing or fixed-function vertex processing. Once created, a vertex shader is referred to by its handle. Vertex shaders are not editable. To change a vertex shader, it must be destroyed and recreated.

Each vertex shader includes a function, which defines the operations to apply to each vertex, and a declaration, which defines the inputs to the shader, including how vertex elements in the input data streams are used by the shader.

Vertex processing performed by vertex shaders encompasses only operations applied to single vertices. The output of the vertex processing step is defined as individual vertices, each of which consists of a clip-space (???请问这里的clipsapce指的是什么?)position (x, y, z, and w) plus color, texture coordinate, fog intensity, and point size information. The projection and mapping of these positions to the viewport, the assembling of multiple vertices into primitives, and the clipping of primitives(???请问这里的clipping指的又是什么?) is done by a subsequent processing stage and is not under the control of the vertex shader.

Fixed function vertex processing provides the same functionality as in Direct3D for DirectX 7.0, including transformation and lighting, vertex blending, and texture coordinate generation. Unlike programmed vertex shaders, where the operations applied to vertices are defined within the shader, fixed-function vertex processing is controlled by a device state set by methods on IDirect3DDevice8, which set lights, transforms, and so on. It is still useful to have multiple fixed-function vertex shaders, because even though the function is fixed and shared, the declarations can vary. This enables feeding the fixed-function shader with differing layouts of multistream inputs.

The input vertex elements for fixed-function vertex processing have fixed semantics. Thus the declaration tags specify input vertex elements as coordinate, normal, color, and so on. The vertex outputs for fixed-function vertex shaders always include coordinates, diffuse and specular colors, and multiple texture coordinates, as required by the current device state settings for pixel processing.

Programmed vertex shaders have a function defined by an array of instructions to apply to each vertex. The mapping of the input vertex elements to the vertex input registers for programmed vertex shaders is defined in the shader declaration, but the input vertex elements do not have specific semantics about their use. The interpretation of the input vertex elements is up to the shader instructions. The vertex outputs for programmed vertex shaders are explicitly written to by instructions in the shader function.

For more information on the Direct3DX vertex shader assembler, see Vertex Shader Assembler Reference.

Built on Wednesday, October 04, 2000abcabcabcabc [em24] [em24] [em24]

9

主题

151

帖子

153

积分

注册会员

Rank: 2

积分
153
发表于 2004-12-15 16:39:00 | 显示全部楼层

Re:Introduction to Vertex Shaders(请知道的提点小弟一下)

clip-space:剪裁空间。就是用来绘图的,由gluPerspective设置的空间
clipping:剪裁,指剪裁操作

6

主题

444

帖子

457

积分

中级会员

Rank: 3Rank: 3

积分
457
发表于 2004-12-15 17:53:00 | 显示全部楼层

Re:Introduction to Vertex Shaders(请知道的提点小弟一下)

楼上的,人家问的是D3D……而且您的回答基本等于没回答
clip-space就是指投影空间,也就是顶点经过投影矩阵变换出来所在的4维齐次空间。是顶点经过线性变换到达的最后空间,它并不和屏幕空间线性对应,这中间需要经过一个齐次坐标除法,也就是x'=x/w,y'=y/w,z'=z/w。然后通过viewport mapping,就可以将x'y'线性对应到屏幕上的坐标,z值保留,在后期写入z-buffer。w值用作光栅化时的透视矫正。
剪切操作指的就是按照一定的规则将不必要的顶点舍弃掉。比如用户定义的剪切平面外的顶点,齐次坐标除法后z超出[0,1]范围或者x,y超出[-1,1]的顶点等等

4

主题

12

帖子

12

积分

新手上路

Rank: 1

积分
12
 楼主| 发表于 2004-12-16 09:51:00 | 显示全部楼层

Re:Introduction to Vertex Shaders(请知道的提点小弟一下)

根据hourousha所说
也就是说vertexshader(...output of the vertex processing step...)并没有对任何点做裁剪操作
这使我想到另一个问题,具体的内容在
http://bbs.gameres.com/showthread.asp?threadid=19636

6

主题

444

帖子

457

积分

中级会员

Rank: 3Rank: 3

积分
457
发表于 2004-12-16 13:07:00 | 显示全部楼层

Re:Introduction to Vertex Shaders(请知道的提点小弟一下)

vertexshader只能改变顶点的属性(至于是哪些属性,如何改变则要看你如何定义顶点结构和如何编写shader code)不能产生或者消灭任何顶点。
d3d流水线的结构应该是:顶点数据准备-〉vertexshader-〉后vertexshader处理-〉光栅化-〉pixelshader-〉后pixelshader处理
这样一个结构,vs是针对单一的独立的顶点进行处理。比如在vs之后,需要按照原先的DP或者DIP参数将处理后的顶点连接成三角形才能接下来进行backface culling等工作。简单来说,vs只是负责对每个顶点进行数学运算。

4

主题

12

帖子

12

积分

新手上路

Rank: 1

积分
12
 楼主| 发表于 2004-12-16 18:23:00 | 显示全部楼层

Re:Introduction to Vertex Shaders(请知道的提点小弟一下)

也就是说vs处理所有vertexbuffer中的顶点,而不管DP或DIP的参数,如果我的vertexbuffer里有100个顶点,而我只画10个三角形,vs还是要处理100个顶点?
另外我想问一下,一个vertexbuffer最多能容多少个顶点,比如说我想用一个vertexbuffer存放1024*1024个顶点,如果不行,有什么解决方法?
以上问题主要是我用D3D实现LOD地形时遇到的,我想用一个固定的VB存放所有全分辨率的顶点,然后再根据一定的规则填充一个IB,每一帧都按规则重新填充IB,再由IB画三角形,但如果地形的尺寸很大,如1025*1025,2049*2049,那VB中就要存放好多点,一个VB能放这么多的点吗?如果不行,有什么解决方法?

6

主题

444

帖子

457

积分

中级会员

Rank: 3Rank: 3

积分
457
发表于 2004-12-16 21:53:00 | 显示全部楼层

Re:Introduction to Vertex Shaders(请知道的提点小弟一下)

vs当然只处理dp或者dip参数所表示的需要绘制的顶点……都处理……你当D3D和GPU是冤大头呐?

6

主题

444

帖子

457

积分

中级会员

Rank: 3Rank: 3

积分
457
发表于 2004-12-16 22:02:00 | 显示全部楼层

Re:Introduction to Vertex Shaders(请知道的提点小弟一下)

另外,使用静态huge vb+动态IB并不见得是个好方法。具体的你可以试一试

36

主题

1047

帖子

1147

积分

金牌会员

Rank: 6Rank: 6

积分
1147
发表于 2004-12-16 23:33:00 | 显示全部楼层

Re:Introduction to Vertex Shaders(请知道的提点小弟一下)

hourousha 关于 clip space 那段讲得很好!

35

主题

340

帖子

350

积分

中级会员

Rank: 3Rank: 3

积分
350
发表于 2004-12-17 17:18:00 | 显示全部楼层

Re: Re:Introduction to Vertex Shaders(请知道的提点小弟一下)

hourousha: Re:Introduction to Vertex Shaders(请知道的提点小弟一下)

d3d流水线的结构应该是:顶点数据准备-〉vertexshader-〉后vertexshader处理-〉光栅化-〉pixelshader-〉后pixelshader处理。。。


我以前一直以为光栅化是最后阶段呢

ps 那pixelshader是不是和ddraw中锁定后修改后台缓冲一样。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-12-23 19:10

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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