[英]Passing Data Through GLSL Shaders
我在通過着色器(尤其是幾何着色器)傳遞數據時遇到了一些麻煩。 我以前從未使用過Geometry Shader,因此在理解數據傳遞方式時遇到了一些麻煩。
基本上,在“幾何”着色器之前,我只需使用輸入/輸出限定符將數據從“頂點着色器”傳遞到“片段”。 就像我有:
頂點着色器!
out vec3 worldNormal;
out vec3 worldView;
片段着色器:
in vec3 ex_worldNorm;
in vec3 ex_worldView;
因此,對於“幾何着色器”,我是否必須執行類似的操作才能傳遞數據?
in vec3 ex_worldNorm[];
in vec3 ex_worldView[];
out vec3 ex_worldNorm[];
out vec3 ex_worldNorm[];
我的問題是,如何在每個着色器之間正確傳遞數據? 就像,這是這樣做的方式嗎? (因為它對我不起作用!)
輸入的無邊界數組對於Geomtery着色器是正確的(大小將由布局限定符中的輸入類型確定),但是輸出不能是數組。
通過將值寫入所有輸出變量,然后調用EmitVertex (...)
來一次輸出一個頂點。 在EmitVertex (...)
調用EmitVertex (...)
之間未寫入的任何輸出變量都將是不確定的。
#version 330
layout (triangles) in; // This will automatically size your two arrays to 3, and also
// defines the value of `gl_in.length ()`
in vec3 worldNormal [];
in vec3 worldView [];
// ^^^ Names match up with Vertex Shader output
layout (triangle_strip, max_vertices = 3) out;
out vec3 ex_worldNorm;
out vec3 ex_worldView;
// ^^^ Names match up with Fragment Shader input
void main (void)
{
// For each input vertex, spit one out
for (int i = 0; i < gl_in.length (); i++) {
ex_worldNorm = worldNormal [i];
ex_worldView = worldView [i];
EmitVertex ();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.