OpenGL-如果是Alpha,请勿写入深度 [英] OpenGL - don't write depth if alpha

查看:109
本文介绍了OpenGL-如果是Alpha,请勿写入深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在OpenGL中使用C ++和GLSL做什么: 当纹理具有alpha(texture.a!= 1.0;)时,则不会将此像素写入深度缓冲区. (对于颜色缓冲区,将其写入) 写深度仅在像素纹理时发生.a == 1.0;

What I'm want to do in OpenGL using C++ and GLSL: When texture has alpha (texture.a! = 1.0;) then this pixel is not written to the depth buffer. (for color buffer it is written) Write depth occurs only when a pixel texture.a == 1.0;

丢弃着色器不是解决方案-则此像素不会写入颜色缓冲区.

Discarding in shader is not a solution - then this pixel is not written to color buffer.

有什么想法吗?

@UPDATE: 示例:我有一些由OpenGL渲染的UI图像.他们中有些人的角落有阿尔法. 在场景渲染中,我具有深度预通过"功能,可以通过不计算其上的光来节省一些像素. 我也想让UI图像达到该优先级-但只能是完全不透明的像素(alpha = 1.0).

@UPDATE: Example: I've got some UI images rendered by OpenGL. Some of them have alpha in corners. In scene rendering I have "depth prepass" to save some pixels by not calculating light on them. I want to also get UI images to that prepass - but only completely opaque pixels (alpha = 1.0).

推荐答案

Andon的评论中所述a>:编写片段时,您始终必须写入深度值,无法在着色器级别选择性地启用或禁用该值."

As mentioned in the comments by Andon: "You always have to write a depth value when you write a fragment, there is no way to selectively enable or disable this at the shader level."

这篇关于OpenGL-如果是Alpha,请勿写入深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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