OpenGL水折射

发布于 2024-12-09 00:47:33 字数 180 浏览 0 评论 0原文

我正在尝试创建一个带有水波和折射的 OpenGL 应用程序。我需要要么从太阳投射光线,然后从相机投射光线并找出它们相交的位置,或者我需要从海底开始并找出我必须朝哪个方向(如果有的话)走才能击中目标太阳或相机。我有点被困住了,谁能给我一个关于 OpenGL 光线投射或高级几何速成课程的指导吗?我不希望海底处于恒定深度,也不希望水波是简单的正弦波。

I'm trying to create an OpenGL application with water waves and refraction. I need to either cast rays from the sun and then the camera and figure out where they intersect, or I need to start from the ocean floor and figure out in which direction(s, if any) I have to go in order to hit the sun or the camera. I'm kind of stuck, can any one give me an inpoint into either OpenGL ray casting or a crash course in advanced geometry? I don't want the ocean floor to be at a constant depth and I don't want the water waves to be simple sinusoidal waves.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空城旧梦 2024-12-16 00:47:33

首先,您要实现的效果可以使用 OpenGL 来实现,但它不是 OpenGL 的功能。 OpenGL 本身只是一个复杂的三角形屏幕绘制 API。您获得了一些输入数据并编写了一个程序,该程序使用 OpenGL API 根据输入数据执行相对简单的光栅化绘图操作。着色器给它一些空间;您可以在片段着色器中实现光线跟踪器。

在您的情况下,这意味着您必须实现某种算法来生成您想要的图片。对于水来说,必须使用某种光线追踪器或假折射方法才能达到看水的效果。焦散需要一个全功能的光子映射器,或者你擅长基于水面的二阶导数的假效果。

有一个 WebGL 演示,渲染出令人惊叹的漂亮交互式水:http://madebyevan.com/webgl-water/ 这是 YouTube 上的视频 http://www.youtube.com/watch?v=R0O_9bp3EKQ

该演示使用真正的光线追踪(水面、球体和水池均经过光线追踪),焦散是“假的”焦散”效果,基于投影水面高度图的二阶导数。

First things first: The effect you're trying to achieve can be implemented using OpenGL, but it is not a feature of OpenGL. OpenGL by itself is just a sophisticated triangle to screen drawing API. You got some input data and write a program that performs relatively simple rasterizing drawing operations based on the input data using the OpenGL API. Shaders give it some space; you can implement a raytracer in the fragment shader.

In your case that means, you must implement a some algorithm that generates a picture like you intend. For water is must be some kind of raytracer or fake refraction method to get the effect of looking into the water. The caustics require either a full features photon mapper, or you're good with a fake effect based on the 2nd derivative of the water surface.

There is a WebGL demo, rendering stunningly good looking, interactive water: http://madebyevan.com/webgl-water/ And here's a video of it on YouTube http://www.youtube.com/watch?v=R0O_9bp3EKQ

This demo uses true raytracing (the water surface, the sphere and the pool are raytraced), the caustics are a "fake caustics" effect, based on projecting the 2nd derivative of the water surface heightmap.

心房的律动 2024-12-16 00:47:33

这与 OpenGL 没有什么特别相关的。

您在谈论焦散吗?这是另一篇很好的 Gamasutra 文章

反射通常是通过在镜面反射相机并渲染到纹理来实现的,您可以应用扭曲,然后用它来纹理水面。这只适用于小波浪。

你在这里追求的是很多作弊的小方法:-)

There's nothing very OpenGL-specific about this.

Are you talking about caustics? Here's another good Gamasutra article.

Reflections are normally achieved by reflecting the camera in the plane of the mirror and rendering to a texture, you can apply distortion and then use it to texture the water surface. This only works well for small waves.

What you're after here is lots of little ways to cheat :-)

被你宠の有点坏 2024-12-16 00:47:33

从技术上讲,您所感知到的一切都是光波/光子从表面反射并通过介质传播的结果。对于“真正的交易”,您必须追踪直接来自太阳的光线,每条光线都遵循以下路径:

  • 撞击水面
  • 折射+反射,反射进入相机(*),折射部分进一步
  • 撞击海底
  • 反射
  • 从下面打到水面上
  • 反射+折射,折射部分出水面打到相机(*),再反射到海底,反射等等。

(*) 实际上,大部分光线都会错过相机,但这太过分了价格昂贵,所以这是一个骗局。

至少对三个波长执行此操作 - “红色”、“绿色”和“蓝色”。它们中的每一个都会发生不同的折射和反射。通过将三者结合起来,您将获得全貌。

然后,您只需使用进入相机的光线创建纹理并将其覆盖在 OpenGL 中。

这是一种直接、简单且计算量非常大的方法,可以近似地模拟焦散以外的物理现象。

Techincally, all you perceive is a result of lightwaves/photons bouncing off the surfaces and propagating through mediums. For the "real deal" you'll have to trace the light directly from the Sun with each ray following the path:

  • hit the water surface
  • refract+reflect, reflected goes into the camera(*), refracted part goes further
  • hits the ocean bottom
  • reflects
  • hits the water from beneath
  • reflect+refracts, refracted part gets out of the water and hits the camera(*), reflected again goes to the ocean bottom, reflects etc.

(*) Actually, most of the rays will miss the camera, but that will be overly expensive, so this is a cheat.

Do this for at least three wavelengths - "red", "green" and "blue". Each of them will refract and reflect differently. You'll get the whole picture by combining the three.

Then you just create a texture with the rays that got into the camera and overlay it in OpenGL.

That's a straighforward, simple and very computationally expensive way that gives an approximation to the physics beyond the caustics.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文