I´m currently developing an online multiplayer game using OpenGL.
Until recently, I used the fixed OpenGL rendering pipeline, but I (nearly) successfully switched to shaders (it looks MUCH better
But there is an issue with the lighting:
On my computer everything is fine (I guess because I took suitable values for the lights) ;
but on two other computers, the lightning is pretty much brighter than on mine. Therefore we can not figure out some good looking values for the light...
Could it have something to do with me having ATI and my friend Geforce?
Anyway, I´ll attach two images of the situation to this post.
Now for the code:
As far as the shader goes, here is the code of the fragmentshader:
[source lang="java"]varying vec4 diffuse, ambient;varying vec3 normal, lightDir, halfVector;varying vec4 glColor;uniform sampler2D tex0;uniform sampler2D tex1;uniform sampler2D tex2;uniform int lighting;uniform int texturing;uniform int alphamap;void main (void){ vec3 n,halfV; float NdotL,NdotHV; vec4 color = glColor; if (lighting==1) {color*=2*ambient;color.a=1; } else if (lighting==2) { color*=ambient;color.a=1; n = normal; NdotL = dot(n,lightDir); if (true) { NdotL+=0.6f; NdotL/=1.6f; color += diffuse * NdotL; } } switch (texturing) { case 0: gl_FragColor=color;break; case 1: gl_FragColor=color*texture2D(tex0,gl_TexCoord[0].st);break; case 2: vec4 texture0 = texture2D(tex0,gl_TexCoord[0].st); vec4 texture1 = texture2D(tex1,gl_TexCoord[1].st); vec4 texture2 = texture2D(tex2,gl_TexCoord[2].st); if (alphamap==0) {gl_FragColor = color*mix(texture1,texture2,texture0.g); } else if (alphamap==1) {gl_FragColor = color*mix(texture1,texture2,texture0.r);} else {gl_FragColor= vec4(1,1,1,1);}break; }}[/source]
Usually lighting equals 2 and texturing equals 1.
There are some calculations in the vertexshader as well:
[source lang="java"] if (lighting>=1) { ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; ambient += gl_LightModel.ambient * gl_FrontMaterial.ambient; } if (lighting==2) { normal = normalize(gl_NormalMatrix * gl_Normal); lightDir = normalize(vec3(gl_LightSource[0].position)); halfVector = normalize(gl_LightSource[0].halfVector.xyz); diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; }[/source]
Finally, I set up the lighting in the program itself:
[source lang="java"]//Lighting GL11.glLightf(GL11.GL_LIGHT0,GL11.GL_SPOT_DIRECTION,180); GL11.glLightf(GL11.GL_LIGHT0,GL11.GL_CONSTANT_ATTENUATION,1); GL11.glLightf(GL11.GL_LIGHT0,GL11.GL_LINEAR_ATTENUATION,0.0f); GL11.glLightf(GL11.GL_LIGHT0,GL11.GL_QUADRATIC_ATTENUATION,0f); FloatBuffer lightPosition = BufferUtils.createFloatBuffer(4); lightPosition.put(0.0f).put(1.0f).put(0.0f).put(0.0f).flip(); GL11.glLight(GL11.GL_LIGHT0,GL11.GL_POSITION,lightPosition); FloatBuffer whiteLight = BufferUtils.createFloatBuffer(4); whiteLight.put(0.7f).put(0.7f).put(0.7f).put(1.0f).flip(); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, whiteLight); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, whiteLight); FloatBuffer lModelAmbient = BufferUtils.createFloatBuffer(4); lModelAmbient.put(1.4f).put(1.4f).put(1.4f).put(1.0f).flip(); GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT,lModelAmbient); GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_LIGHT0); GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK,GL11.GL_AMBIENT_AND_DIFFUSE);[/source]
Basically, the scene consists of a simple ambient light and one directional light (representing the sun).
Now, I get that 1.4f may be a pretty high value for the ambient light, but when I turn it down, the scene gets very dark (at least on my computer).
Do you have a clue of where to look for the mistake?
Is there some kind of function or calculation that may be treated differently by different graphic cards or even by different versions of GLSL?
It´s like one computer adds a certain value to the light and the other doesn´t...
Thanks in advance for any clues






