[英]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.