Hey
im stil new to shaders and im having trouble understanding this error i get from the following fragment shader im busy writing (its not complete yet, im probely using some bad naming conventions and the logic might stil be flawed but for now my only concern is the error its giving me)
uniform sampler2D tex;
uniform int textureMode;
uniform int lightMode;
varying vec3 normal;
uniform float l1_constantAttenuation,l1_linearAttenuation,l1_quadraticAttenuation;
varying vec4 l1_diffuse;
varying vec3 l1_lightDir;
varying float l1_dist;
uniform float l0_constantAttenuation,l0_linearAttenuation,l0_quadraticAttenuation;
varying vec4 l0_diffuse;
varying vec3 l0_lightDir;
varying float l0_dist;
void main (void)
{
vec4 l0_contribution;
vec4 l1_contibution;
if (textureMode == 0)
{
l0_contibution = l0_diffuse;
l1_contibution = l1_diffuse;
}
if (textureMode == 1)
{
vec4 texColor = texture2D(tex,gl_TexCoord[0].st);
l0_contibution = texColor;
l1_contibution = vec4(0,0,0,0);
}
else if (textureMode == 2)
{
vec4 texColor = texture2D(tex,gl_TexCoord[0].st);
l0_contibution = texColor*l0_diffuse;
l1_contibution = texColor*l1_diffuse;
}
if (lightMode == 0)
{
gl_FragColor = l0_contribution;
}
else if (lightMode == 1)
{
vec3 n;
float NdotL;
n = normalize(normal);
NdotL = max(dot(n,l1_lightDir),0.0);
float att = 1.0 / (l1_constantAttenuation +
l1_linearAttenuation * l1_dist +
l1_quadraticAttenuation * l1_dist * l1_dist);
l1_contribution = vec4(att*l1_contribution.r*NdotL,att*l1_contribution.g*NdotL,att*l1_contribution.b*NdotL,0.0);
n = normalize(normal);
NdotL = max(dot(n,l0_lightDir),0.0);
att = 1.0 / (l0_constantAttenuation +
l0_linearAttenuation * l0_dist +
l0_quadraticAttenuation * l0_dist * l0_dist);
l0_contribution = vec4(att*l0_contribution.r*NdotL,att*l0_contribution.g*NdotL,att*l0_contribution.b*NdotL,1.0);
gl_FragColor = l0_contribution+l1_contribution;
}
else if (lightMode == 2)
{
float att = 1.0 / (l1_constantAttenuation +
l1_linearAttenuation * l1_dist +
l1_quadraticAttenuation * l1_dist * l1_dist);
l1_contribution = vec4(att*l1_contribution.r*NdotL,att*l1_contribution.g*NdotL,att*l1_contribution.b*NdotL,0.0);
att = 1.0 / (l0_constantAttenuation +
l0_linearAttenuation * l0_dist +
l0_quadraticAttenuation * l0_dist * l0_dist);
l0_contribution = vec4(att*l0_contribution.r*NdotL,att*l0_contribution.g*NdotL,att*l0_contribution.b*NdotL,1.0);
gl_FragColor = l0_contribution+l1_contribution;
}
}
here is the code for the vertice shader. its probely irrelevent but im pasting it for just in case
uniform mat4 completeMatrix;
uniform mat3 normalMatrix;
uniform mat4 modelMatrix;
uniform int lightMode;
varying vec3 normal;
uniform vec3 l1_pos;
uniform vec4 l1_color;
varying vec4 l1_diffuse;
varying vec3 l1_lightDir;
varying float l1_dist;
uniform vec3 l0_pos;
uniform vec4 l0_color;
varying vec4 l0_diffuse;
varying vec3 l0_lightDir;
varying float l0_dist;
void main()
{
gl_Position = completeMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
vec4 pos = modelMatrix * gl_Vertex;
if (lightMode == 0)
{
l0_diffuse = gl_Color;
}
else if (lightMode == 1)
{
normal = normalize(normalMatrix*gl_Normal);
vec3 aux = vec3(l1_pos.x-pos.x,l1_pos.y-pos.y,l1_pos.z-pos.z);
l1_dist = length(aux);
l1_lightDir = normalize(aux);
l1_diffuse = gl_Color * l1_color;;
aux = vec3(l0_pos.x-pos.x,l0_pos.y-pos.y,l0_pos.z-pos.z);
l0_dist = length(aux);
l0_lightDir = normalize(aux);
l0_diffuse = gl_Color * l0_color;;
}
else if (lightMode == 2)
{
vec3 aux = vec3(l1_pos.x-pos.x,l1_pos.y-pos.y,l1_pos.z-pos.z);
l1_dist = length(aux);
l1_diffuse = gl_Color * l1_color;;
aux = vec3(l0_pos.x-pos.x,l0_pos.y-pos.y,l0_pos.z-pos.z);
l0_dist = length(aux);
l0_diffuse = gl_Color * l0_color;;
}
}
and here's the errors it gives me
(29) : error C1008: undefined variable "l0_contibution"
(35) : error C1008: undefined variable "l0_contibution"
(42) : error C1008: undefined variable "l0_contibution"
(65) : error C1008: undefined variable "l1_contribution"
(65) : error C1008: undefined variable "l1_contribution"
(65) : error C1008: undefined variable "l1_contribution"
(65) : error C1008: undefined variable "l1_contribution"
(79) : error C1008: undefined variable "l1_contribution"
(88) : error C1008: undefined variable "l1_contribution"
(88) : error C1008: undefined variable "l1_contribution"
(88) : error C1008: undefined variable "NdotL"
(88) : error C1008: undefined variable "l1_contribution"
(88) : error C1008: undefined variable "NdotL"
(88) : error C1008: undefined variable "l1_contribution"
(88) : error C1008: undefined variable "NdotL"
(94) : error C1008: undefined variable "NdotL"
(94) : error C1008: undefined variable "NdotL"
(94) : error C1008: undefined variable "NdotL"
(96) : error C1008: undefined variable "l1_contribution"
Thnx in Advance!