假设我们有以下片段着色器:
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,那么该值是否会检查第二个if条件,还是gl_FragColor的建立会导致main()
函数“返回”还是退出?有没有办法强制片段着色器在给定点退出或返回?
答案 0 :(得分:0)
新答案(特定于问题)
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)
}