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月14日星期四
Bump Mapping [转]
Bump mapping is very much like Texture Mapping. However, where Texture Mapping added colour to a polygon, Bump Mapping adds, what appears to be surface roughness. This can have a dramatic effect on the look of a polygonal object. Bump Mapping can add minute detail to an object which would otherwise require a large number of polygons. Note that the polygon is still physically flat, but appears to a be bumpy.
The theory behind Bump Mapping
![](http://freespace.virgin.net/hugo.elias/graphics/bumpmap3.gif)
![](http://freespace.virgin.net/hugo.elias/graphics/bumpmap4.gif)
What is a Bump Map
![](http://freespace.virgin.net/hugo.elias/graphics/bumpmap5.gif)
So how's it done
![](http://freespace.virgin.net/hugo.elias/graphics/bumpmap6.gif)
![](http://freespace.virgin.net/hugo.elias/graphics/bumpmap7.gif)
x_gradient = pixel(x-1, y) - pixel(x+1, y) y_gradient = pixel(x, y-1) - pixel(x, y+1)
![](http://freespace.virgin.net/hugo.elias/graphics/x_n1.gif)
![](http://freespace.virgin.net/hugo.elias/graphics/x_t1.gif)
![](http://freespace.virgin.net/hugo.elias/graphics/x_n2.gif)
![](http://freespace.virgin.net/hugo.elias/graphics/x_t2.gif)
New_Normal = Normal + (U * x_gradient) + (V * y_gradient)
From: http://freespace.virgin.net/hugo.elias/graphics/x_polybm.htm
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
订阅:
博文 (Atom)