簡體   English   中英

GLSL:片段着色器何時退出/返回

[英]GLSL: When does the fragment shader exit / return

假設我們有以下片段着色器:

varying vec2 vUv; // uv coordinates
varying float vTexture; // texture index in array of textures

uniform sampler2D textures[2]; // number of textures

void main() {
  int textureIndex = int(floor(vTexture)); // convert texture index to int for equality checks

  if (textureIndex == 0) {
    gl_FragColor = texture2D(textures[0], vUv);
  }

  if (textureIndex == 1) {
    gl_FragColor = texture2D(textures[1], vUv);
  } 
}

如果通過此着色器獲得的給定值的textureIndex = 0,則該值是否將檢查第二個是否有條件,或者gl_FragColor的建立會使main()函數“返回”或退出? 有沒有一種方法可以強制片段着色器在給定點退出或返回?

新答案 (特定於問題)

void main() {
  int textureIndex = int(floor(vTexture)); // convert texture index to int for equality checks

  if (textureIndex == 0) {
    gl_FragColor = texture2D(textures[0], vUv);
  }

  if (textureIndex == 1) {
    gl_FragColor = texture2D(textures[1], vUv);
  } 

  // <--- HERE (ONCE IT RUNS THE CODE ABOVE, IT REACHES THE "END" AND EXITS)

}

暫無
暫無

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

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