你如何使用GLshorts表示法线或纹理坐标? [英] How do you represent a normal or texture coordinate using GLshorts?

查看:126
本文介绍了你如何使用GLshorts表示法线或纹理坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于提高iPhone游戏性能的很多建议都围绕着向GPU发送更少的数据。显而易见的建议是尽可能使用GLshorts而不是GLfloat,例如顶点,法线或纹理坐标。



使用GLshort作为常规时的具体情况是什么或纹理坐标?使用GLshort时,是否可以表示0.5的GLfloat纹理坐标?如果是这样,你怎么做?它会是SHRT_MAX / 2吗?也就是说,使用GLshort纹理坐标时,GLfloat贴图的范围从0到1是否为0到SHRT_MAX?



法线怎么样?我一直使用GLfloats创建法线,并将它们归一化为单位长度。将GLshort用于正常情况时,您是否将非标准化矢量发送给GPU?如果是这样,什么时候以及如何正常化?通过SHRT_MAX除以所有组件?

解决方案

正常



glEnable(GL_NORMALIZE)那么你可以提交法线为 GL_BYTE (或短线)。作为字节 0xFF 0xCC 0x33 提交的正常值由GPU规范化为(0.77,0.62,0.15)。



请注意,从 GL_NORMALIZE 有一个小的性能损失,因为GPU必须标准化每个法线。



GL_NORMALIZE 是你不能使用未标准化的法线进行光照欺骗。



编辑: ',我的意思是调整源数据中一个法线的长度(使其不为1.0),使垂线更明亮或更暗。

纹理坐标



就我所知,整数(字节或短裤)对纹理坐标来说不太有用。没有简单的调用指示OpenGL正常化你的纹理坐标。 0表示0.0,1表示1.0,而255表示255.0(用于平铺)。没有办法在两者之间指定小数值。



但是,不要忘记纹理矩阵。您可能可以使用它将整数转换为有用的纹理坐标。 (我还没试过。)


A lot of suggestions on improving the performance in iPhone games revolve around sending less data to the GPU. The obvious suggestion is to use GLshorts instead of GLfloat wherever possible, such as for vertices, normals, or texture coordinates.

What are the specifics when using a GLshort for a normal or a texture coordinate? Is it possible to represent a GLfloat texture coordinate of 0.5 when using a GLshort? If so, how do you do that? Would it just be SHRT_MAX/2? That is, does the range of 0 to 1 for a GLfloat map to 0 to SHRT_MAX when using a GLshort texture coordinate?

What about normals? I've always created normals with GLfloats and normalized them to unit length. When using a GLshort for a normal, are you sending a non-normalized vector to the GPU? If so, when and how is it normalized? By dividing by all components by SHRT_MAX?

解决方案

Normals

If you glEnable( GL_NORMALIZE ) then you can submit normals as GL_BYTE (or a short). A normal submitted as bytes 0xFF 0xCC 0x33 is normalized by the GPU to (0.77, 0.62, 0.15).

Note that there is a small performance penalty from GL_NORMALIZE because the GPU has to normalize each normal.

Another caveat with GL_NORMALIZE is that you can't do lighting trickery by using un-normalized normals.

Edit: By 'trickery', I mean adjusting the length of a normal in the source data (to a value other than 1.0) to make a vert brighter or darker.

Texture Coordinates

As far as I can tell, integers (bytes or shorts) are less useful for texture coordinates. There's no easy call instruct OpenGL to 'normalize' your texture coordinates. 0 means 0.0, 1 means 1.0, and 255 means 255.0 (for tiling). There's no way to specify fractional values in between.

However, don't forget about the texture matrix. You might be able to use it to transform the integers into useful texture coordinates. (I haven't tried.)

这篇关于你如何使用GLshorts表示法线或纹理坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆