Talk:GLSL Programming/Vertex Transformations

= Computing the Projection Matrix =

I find that the difference between standard perspective and oblique perspective is confusing. Aren't they two ways to describe the same frustum? Beuc (discuss • contribs) 15:01, 14 August 2011 (UTC)


 * In the standard perspective frustum, the view direction is always to the center of the view plane. The oblique perspective frustum can be defined such that the view direction is to another point, even outside the visible rectangle of the view plane. Thus, the oblique perspective frustum is more general; i.e. you can specify any standard perspective frustum with the parameters of the oblique perspective frustum but not vice versa. --Martin Kraus (discuss • contribs) 17:47, 14 August 2011 (UTC)


 * OK, thanks a lot! Beuc (discuss • contribs) 06:23, 15 August 2011 (UTC)

Orientation of the coordinates system
I see that OpenGL view is aligned with the reverse Z axis by default, and this is the orientation that is displayed in the graphics. However in some other 3D tools, such as Blender, this is the "top view". This is also used in maths. Maybe it is less confusing the use the same convention.

Though, I also saw a reference about Unity using a "left-hand" coordinate system? Beuc (discuss • contribs) 15:28, 14 August 2011 (UTC)


 * The idea in OpenGL is that the x view coordinate goes to the right (on the screen) and the y view coordinate goes up (on the screen). This is the standard mathematical convention. Furthermore, a right-handed coordinate system is used. (I.e. if the thumb of a right hand points to the x axis and the index finger points to the y axis, then the middle finger should point in the positive z direction.) This is also a standard mathematical convention. These restrictions already imply that the viewer looks down the negative z axis. This is an OpenGL convention that is fixed in the OpenGL specification (even the programmable pipeline assumes that you look down the negative z axis); thus, I don't think one can avoid this convention in a book/tutorial on OpenGL/GLSL. Note that this OpenGL convention for the view coordinate system has no consequences whatsoever for world coordinates. Modeling a 3D world with the z axis going up is as good as any other orientation of the 3D world. In fact, even using a left-handed world coordinate system is fine as long as the view matrix is correctly set. However, I realize that I haven't described in this page how to go from a left-handed world coordinate system to a right-handed view coordinate system. Mainly because I'm not sure about all the consequences. (For example, clockwise-polygons will become counter-clockwise polygons by this transformation. I'm not sure I'm aware of all the issues that can arise.) Also, most libraries that are built on top of OpenGL or the standard convention of a right-handed coordinate system (e.g. Blender) won't have this issue.
 * I guess Unity uses a left-handed world coordinate system because it was built with Direct3D in mind, which also uses a left-handed world coordinate system as far as I know. I never really noticed it because Unity provides the correct transformation matrices that take care of the correct transformation from left-handed world space to right-handed view space. I'll have to think about whether and where to mention this point in the Unity tutorials.--Martin Kraus (discuss • contribs) 17:47, 14 August 2011 (UTC)


 * The only problem/confusion that I think of, is loading several objects, one in OpenGL "look-down" convention, and one in Blender convention : one will be displayed with a 90° rotation on the Y axis. This happened to me when importing meshes in standard Blender ;) This will surprise the users, for instance if (s)he hand-wrote a tetrahedron/cube/etc. coordinates by hand with "look-down" convention, positioned the camera accordingly (look-down too), then load an external mesh and see (s)he either has to rewrite all his manual coordinates, or rotate all his manual objects, or rotate each and every mesh (s)he imports. I'll have to see what happens when I do that and decide. Beuc (discuss • contribs) 06:23, 15 August 2011 (UTC)


 * I see what you mean. But I think that's a standard problem when importing models from different modeling tools. Also, as far as I know, OpenGL really doesn't have a convention for world space (only for view space). Thus, it might actually be a good idea to use a world space with the z axis up. This way, the difference between world space and view space should be obvious. --Martin Kraus (discuss • contribs) 08:13, 15 August 2011 (UTC)


 * O well, I just tried to use a reflection map in Blender and got completely confused: isn't +Z supposed to be top in Blender? On the other hand, the description for cube maps on Blender 3D: Noob to Pro/Build a skybox appears to follow the OpenGL convention. But then, when I tried to use that map in Blender with a GLSL shader it doesn't seem to map it to the faces of a cube map the way that wikibook page describes it. Do you have any experience with skyboxes in Blender? Is that wikibooks page still valid for Blender 2.58? --Martin Kraus (discuss • contribs) 10:12, 15 August 2011 (UTC)


 * I don't have experience with Blender skyboxes; looking at the screenshots, the coordinates (at the bottom-left corner) seem to follow the "Z is up" convention, but indeed this disagrees with the explanations about the cube faces..
 * You're right that bad orientation is a common issue, users will encounter it anyway and we have to cover it. Beuc (discuss • contribs) 11:00, 15 August 2011 (UTC)


 * Actually, that Blender 3D wikibook page appears to label the faces according to the Direct3D convention. Confusing. In any case, the cube map is apparently in the correct format for Blender 2.58 (the preview is fine with the sky at the top), I only had to negate the z coordinate and swap it with the y coordinate in the GLSL shader. Thus, this is probably just the different +Z=up convention in Blender. --Martin Kraus (discuss • contribs) 13:28, 15 August 2011 (UTC)

I just saw that using the Blender "Z is up" coordinates system in OpenGL introduces issues: I guess it's best to stick with "Y is up". Time to fix the objects and lights coordinates in my tutorials T-T Beuc (discuss • contribs) 07:37, 11 September 2011 (UTC)
 * .obj files are usually in "Y is up", requiring changes when loading them (or when exporting them from Blender)
 * the camera is in "Y is up", which requires confusing work-arounds when controlling it with keyboard (to move left/right, you rotate on Y axis in view coordinates - not Z)
 * as far as I understand, other engines such as Irrlicht and Ogre also use "Y is up"
 * Well, I guess "Y is up" will make the code somewhat simpler since it is the default in OpenGL. --Martin Kraus (discuss • contribs) 14:21, 12 September 2011 (UTC)

= I simple explanations as to what the steps actually do to the article. I hope this is ok =