I just made my first steps into GLSL. I wrote some code to calculate lighting myself just for fun.
Sadly it only works properly with the right camera angle (90 degrees), but lighting should be camera independet.
The people ##OpenGL told me the shader should be fine but it depens on my (irrlichts) implementation of OpenGL.
Should I use irrlichts getter-functions to get those matrices and set them via setShaderConstant or can I use OpenGls global variables directly in the shader?
Whatever here is the code:
Code: Select all
// Values for the Sunlight
uniform vec3 mLightDir;
uniform vec4 mLightColor;
void main()
{
vec3 normal = gl_NormalMatrix * gl_Normal;
vec4 diffuse = gl_FrontMaterial.diffuse * mLightColor;
vec3 lightDir = normalize(mLightDir);
// Get the dot product of normal and light
float NdotL = max(dot(normal, lightDir), 0.0);
// Calculate
vec4 globalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient;
gl_FrontColor = NdotL * diffuse + globalAmbient;
gl_Position = ftransform();
}
Code: Select all
uniform sampler2D mTerrainData;
void main()
{
gl_FragColor = gl_Color;
}