中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Geometry Shaders(幾何造型Shader)

發布時間:2020-03-12 15:38:21 來源:網絡 閱讀:663 作者:萌谷王 欄目:游戲開發

周一到周五,每天一篇,北京時間早上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)

本日的翻譯就到這里,明天見,拜拜~~

第一時間獲取最新橋段,請關注東漢書院以及圖形之心公眾號

東漢書院,等你來玩哦

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

谷城县| 龙游县| 云龙县| 永丰县| 凯里市| 鄄城县| 霞浦县| 唐河县| 宜都市| 崇礼县| 无极县| 平利县| 临海市| 慈溪市| 年辖:市辖区| 彩票| 临邑县| 武山县| 延吉市| 永昌县| 扬中市| 莱州市| 长寿区| 花莲县| 阜城县| 阳城县| 滦平县| 兴隆县| 搜索| 大厂| 大理市| 长垣县| 密山市| 莫力| 井研县| 阳春市| 阜阳市| 阳泉市| 会宁县| 胶州市| 新竹市|