Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1350466
  • 博文数量: 281
  • 博客积分: 8800
  • 博客等级: 中将
  • 技术积分: 3346
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-17 22:31
文章分类

全部博文(281)

文章存档

2013年(1)

2012年(18)

2011年(16)

2010年(44)

2009年(86)

2008年(41)

2007年(10)

2006年(65)

我的朋友

分类: LINUX

2012-01-29 12:48:23

Opengl里各个变量的属性太多,一个不留神,属性设置错误,得到的结果就会差别很大。

关于depth texture,这条属性的设置很重要:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);

 

手册中的解释引用如下:

GL_TEXTURE_COMPARE_MODE

Specifies the texture comparison mode for currently bound depth textures. That is, a texture whose internal format is GL_DEPTH_COMPONENT_*; see glTexImage2D) Permissible values are:

   GL_COMPARE_R_TO_TEXTURE

Specifies that the interpolated and clamped r texture coordinate should be compared to the value in the currently bound depth texture. See the discussion of GL_TEXTURE_COMPARE_FUNC for details of how the comparison is evaluated. The result of the comparison is assigned to luminance, intensity, or alpha (as specified by GL_DEPTH_TEXTURE_MODE).

   GL_NONE

Specifies that the luminance, intensity, or alpha (as specified by GL_DEPTH_TEXTURE_MODE) should be assigned the appropriate value from the currently bound depth texture.

 

GL_TEXTURE_COMPARE_FUNC

Specifies the comparison operator used when GL_TEXTURE_COMPARE_MODE is set to GL_COMPARE_R_TO_TEXTURE. Permissible values are:

Texture Comparison Function Computed result
GL_LEQUAL
result=1.00.0⁢  r<=Dtr>Dt
GL_GEQUAL
result=1.00.0⁢  r>=Dtr
GL_LESS
result=1.00.0⁢  r=Dt
GL_GREATER
result=1.00.0⁢  r>Dtr<=Dt
GL_EQUAL
result=1.00.0⁢  r=Dtr≠Dt
GL_NOTEQUAL
result=1.00.0⁢  r≠Dtr=Dt
GL_ALWAYS
result=1.0
GL_NEVER
result=0.0

where r is the current interpolated texture coordinate, and Dt is the depth texture value sampled from the currently bound depth texture. result is assigned to the either the luminance, intensity, or alpha (as specified by GL_DEPTH_TEXTURE_MODE.)

 

 

解释:

1。如果用GL_COMPARE_R_TO_TEXTURE模式,则我们存到纹理中的就是result值,要么0,要么1。

2。如果用GL_NONE,才会保存下来按照设定的逻辑比较关系得到的结果深度值。

 

我一开始用的是GL_COMPARE_R_TO_TEXTURE,在shader里发现读取出来的值都是1.0,改为GL_NONE后就正常了。

 

 

Open issue:

我在程序里用的是FBO,并且render both a color image texture and depth texture to FBO,然后用

 glReadBuffer(GL_DEPTH_ATTACHMENT_EXT);
 glReadPixels(0, 0, s_width, s_height, GL_DEPTH_COMPONENT, GL_FLOAT, p); 

读取深度值的时候,即使上边设置为GL_COMPARE_R_TO_TEXTURE也能正常读取出深度信息来。这又是为何呢?

阅读(1144) | 评论(0) | 转发(0) |
0

上一篇:Vertex Texture Fetch

下一篇:Shader Model 4.0

给主人留下些什么吧!~~