简体   繁体   English

体素中的OpenGL 3D透明度

[英]OpenGL 3D transparency in voxels

(Sorry in advance, I'm not at my computer so I can't provide code) I have a voxel based game, and I wanted to add in transparent textures, namely glass. (对不起,我不在电脑上,所以我不能提供代码。)我有一个基于体素的游戏,我想添加透明的纹理,即玻璃。 I realized that transparent textures would throw things off (looking through other blocks), so I used my shaders to remove any alpha components lower than the alpha value of the glass texture. 我意识到透明纹理会扔掉东西(通过其他块查看),因此我使用着色器删除了任何低于玻璃纹理的alpha值的alpha分量。 Currently, the glass has an alpha of 0.26 (coordinates range from 0 - 1), and it works fine. 目前,玻璃的Alpha为0.26(坐标范围为0-1),并且工作正常。 But, if I want to add some transparency to the glass instead of removing all transparency, I run into my old issue where you can see through the blocks behind the glass. 但是,如果我想向玻璃杯添加一些透明度而不是除去所有透明度,则会遇到我的旧问题,在该问题中,您可以看到玻璃杯后面的块。

I read in a few places that I would need to sort my geometry from front to back. 我在一些地方阅读过,需要从前到后对我的几何图形进行排序。 Does this still pertain to my situation even after using shaders? 即使使用着色器后,这是否仍然与我的情况有关? I use display lists, for each chunk in my world, should I keep two lists, one for opaque blocks and one for transparent? 我使用显示列表,对于我的世界中的每个块,我应该保留两个列表,一个用于不透明块,另一个用于透明吗? So when I render, I would do one pass and render the opaque lists, and then do another render pass, and render the chunks inversely and render the transparent list? 因此,当我渲染时,我将进行一次渲染并渲染不透明列表,然后进行另一次渲染遍历,然后反转渲染块并渲染透明列表?

Or is there a better way to do this? 还是有更好的方法来做到这一点?

looking through blocks behind transparent geometry means you still have depth checking enabled meaning the blocks behind the glass didn't get rendered. 通过透明几何体后面的块查看意味着您仍启用了深度检查,这意味着未渲染玻璃后面的块。

I read in a few places that I would need to sort my geometry from front to back. 我在一些地方阅读过,需要从前到后对我的几何图形进行排序。 Does this still pertain to my situation even after using shaders? 即使使用着色器后,这是否仍然与我的情况有关?

yes you still need to sort, geometry shaders don't solve that issue 是的,您仍然需要排序,几何着色器无法解决该问题

however you only need to sort the transparent geometry when you render them after the opaque geometry (after turning on alpha blending) 但是,当您在不透明几何图形之后(在启用alpha混合之后)渲染它们时,只需要对透明几何图形进行排序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM