Note on depth texture

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<Dt
GL_LESS
result=1.00.0⁢  r<Dtr>=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也能正常读取出深度信息来。这又是为何呢?

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值