小编cal*_*rks的帖子

'错误:在片段着色器中的GLSL 1.30及更高版本中禁止使用非常量表达式索引的采样器数组

我正在为游戏引擎编写以下片段着色器:

#version 330 core

layout (location = 0) out vec4 color;

uniform vec4 colour;
uniform vec2 light_pos;

in DATA
{
    vec4 position;
    vec2 uv;
    float tid;
    vec4 color;
} fs_in;

uniform sampler2D textures[32];

void main()
{
    float intensity = 1.0 / length(fs_in.position.xy - light_pos);

    vec4 texColor = fs_in.color;

    if(fs_in.tid > 0.0){
        int tid = int(fs_in.tid + 0.5);
        texColor = texture(textures[tid], fs_in.uv);
    }

    color = texColor * intensity;
}
Run Code Online (Sandbox Code Playgroud)

该行texColor = texture(textures[tid], fs_in.uv);导致在编译着色器时,GLSL 1.30及更高版本的表达式中禁止使用非常量表达式索引的采样器数组.

如果需要,顶点着色器是:

#version 330 core

layout …
Run Code Online (Sandbox Code Playgroud)

c++ opengl glsl

0
推荐指数
1
解决办法
708
查看次数

标签 统计

c++ ×1

glsl ×1

opengl ×1