   GLSL questions
  I've been reading up a bit on GLSL (my first foray into the world of shaders), and there's one thing that I'm a bit unsure on. As far as OpenGL matrices go, I know of four:GL_MODELVIEWGL_PROJECTIONGL_TEXTUREGL_COLORNow from what I understand, GLSL has a few built in uniforms, two of them being gl_ModelViewMatrix and gl_ModelViewProjectionMatrix. The first is obvious, but the second is what I'm confused about. Is that essentially just what I've come to know as the Projection matrix, or is it some combination of both the Modelview and the Projection matrix? Or perhaps something completely different? I have the orange book on hold at the library, but until it comes in, if someone could answer this I'd appreciate it.Also, I'm thinking I don't have enough knowledge of the math involved as far as the processes involved in the various processes of the pipeline. For example, the diffuse lighting example on the nehe site is as follows://Vertex Shadervarying vec3 normal;varying vec3 vertex_to_light_vector;void main(){// Transforming The Vertexgl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;// Transforming The Normal To ModelView-Spacenormal = gl_NormalMatrix * gl_Normal; // Transforming The Vertex Position To ModelView-Spacevec4 vertex_in_modelview_space = gl_ModelViewMatrx * gl_Vertex;// Calculating The Vector From The Vertex Position To The Light Positionvertex_to_light_vector = vec3(gl_LightSource[0].position – vertex_in_modelview_space);}//Fragment Shadervarying vec3 normal;varying vec3 vertex_to_light_vector;void main(){// Defining The Material Colorsconst vec4 AmbientColor = vec4(0.1, 0.0, 0.0, 1.0);const vec4 DiffuseColor = vec4(1.0, 0.0, 0.0, 1.0);// Scaling The Input Vector To Length 1vec3 normalized_normal = normalize(normal);vec3 normalized_vertex_to_light_vector = normalize(vertex_to_light_vector);// Calculating The Diffuse Term And Clamping It To [0;1]float DiffuseTerm = clamp(dot(normal, vertex_to_light_vector), 0.0, 1.0);// Calculating The Final Colorgl_FragColor = AmbientColor + DiffuseColor * DiffuseTerm;}I understand what they're doing, I'm just not very sure why they're doing it. At least not enough to be able to do something like that to write my own. I'm thinking going through some of the specifics of the redbook is going to help, and I'm also going to grab More OpenGL Game Programming by Dave and Kevin (also on reserve at the library), and those two along with the orange book should have everything I'm looking for, but if someone can suggest some additional resources, it would be most appreciated.I've been using OpenGL for years, and I can do some pretty spiffy stuff with it, but now I'm going under the hood and a lot of this stuff is what I've taken for granted as being handled for me by the API. Now that I'm essentially reprogramming these processes, it's time to get down and really understand what's going on.Thanks in advance![Edited by - CyberSlag5k on June 18, 2006 11:43:20 AM]
  gl_ModelViewProjectionMatrix is simply the modelview matrix multiplied by the projection matrix. The MVP multiplies an object-space vertex position to clip space, which needs to be done for rendering. Hence the linegl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;In your example code.The most important thing to remember is that in order for operations to make sense the things you perform them on need to be in the same space. Also remember that matrix1 * matrix2 isn't the same thing as matrix2 * matrix1...More OpenGL is a good resource but mostly for the GLSL language itself, it doesn't really explain that much of the math (although some of it). I haven't read the orange book (although I plan to check it out some time) but that one's also probably more about the language itself. You'll probably learn a lot from the red book aswell.http://humus.ca/Articles/PhongIllumination.pdf is a very good description of doing lighting in shaders.Something you should do is download ShaderDesigner, an awesome app that really speeds up the process of... well, designing shaders :DJust one thing to note, in ShaderDesigner's rendering the positions of the lights are set before any transformations, and as such their positions are in object space instead of eye space as normally. As such most shaders won't exactly behave as expected when run in ShaderDesigner, just make sure the light is in the same space as your vertices when you make your light vector and you'll be set. Normally (in your example for instance) this means multiplying the light's position with the modelview matrix. Finding this out was a MAJOR headache for me, hehe.Anyway I felt the same way as you when I first started out with shaders roughly two weeks ago, but it isn't that hard to learn really and it's a lot of fun :)   ;  Thanks Erty. So you were coming into this with a similar level of knowledge? What resources did you use? I know you said you didn't have the orange book. I've skimmed the beginning of the link you provided, so that should be useful. But other than that, what did you use?Thanks again!   ;  Well, I'm relatively inexperienced both in programming and 3d graphics (first time I touched a 3d api was in february this year), so your knowledge of OpenGL is probably much greater. I tend to learn stuff insanely fast though, hehe.Resources... well, MOGLGP as I said, that's my only book so far. Then I've mostly just read loads of tutorials and sample shaders and such and gone from there with trial and error. And don't underestimate the power of the search function here on gamedev :)Some links:http://www.blacksmith-studios.dk/projects/downloads/bumpmapping_using_cg.phphttp://www.blacksmith-studios.dk/projects/downloads/tangent_matrix_derivation.phphttp://www.paulsprojects.net/tutorials/simplebump/simplebump.htmlIf you lack the needed math there are plenty of resources. Some here on gamedev, and then there's a good article series on flipcode aswell.Very late edit: http://www.lighthouse3d.com/opengl/glsl/ is great aswell, would've saved me a lot of hassle if I had found it earlier.[Edited by - Erty on June 20, 2006 12:52:42 PM];  Thanks again, Erty.   