我有一个片段着色器,它有结构和这些结构的统一。当我尝试编译它们时,OpenGL 给了我这个错误:
0(30) : error C0000: syntax error, unexpected identifier, expecting '{' at token "lights_a"
0(31) : error C0000: syntax error, unexpected identifier, expecting '{' at token "material"
我不知道这里有什么问题。我一直在寻找问题...我查看了第 30 行和第 31 行,我做了我能想象的一切,但没有成功。
这是代码:
#version 330 core
struct LightBase
{
int renderit;
vec4 ambient_light;
vec4 specular_light;
vec4 diffuse_light;
float radius;
vec3 light_position;
vec3 light_direction;
int light_type;
};
struct MaterialBase
{
vec4 ambient_affect;
vec4 specular_affect;
vec4 diffuse_affect;
float shining;
float mirror;
int light_affect;
};
in vec3 VertexPos;
in vec3 Normal;
uniform int light_quantity;
uniform LightBase lights_a[50];
uniform MaterialBase material;
uniform float usingTex;
uniform sampler2D texturemap;
in vec2 UVs;
in vec4 Colors;
out vec4 color;
void main() {
vec4 texture_u = texture(texturemap,UVs).rgba * usingTex;
vec4 color_u = Colors * (1.0f-usingTex);
vec4 final_color = color_u+texture_u;
// Light
for(int i=0;i<light_quantity;i++) {
if(lights_a[i].renderit==1) {
if(lights_a[i].light_type==1) {
float attenuation = max(0.0,1.0-dot(lights_a[i].light_direction,lights_a[i].light_direction));
vec3 L = normalize(lights_a[i].light_direction);
vec3 N = normalize(Normal);
vec3 V = normalize(-VertexPos);
vec3 R = normalize(-reflect(L,N));
float nDotL = max(0.0,dot(N,L));
float rDotV = max(0.0,dot(R,V));
float ambient_result = lights_a[i].ambient_light * material.ambient_affect * attenuation;
float diffuse_result = lights_a[i].diffuse_light * material.diffuse_affect * nDotL * attenuation;
float specular_result = lights_a[i].specular_light * material.specular_affect * pow(rDotV,material.shining) * attenuation;
vec4 this_colour = (ambient_result + diffuse_result + specular_result) * final_color;
final_color = this_colour;
}
}
}
color = final_color;
}
代码有什么问题?