在OpenGL中渲染一个*填充的*半透明立方体 [英] Rendering a *stuffed* translucent cube in OpenGL

查看:129
本文介绍了在OpenGL中渲染一个*填充的*半透明立方体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dunno如何表达我的困惑,但是这就是我的想法: 具有透明(或半透明)边的多维数据集不是是固体(填充的,填充的)多维数据集.它更像是一个空的玻璃立方体.现在,我想要的是坚固的填充玻璃立方体.就像水晶球一样,但呈立方体形状.它们背后的事物看起来不同.如何告诉OpenGL我的几何体已塞满?如何实现从很厚的玻璃层(例如玻璃)后面观看某个场景的效果?

Dunno how to express my confusion but here is how it goes in my mind: A cube with transparent(or translucent) sides is not a solid (filled, stuffed) cube. It's more like an empty glass cube. Now what I want is a solid, stuffed glass cube. Just like a crystal ball but in cube shape. Things behind them appear differently.How do I tell OpenGL that my geometry is stuffed ? How do i achieve the effect of looking at some scene from behind a very thick layer of , say, glass ?

推荐答案

正确的术语是"solid".您的问题是一个不平凡的问题,没有简单,现场的方法可以解决.对于简单的伪折射而言,最好的方法是渲染一个立方体贴图,其原点位于绑定体积中心的对象的中心,并使用该立方体贴图将对象法线缩放为纹理坐标.如果您希望它看起来更准确,则需要了解光与物质的相互作用.重建光物质相互作用效果的唯一完美准确的方法是通过 raytracing (如果使用了差分射线元素,则可能将其称为光子映射).

The proper term is "solid". And your problem is a nontrivial one and there's no easy, in-situ way to solve it. The best thing for a simple fake refraction is rendering a cubemap with the origin at the objects bounding volume's center, and use that cubemap in with the objects normals scaled as texture coordinates. If you want it to look more accurate you need to know about light-matter interactions. The only perfectly accurate way to recreate the effects of light-matter interaction is by raytracing (if differential ray elements are used, one may call this photon mapping).

如果要实时渲染结果,则使用OpenGL可以获得粗略的近似值.

Using OpenGL one can get coarse approximations if the results are to be rendered in realtime.

渲染半透明固体需要某种程度上类似于...的光学效果

Rendering translucent solids needs to somehow resemble the optical effects of

  • 折射
  • 反射
  • 吸收-随着光线穿过固体,它将被滤除
  • 荧光-例如,如果阳光或紫光穿过一块铀玻璃,紫外线部分会引起绿色荧光.光线的蓝色部分被吸收了,但是玻璃的绿色部分被吸收了.
  • 散射-玻璃中的小颗粒,杂质,小气泡等会将光散射出去.这就是雾的作用.
  • refraction
  • reflection
  • absorbtion - as the light passes through the solid it will be filtered out
  • flourescence – for example if sunlight, or just violet light passes through a piece of uranium glass, the ultraviolet part will cause green flourescence. The blue part of the light gets absorbed, but you get a green part emitting from the glass.
  • scattering - small particles in the glass, impurities, small air bubbles, etc. scatter the light out. This is what fog does.

在大多数情况下,假折射和吸收就足够了.可以非常有效地以这种方式渲染玻璃.渲染折射的吸收性固体有3个重要的变量:

In most cases it's sufficient to fake refraction and absorbtion. Glass can be rendered that way quite effectively. There are 3 important variables to rendering a refractive, absorbtive solid:

  • 入射光线的入射角(这将隐式确定实体中的光线)
  • 材料的思想
  • 射线的出射角

有几种获取方法:

  • 您可以对其进行预先计算,将它们存储为一组球谐系数,以用作着色器中的附加采样器输入.
  • 您可以使用深度剥离将有问题的对象切成表面层.奇数编号的层是入口,偶数编号的层是出口.你从近到远. 近表面撞击"使光线折射,然后跟随该光线,直到其撞击出射表面,然后再次折射到出射表面.光线的长度被用作参数,例如比尔-朗伯定律吸收方程.

那么您如何在OpenGL中实现这一点.恐怕有关Stackoverflow的答案将无法覆盖它,除非它成长为一本完整的论文.因此,我指的是 GPU Gems 2 的第19章,其中涵盖了

So how do you implement this in OpenGL. I'm afraid an answer on Stackoverflow will not be able to cover it, unless it grew into a fully fledged paper. Thus I refer you to Chapter 19 of GPU Gems 2, which covers the basics http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter19.html

这篇关于在OpenGL中渲染一个*填充的*半透明立方体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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