gpt4 book ai didi

opengl-es - GLSL - 检查设置的属性

转载 作者:行者123 更新时间:2023-12-04 23:09:22 25 4
gpt4 key购买 nike

我有一个顶点着色器,其属性可能会或可能不会在任何给定帧中设置。如何检查是否已设置这些属性?

我想做什么:

attribute vec3 position;
attribute vec3 normal;
attribute vec4 color;
attribute vec2 textureCoord;


uniform mat4 perspective;
uniform mat4 modelview;
uniform mat4 camera;
uniform sampler2D textureSampler;

varying lowp vec4 vColor;

void main() {
gl_Position = perspective * camera * modelview * vec4(position, 1.0);
if ((bool)textureCoord) { // syntax error
vColor = texture2D(textureSampler, textureCoord);
} else {
vColor = (bool)color ? color : vec4((normal.xyz + 1.0)/2.0 , 1.0);
}
}

最佳答案

I have a vertex shader with attributes that may or may not be set in any given frame.



不,你没有。 :)

对于属性,不可能不“设置”属性。每个顶点着色器实例从每个声明的属性接收有效值。

如果 glEnableVertexArray 未启用属性数组,然后将传递默认属性(由 glVertexAttrib 及其默认值指定)。

在您的情况下,您可以:
  • 使用或不使用纹理编译不同版本的着色器(条件编译是您的 friend ;谷歌搜索 UberShader),
  • 使用像“useTexturing”这样的统一变量来节省着色器开关。

  • 选一个。

    关于opengl-es - GLSL - 检查设置的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4419604/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com