Geometry Shaders(几何造型Shader)
admin
2023-02-11 08:40:05
0

周一到周五,每天一篇,北京时间早上7点准时更新~,中英文对照,一边学编程一边弹吉他,做一个奇葩码农!

请不要怀疑翻译是否有问题,我们的翻译工程师是蓝翔毕业的呢!

The geometry shader is logically the last shader stage in the front end(逻辑上来说,geometry shader是整个渲染管线的最后一个shader阶段), sitting after the vertex and tessellation stages and before the rasterizer(在vertex和tessellation之后,光栅化之前). The geometry shader runs once per primitive and has access to all of the input vertex data for all of the vertices that make up the primitive being processed(每个geometry shader一次处理一个图元,每次处理的时候,可以访问该图元的所有点的信息). The geometry shader is also unique among the shader stages in that it is able to increase or reduce the amount of data flowing through the pipeline in a programmatic way(geometry shader也是非常独特的,它可以通过编程的方式增加或者减少输出的图元). Tessellation shaders can also increase or decrease the amount of work in the pipeline, but only implicitly by setting the tessellation levelfor the patch(虽然tessellation也可以增加或者减少图元,但是只能隐式的通过一些设置去做). Geometry shaders, in contrast, include two functions—EmitVertex() and EndPrimitive()(相反,geometry shader有专门的函数去显示的增加或者减少发送给光栅化的图元的个数)— that explicitly produce vertices that are sent to primitive assembly and rasterization

Another unique feature of geometry shaders is that they can change the primitive mode mid-pipeline(另一个独特点就是geometry shader可以在中途改变图元的模式). For example, they can take triangles as input and produce a bunch of points or lines as output(比如他们可以以三角形作为输入图元,最后却输出点或者线), or even create triangles from independent points(甚至是通过输入的点创建更多三角形). An example geometry shader is shown in Listing 3.9.(Listing3.9显示了一个geometry shader的样本)

#version 450 core
layout (triangles) in;
layout (points, max_vertices = 3) out;
void main(void)
{
int i;
for (i = 0; i < gl_in.length(); i++)
{
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
}
Listing 3.9: Our first geometry shader

The shader shown in Listing 3.9 acts as another simple pass-through shader that converts triangles into points so that we can see their vertices(Listing 3.9显示了一个简单的geometry shader,它简单的将三角形转换成点). The first layout qualifier indicates that the geometry shader is expecting to see triangles as its input(第一个修饰符表示geometry shader希望得到三角形作为输入). The second layout qualifier tells OpenGL that the geometry shader will produce points and that the maximum number of points that each shader will produce will be three(第二个修饰符说明的是geometry shader输出的是点,并且每次最多输出3个点). In the main function, a loop runs through all of the members of the gl_in array, which is determined by calling its .length() function(在主函数里,有一个循环,会遍历gl_in数组,它的大小可以通过length接口获取)

We actually know that the length of the array will be three because we are processing triangles and every triangle has three vertices(其实我们已经知道数组大小是3了,因为我们输入的数据是三角形,并且三角形有三个点). The outputs of the geometry shader are again similar to those of a vertex shader(这些输出数据再一次变得更vertex shader的输出数据一样了). In particular, we write to gl_Position to set the position of the resulting vertex(特别是,我们使用gl_Position去设置顶点的位置). Next, we call EmitVertex(), which produces a vertex at the output of the geometry shader(然后我们调用EmitVertex来输出一个点). Geometry shaders automatically call EndPrimitive() at the end of your shader, so calling this function explicitly is not necessary in this example(geometry shader会自动调用EndPrimitive,所以你不必在shader中显示的去调用它). As a result of running this shader, three vertices will be produced and rendered as points(运行之后,将会有三个点被渲染出来)

By inserting this geometry shader into our simple one tessellated triangle example, we obtain the output shown in Figure 3.2(在把这个geometry shader塞到我们的渲染管线了之后,我们将会得到图3.2的结果). To create this image, we set the point size to 5.0 by calling glPointSize()(为了得到这个图片,我们把点的大小设置成了5.0,从而使得点能够大一点,且能够容易被看到). This makes the points large and highly visible

Geometry Shaders(几何造型Shader)

本日的翻译就到这里,明天见,拜拜~~

第一时间获取最新桥段,请关注东汉书院以及图形之心公众号

东汉书院,等你来玩哦

相关内容

热门资讯

德国总理:美国正在被伊朗羞辱 德国之声4月27日报道,德国总理默茨在访问一所学校时表示,在当前的持续冲突中,伊朗领导层正试图羞辱美...
理响中国|“长”歌以行,风云激... 光阴如梭,东方潮阔。这里是中国的长三角,世界的长三角。无论过去、现在还是未来,这片土地都因时代而生,...
白宫:特朗普及其国安团队开会讨... 新华社华盛顿4月27日电 美国白宫新闻秘书莱维特27日在记者会上证实,总统特朗普及其国家安全团队当天...
人民日报刊文:日本放开杀伤性武... 日本放开杀伤性武器出口推高地缘冲突风险(国际论坛)常思纯《人民日报》(2026年04月28日 第 0...
医疗保障法草案二审:明确生育保... 满足多样化健康保障需求本报记者 彭 波4月27日,医疗保障法草案二审稿提请十四届全国人大常委会第二十...
天津一景区发生自转旋翼机事故1... 澎湃新闻记者 吕新文中国民用航空华北地区管理局4月22日公布《豪客通航“10•1”天津长芦汉盐旅游区...
卡塔尔埃米尔与美国总统特朗普通... 当地时间24日,卡塔尔埃米尔塔米姆与美国总统特朗普通电话,重点就中东地区局势以及伊朗与美国谈判问题交...
男子30年前被扣押2859克黄... 澎湃新闻记者 王鑫家住辽宁省大连市的潘永嘉近日向澎湃新闻反映称,三十年前,他在大连周水子机场被盖州市...
商务部:取消反制欧盟两家金融机... 中华人民共和国商务部令二〇二六年 第1号鉴于欧盟已取消对中国两家金融机构的制裁措施,现公布《关于取消...
过去24小时共有5艘船只通过霍... 总台记者当地时间24日获悉,过去24小时内,共有5艘船只通过霍尔木兹海峡,其中包括一艘伊朗油轮。(总...