2013-03-10 2 views
0

조각 쉐이더가 있는데 구조체와 유니폼이 균일합니다. 나는 문제가 여기에 모르는GLSL Shader (structs) 컴파일시 이상한 오류

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" 

: 내가 그들을 컴파일했을 때, OpenGL은 날이 오류를했다. 나는 그 문제를 찾고 있었다. 나는 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; 
} 

코드에 대한 문제점은 무엇입니까 : 여기

코드인가? 경고의 몇 - 난 당신의 코드를 컴파일 할 때

+0

31 줄은 무엇입니까? –

답변

3

나는 오류가 표시되지 않습니다 :

0(62) : error C7011: implicit cast from "vec4" to "float" 
0(63) : error C7011: implicit cast from "vec4" to "float" 
0(64) : error C7011: implicit cast from "vec4" to "float" 

나는 거의 당신이 struct LightBasestruct MaterialBase의 선언을 주석으로 볼 수있는 오류를 재현 할 수 있습니다 - 그들이 라인 (33) 및 (34)에 표시를 제외하고 이것은 당신의 문제는 당신이 실제로 당신은 당신이 생각하는 프로그램을 컴파일하지 않을 것입니다 믿고 나를 리드 언급 토큰 lights_amaterial

와 선이있는. 아마도 파일에서 메모리로 읽는 중일 수도 있지만 glShaderSource를 호출하기 전에 메모리가 어떻게 든 손상됩니다 ...

+0

메모리에있는 데이터를 확인합니다 (const char *입니다). – Spamdark

+0

데이터는 문제가 없으며 구조체에 주석이 달려 있지 않습니다.이 문제가 발생하지 않아야합니다. 이것은 이상합니다 ... – Spamdark

+0

예, 오류가 발견되었습니다 ... 실제로 데이터가 손상되었습니다. 하지만 그렇지 않았습니다. – Spamdark