MAX_LIGHTS
次のシェーダー コードの値に応じて、次の例外が発生します。これはなぜですか?私は何が欠けていますか?
/usr/lib/python2.7/site-packages/OpenGL/GL/shaders.pyc in compileProgram(*shaders, **named)
194 program = ShaderProgram( program )
195 glLinkProgram(program)
--> 196 program.check_validate()
197 program.check_linked()
198 for shader in shaders:
/usr/lib/python2.7/site-packages/OpenGL/GL/shaders.pyc in check_validate(self)
106 """Validation failure (%s): %s"""%(
107 validation,
--> 108 glGetProgramInfoLog( self ),
109 ))
110 return self
RuntimeError: Validation failure (0):
頂点シェーダー コード:
#define MAX_LIGHTS 2
varying vec4 diffuse[MAX_LIGHTS], ambientGlobal[MAX_LIGHTS], ambient[MAX_LIGHTS];
varying vec3 normal[MAX_LIGHTS], lightDir[MAX_LIGHTS], halfVector[MAX_LIGHTS];
varying float dist[MAX_LIGHTS];
void main()
{
vec4 ecPos;
vec3 aux;
for (int i=0; i<MAX_LIGHTS; i++)
{
/* first transform the normal into eye space and normalize the result */
normal[i] = normalize(gl_NormalMatrix * gl_Normal);
/* now normalize the light's direction. Note that according to the
OpenGL specification, the light is stored in eye space. Also since
we're talking about a directional light, the position field is actually
direction */
ecPos = gl_ModelViewMatrix * gl_Vertex;
aux = vec3(gl_LightSource[i].position - ecPos);
lightDir[i] = normalize(aux);
/* compute the distance to the light source to a varying variable*/
dist[i] = length(aux);
/* Normalize the halfVector to pass it to the fragment shader */
halfVector[i] = normalize(gl_LightSource[i].halfVector.xyz);
/* Compute the diffuse, ambient and globalAmbient terms */
diffuse[i] = gl_FrontMaterial.diffuse * gl_LightSource[i].diffuse;
ambient[i] = gl_FrontMaterial.ambient * gl_LightSource[i].ambient;
ambientGlobal[i] = gl_LightModel.ambient * gl_FrontMaterial.ambient;
}
gl_Position = ftransform();
}
フラグメント シェーダー コード:
#define MAX_LIGHTS 2
varying vec4 diffuse[MAX_LIGHTS], ambientGlobal[MAX_LIGHTS], ambient[MAX_LIGHTS];
varying vec3 normal[MAX_LIGHTS], lightDir[MAX_LIGHTS], halfVector[MAX_LIGHTS];
varying float dist[MAX_LIGHTS];
void main()
{
vec3 n, halfV, viewV, ldir;
float NdotL, NdotHV;
vec4 color = ambientGlobal[0];
float att;
for (int i=0; i<MAX_LIGHTS; i++)
{
/* a fragment shader can't write a verying variable, hence we need
a new variable to store the normalized interpolated normal */
n = normalize(normal[i]);
/* compute the dot product between normal and ldir */
NdotL = max(dot(n, normalize(lightDir[i])), 0.0);
if (NdotL > 0.0) {
att = 1.0 / (gl_LightSource[i].constantAttenuation +
gl_LightSource[i].linearAttenuation * dist[i] +
gl_LightSource[i].quadraticAttenuation * dist[i] * dist[i]);
color += att * (diffuse[i] * NdotL + ambient[i]);
halfV = normalize(halfVector[i]);
NdotHV = max(dot(n,halfV),0.0);
color += att * gl_FrontMaterial.specular * gl_LightSource[i].specular * pow(NdotHV,gl_FrontMaterial.shininess);
}
}
gl_FragColor = color;
}