簡體   English   中英

這個頂點着色器在做什么?

[英]What is this vertex shader doing?

我最近接手了一個幾個月前被團隊成員停滯不前的項目。 在嘗試提高自己的速度時,我遇到了這個頂點着色器,我很難理解它的作用:

uniform int axes;
varying vec4 passcolor;

void main()
{
  // transform the vertex
  vec4 point;
  if (axes == 0) {
     point = gl_Vertex;
  } else if (axes == 1) {
     point = gl_Vertex.xzyw;

  } else if (axes == 2) {
     point = gl_Vertex.xwzy;

  } else if (axes == 3) {
      point = gl_Vertex.yzxw;

  } else if (axes == 4) {
     point = gl_Vertex.ywxz;

  } else if (axes == 5) {
     point = gl_Vertex.zwxy;
  }

  point.z = 0.0;
  point.w = 1.0;

  // eliminate w point
  gl_Position = gl_ModelViewProjectionMatrix * point;

 passcolor = gl_Color;
}

我想更好地理解的行是這樣的行:

point = gl_Vertex.xwzy;

我似乎找不到解釋此問題的文檔。

有人可以快速說明此着色器的功能嗎?

我似乎找不到解釋此問題的文檔。

GLSL規范非常清楚選擇毛刺的方式。

着色器基本上是在從vec4中拾取兩個軸的鈍化方式。 請注意,選擇后該point的Z和W被覆蓋。 根據所有權利,可以將其重寫為:

vec2 point;
if (axes == 0) {
   point = gl_Vertex.xy;
} else if (axes == 1) {
   point = gl_Vertex.xz;
} else if (axes == 2) {
   point = gl_Vertex.xw;
} else if (axes == 3) {
   point = gl_Vertex.yz;
} else if (axes == 4) {
   point = gl_Vertex.yw;
} else if (axes == 5) {
   point = gl_Vertex.zw;
}

gl_Position = gl_ModelViewProjectionMatrix * vec4(point.xy, 0.0, 1.0);

因此,僅從輸入頂點中選擇兩個坐標。 我不能說為什么需要這樣做。

之后的x,y,z和w的順序。 確定從gl_Vertex的x,y,z和w到點的x,y,z和w的映射。

這稱為sw流。 point = gl_Vertex等效於point = gl_Vertex.xyzw point = gl_Vertex.yxzw產生一個等效於gl_Vertex的點,其中x和y值互換。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM