OpenGL: 按列存储矩阵(column-major)。调用API形成的矩阵用来和一个列向量相乘,矩阵在左,列向量在右
GLSL: 存储方式和OpenGL相同(column-major)
DirectX: 按行存储矩阵(row-major)。调用API形成的矩阵用来和一个行向量相乘,矩阵在右,行向量在左
HLSL: 存储方式和DirectX相反(column-major)
因此,若HLSL的矩阵也是用来右乘行向量,则应将DX API构造的矩阵做Transpose,这样数学上HLSL会将Transpose后的矩阵视为 和DX API构造的矩阵是同一个矩阵,但是实际数值的存储顺序不同。若用来将矩阵左乘列向量,则可以不必做Transpose。
因此,一般的传入shader的操作是原封不动的将用来存储矩阵的array导入shader。但是如果是用的effect system里的setMatrix(), 则会先自动将矩阵由row-major改为colunn-major存储,再将其导入shader。这种情况下则无需在导入前手动Transpose 矩阵。
2010年10月30日星期六
2010年10月10日星期日
Texture types in OpenGL
GL_TEXTURE_1D: Images in this texture all are 1-dimensional. They have width, but no height or depth.
GL_TEXTURE_2D: Images in this texture all are 2-dimensional. They have width and height, but no depth.
GL_TEXTURE_3D: Images in this texture all are 3-dimensional. They have width, height, and depth.
GL_TEXTURE_RECTANGLE: The image in this texture (only one image. No mipmapping) is 2-dimensional. Texture coordinates used for these textures are not normalized.
GL_TEXTURE_BUFFER: The image in this texture (only one image. No mipmapping) is 1-dimensional. The storage for this data comes from a Buffer Object.
GL_TEXTURE_CUBE_MAP: There are exactly 6 distinct sets of 2D images, all of the same size. They act as 6 faces of a cube.
GL_TEXTURE_1D_ARRAY: Images in this texture all are 1-dimensional. However, it contains multiple sets of 1-dimensional images, all within one texture. The array length is part of the texture's size.
GL_TEXTURE_2D_ARRAY Array: Images in this texture all are 2-dimensional. However, it contains multiple sets of 2-dimensional images, all within one texture. The array length is part of the texture's size.
GL_TEXTURE_2D_MULTISAMPLE: The image in this texture (only one image. No mipmapping) is 2-dimensional. Each pixel in these images contains multiple samples instead of just one value.
GL_TEXTURE_2D_MULTISAMPLE_ARRAY: Combines 2D array and 2D multisample types. No mipmapping.
From: http://www.opengl.org/wiki/Texture
2010年6月24日星期四
glTexGen中object linear和eye linear的区别
根据red book的解释,在eye linear模式下,t = p1' * Xe + p2' * Ye + p3' * Ze + p4' ,Xe,Ye,Ze是顶点在viewing space的坐标, 故有(Xe, Ye, Ze, We) = M * (x0, y0, z0, w0),x0 , y0 , z0 ,w0为顶点在object space的坐标。而( p1' , p2', p3', p4') = (p1, p2 , p3 ,p4)*inverse(M),这样看来 t = (p1, p2, p3, p4) * (x0 , y0 , z0 ,w0), 生成的texture coordinates和在object linear模式下完全相同。怎么会这样呢?
实际上,在( p1' , p2', p3', p4') = (p1, p2 , p3 ,p4)*inverse(M)中,M为调用glTexGen时的Model-view矩阵,在生成坐标过程中不会再变化,而(Xe , Ye , Ze , We) = M * (x0 , y0 , z0 ,w0)中的M则是定义(x0 , y0 , z0 ,w0)时当前的Model-view矩阵,在定义不同顶点时Model-view矩阵可能会有所不同。只有在调用glTexGen后Model-view矩阵没有变化的情况下,在两种模式下生成的texture coordinates相同。简单的说,object linear模式中的纹理坐标跟据顶点的object coordinate(也就是glVertex定义的坐标)做一个固定的变换而生成,而eye linear模式则是把顶点变换到当先的viewing space,根据得到的viewing coordinate做一个固定的变换而生成。
实际上,在( p1' , p2', p3', p4') = (p1, p2 , p3 ,p4)*inverse(M)中,M为调用glTexGen时的Model-view矩阵,在生成坐标过程中不会再变化,而(Xe , Ye , Ze , We) = M * (x0 , y0 , z0 ,w0)中的M则是定义(x0 , y0 , z0 ,w0)时当前的Model-view矩阵,在定义不同顶点时Model-view矩阵可能会有所不同。只有在调用glTexGen后Model-view矩阵没有变化的情况下,在两种模式下生成的texture coordinates相同。简单的说,object linear模式中的纹理坐标跟据顶点的object coordinate(也就是glVertex定义的坐标)做一个固定的变换而生成,而eye linear模式则是把顶点变换到当先的viewing space,根据得到的viewing coordinate做一个固定的变换而生成。
订阅:
博文 (Atom)