   Color seams in opengl & shader issues
  I've added per vertex lighting as color to an environment of mine. It's kind of strange that i see some seams that i suspect are due to interpolation. I'm running on a GF 9600 GT. Here are fill and wire images of how it looks like:FillWireframeI'm using:glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);glShadeModel(GL_SMOOTH);Any idea of what may be happening?[Edited by - Deliverance on May 26, 2009 7:03:26 PM]
  I've checked the color values... 85... 84... 83... 82... Dude, you've pretty much hit the resolution of the color buffer XD256 shades normally isn't noticeable but in cases like this sudden of all it becomes extremely noticeable. The human eye is more accurate it seems.EDIT (I should stop editing and think twice before posting -_-): if you really want to get rid of the seams, I'm afraid your only choice is trying a color buffer with a higher resolution (more than 8-bit per channel), although I'm not sure how widely supported are those =|A workaround would be to shift the color components a bit (e.g. red is 1.0 / 768.0 lower, green stays as is, blue is 1.0 / 768.0 higher) after the final color is calculated. Though the result won't be very good, and just will increase the amount of seams in order to fake a smoother gradient (which isn't very smooth after all).   ;  That's pretty interesting Sik_the_hedgehog :D.I have another issue with shaders. I'm doing a simple per pixel phong lighting shader and i get incorrect results IF i normalize the normal and light direction in the vertex shader. Images and code follow:Vertex shader with normal and lightdir normalized:varying vec3 normal, lightDir;void main(){vec4 pos;normal   = normalize(gl_NormalMatrix * gl_Normal);pos = gl_ModelViewMatrix * gl_Vertex;lightDir = normalize(vec3(gl_LightSource[0].position - pos));gl_Position = ftransform();} Output normalizedAlso notice the banding...Vertex shader with normal and lightdir NOT normalized:varying vec3 normal, lightDir;void main(){vec4 pos;normal   = (gl_NormalMatrix * gl_Normal);pos = gl_ModelViewMatrix * gl_Vertex;lightDir = (vec3(gl_LightSource[0].position - pos));gl_Position = ftransform();} OutputThe fragment shader looks like this:varying vec3 normal, lightDir;void main(){vec4 diffuseLight;vec3 n = normalize(normal);float lightIntensity = max(dot(n, normalize(lightDir)), 0.0);diffuseLight = lightIntensity * gl_LightSource[0].diffuse;gl_FragColor = diffuseLight;}The normal channel looks the same using any of the vertex shaders(?):NormalsI wonder what is this difference all about and why isn't the output in the framebuffer the same?   ;  bump :D   ;  Why are you normalizing lightDir twice? o_O (once in the vertex shader, once in the fragment shader) In theory the result should be the same (albeit slower), but maybe the floating comma precision is ruining it all.And removing the normalizing from the fragment shader would be a bad idea because of the way GPUs interpolate vectors.   ;Quote:Original post by Sik_the_hedgehogWhy are you normalizing lightDir twice? o_O (once in the vertex shader, once in the fragment shader) In theory the result should be the same (albeit slower), but maybe the floating comma precision is ruining it all.And removing the normalizing from the fragment shader would be a bad idea because of the way GPUs interpolate vectors.I understand there is no need for normalization in the vertex shader but i'm surprised why it produces incorrect results when doing so.Of course i won't remove the normalization in the fragment shader :D.   ;  Deliverance, You should consider the Normal and the lightDir separately.For the normal in vertex shader, it is simply the vertex normal you passed to the vertex program. In most case, the vertex normal of a 3D model is already an unit vector.  Therefore, normalizing the normal in vertex shader is not necessary because the normal is already unit vector in the first place.However, the local light source position (i.e your lightDir) should not be normalized before it reaches the fragment shader.  Although it might seems to have null effect, as it is going to be normalized in fragment shader anyway.  However, when you normalize it in vertex shader,  the rate of change of the interpolation of lightDir is different during rasterizatoin.  This is the reason why you get different result when you normalize/not-normalize your lightDir.Well, why the local light source position should not be normalized?  Mmmm....    I think it is just its nature.   