Now I really don’t know what is going on. It seems that the problem has nothing to do with ClipVertex. Here is the whole shader:

I cut away as much as I could to make it as short as possible. The vertex shader does not make too much sense this way but I deleted most of it on purpose. This shader does not work. When I compile it in Shader Designer, I get this error message:

Vertex attribute output count exceeds hardware limits

If I comment out just one line (line 74) in the Directional function:

FSpecular+=clamp(Ispec,0.0,1.0);

Then the shader works and I get a per fragment point light. But this makes no sense at all, at least not to me. Plese help.

Vertex shader:

varying vec3 Normal;

varying vec4 Ambient;

varying vec4 Diffuse;

varying vec4 Specular;

varying vec4 Campos;

varying vec3 Campos3;

varying vec3 Eye;

void main()

{

int i;

```
gl_TexCoord[0] = gl_TextureMatrix[0]*gl_MultiTexCoord0;
gl_TexCoord[1]=gl_TexCoord[2]=gl_TexCoord[3]=gl_TexCoord[4]=gl_TexCoord[0];
gl_Position = ftransform();
Normal = gl_NormalMatrix * gl_Normal;
Normal=normalize(Normal);
Ambient=vec4(0.0,0.0,0.0,0.0);
Diffuse=Ambient;
Specular=Ambient;
Campos=gl_ModelViewMatrix * gl_Vertex;
Campos3=Campos.xyz/Campos.w;
Eye=vec3(0.0, 0.0, 1.0);
gl_ClipVertex = Campos;
```

}

Fragment Shader:

uniform int texblending;

uniform int tenable[8];

uniform int lighttype[8];

uniform int atten[8];

uniform int numlights;

uniform int objperpixel;

uniform int lightperpixel[4];

uniform sampler2D tex0;

uniform sampler2D tex1;

uniform sampler2D tex2;

uniform sampler2D tex3;

uniform sampler2D tex4;

varying vec3 Normal;

varying vec4 Campos;

varying vec3 Campos3;

varying vec3 Eye;

varying vec4 Ambient;

varying vec4 Diffuse;

varying vec4 Specular;

vec4 FAmbient;

vec4 FDiffuse;

vec4 FSpecular;

vec4 VertColor;

float FShiny;

vec2 texcoor;

void Spot (in int ix)

{

}

void Point (in int ix)

{

//

float d;

float attenu=1.0;

```
vec3 L=normalize(gl_LightSource[ix].position.xyz - Campos3);
if (atten[ix]>0)
{
d=length(L);
attenu = 1.0 / (gl_LightSource[ix].constantAttenuation +
gl_LightSource[ix].linearAttenuation * d +
gl_LightSource[ix].quadraticAttenuation * d * d);
}
vec3 E=normalize(-Campos.xyz);
vec3 R=normalize(-reflect(L,Normal));
FAmbient+=gl_LightSource[ix].ambient;
FDiffuse+=clamp(( gl_LightSource[ix].diffuse * max(dot(Normal,L),0.0)),0.0,1.0)*attenu;
vec4 Ispec= gl_LightSource[ix].specular * pow(max(dot(R,E),0.0),FShiny)*attenu;
FSpecular+=clamp(Ispec,0.0,1.0);
```

//

}

void Directional (in int ix)

{

```
float d;
vec3 L=normalize(gl_LightSource[ix].position.xyz);
vec3 E=normalize(Eye);
vec3 R=normalize(-reflect(L,Normal));
FAmbient+=gl_LightSource[ix].ambient;
FDiffuse+=clamp(( gl_LightSource[ix].diffuse * max(dot(Normal,L),0.0)),0.0,1.0);
vec4 Ispec= gl_LightSource[ix].specular * pow(max(dot(R,E),0.0),FShiny);
```

//////

FSpecular+=clamp(Ispec,0.0,1.0);

//////

}

void PixelLight(in int i)

{

```
if (lighttype[i]==0)
Directional (i);
else if (lighttype[i]==1)
{
Point(i);
}
else if(lighttype[i]==2)
Spot(i);
```

}

void Textura(out vec4 color)

{

color=vec4(0.0,0.0,0.0,0.0);

texcoor=vec2(gl_TexCoord[0].xy);

vec4 texture;

vec3 tempColor;

```
if (tenable[0]>0)
{
color = texture2D(tex0, gl_TexCoord[0].xy);
}
if (tenable[1]>0)
{
texture = texture2D(tex1, gl_TexCoord[0].xy);
tempColor = mix(color.rgb, texture.rgb, texture.g);
color = vec4 (tempColor, color.a);
}
if (tenable[2]>0)
{
texture = texture2D(tex2, gl_TexCoord[0].xy);
tempColor = mix(color.rgb, texture.rgb, texture.g);
color = vec4 (tempColor, color.a);
}
if (tenable[3]>0)
{
texture = texture2D(tex3, gl_TexCoord[0].xy);
tempColor = mix(color.rgb, texture.rgb, texture.g);
color = vec4 (tempColor, color.a);
}
```

}

void main()

{

int i;

```
VertColor=gl_Color;
FAmbient=Ambient;
FDiffuse=Diffuse;
FSpecular=Specular;
FShiny=(gl_FrontMaterial.shininess+3.0)*0.3;
if (objperpixel>0)
{
for (i=0; i<numlights;i++)
{
if (lightperpixel[i]>0)
{
PixelLight(i);
}
}
}
VertColor = vec4(FAmbient.rgb,gl_Color.a);
VertColor += gl_FrontLightModelProduct.sceneColor + FDiffuse * gl_FrontMaterial.diffuse; // + FSpecular * gl_FrontMaterial.specular;
if (tenable[4]>0)
{
FSpecular = texture2D(tex4, gl_TexCoord[0].xy) * gl_FrontMaterial.specular;
}
vec4 Vcolor=vec4(VertColor);
vec4 color=vec4(0.0,0.0,0.0,0.0);
if (texblending>-1)
{
Textura(color);
if (color.a>0.0)
{
if (texblending==0)
Vcolor=color;
//else if (texblending==1)
//VertColor=color=VertColor;
else if (texblending==2)
{
vec3 temp=mix(Vcolor.rgb, color.rgb,color.a);
Vcolor=vec4(temp,color.a);
}
else if (texblending==3)
{
Vcolor.rgb+=color.rgb;
Vcolor=clamp(Vcolor,0.0,1.0);
}
}
}
Vcolor += FSpecular * gl_FrontMaterial.specular;
gl_FragColor =Vcolor;
```

}