We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello!
I´m trying to implement a directional light per vertex to simulate the OpenGL light and this error appears to me:
Attached vertex shader is not compiled.
But the strange is that when i compile, but changing this line: color = diffuse + specular + ambient; into this: color = vec4(1.0,0.0,0.0,1.0); actually works! But the problem is that the shader log is not point me what is wrong, and i couldn´t figure why!
This is the full vertex shader:
varying vec4 color;
//Light variables
uniform vec3 positionLight,ambientLight,diffuseLight,specularLight;
//Light Model
uniform vec3 lightModel;
//Material variables
uniform vec3 frontMaterialDiffuse,frontMaterialAmbient,
frontMaterialSpecular;
uniform float frontMaterialShininess;
vec3 getHalfVector(vec3 lightDir)
{
vec3 v,l;
v = vec3(gl_ModelViewMatrix * gl_Vertex);
vec3 view = normalize(-v);
l = normalize(lightDir - v);
return normalize( l + view );
}
vec3 getDiffuse(vec3 N, float NdotL)
{
vec3 diff = (diffuseLight * frontMaterialDiffuse);
diff *= NdotL;
return diff;
}
vec3 getAmbient(vec3 N, float NdotL)
{
vec3 ambient = frontMaterialAmbient * ambientLight;
vec3 globalAmbient = lightModel * ambientLight;
return ambient + globalAmbient;
}
vec3 getSpecular(vec3 N, vec3 H,float NdotHV)
{
vec3 spec = specularLight * frontMaterialSpecular;
spec *= pow(NdotHV,frontMaterialShininess);
return spec;
}
void main()
{
vec4 diffuse, ambient, specular = vec4(0.0);
vec3 normal, lightDir, halfVector;
float NdotL,NdotHV;
normal = normalize(gl_NormalMatrix * gl_Normal);
lightDir = normalize(vec3(positionLight));
halfVector = getHalfVector(lightDir);
NdotL = max(dot(normal, lightDir), 0.0);
NdotHV = max(dot(normal,normalize(halfVector)),0.0);
if (NdotL > 0.0)
{
diffuse = getDiffuse(normal,NdotL);
specular = getSpecular(normal,halfVector,NdotHV);
}
ambient = getAmbient(normal,NdotL);
// color = vec4(1.0,0.0,0.0,1.0);
color = diffuse + specular + ambient;
gl_Position = ftransform();
}
this is the fragment shader:
varying vec4 color;
void main()
{
gl_FragColor = color;
}
Any help will be appreciated, thanks!
Answers
Try adding: diffuse = vec4(0.0);
Also try using the variables that are used in Processing, see: https://processing.org/tutorials/pshader/
Thanks for the answer! In this line i already initialize all vec4 variables
vec4 diffuse, ambient, specular = vec4(0.0);
About the Processing, i can only use glsl also, i can not use built-in variables like gl_lightSource[] or gl_materials!
Processing shaders don't use any built-in lighting or matrix math variables from the older GL fixed-pipeline. Processing defines its own uniforms to store lighting parameters. Take a look at the Light Shaders section in the PShader tutorial
Thanks. As i said i cannot use Processing, only glsl.