使用在OpenGL着色器显示像素 [英] Display voxels using shaders in openGL

查看:296
本文介绍了使用在OpenGL着色器显示像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的渲染管线voxelisation现在我使用顶点+几何+片段着色成功voxelise现场。现在我的体素被存储在3D纹理具有大小,例如,128x128x128。

I am working on voxelisation using the rendering pipeline and now I successfully voxelise the scene using vertex+geometry+fragment shaders. Now my voxels are stored in a 3D texture which has size, for example, 128x128x128.

我原来的场景模式集中在(0,0,0),它的正面和负面的轴线延伸。的texure然而,在特坐标为中心在(63,63,63)。

My original model of the scene is centered at (0,0,0) and it extends in both positive and negative axis. The texure, however, is centered at (63,63,63) in tex coordinates.

我实现了一个简单的射线marcing用于可视化,但它并没有考虑到在相机运动(我可以从非常固定位置只呈现,因为我的射线必须产生考虑到3D纹理的不同坐标)。

I implemented a simple ray marcing for visualizing but it doesn't take into account the camera movements (I can render only from very fixed positions because my ray have to be generated taking into account the different coordinates of the 3D texture).

我的问题是:我怎么能映射我的光线,这样在点宝在我的三维模型的坐标方向D产生,他们却相交的体素在纹理坐标相机在每一个动作对应的位置, 3D世界重新映射在像素坐标?

My question is: how can I map my rays so that they are generated at point Po with direction D in the coordinates of my 3D model but intersect the voxels at the corresponding position in texture coordinates and every movement of the camera in the 3D world is remapped in the voxel coordinates?

现在我生成这样的光线: 创建于镜头前的位置,四(63,63,-20) 投光方向朝向(63,63,3)

Right now I generate the rays in this way: create a quad in front of the camera at position (63,63,-20) cast rays in direction towards (63,63,3)

推荐答案

我觉得你应该存储您的整个视图中的着色均匀PARAMS变换矩阵。然后为每个着色器执行,你可以使用它的屏幕COORDS并查看变换来计算特定像素的观点光线的方向。 有你只是用他们同样作为目前光线的方向和摄像头的位置。

I think you should store your entire view transform matrix in your shader uniform params. Then for each shader execution you can use its screen coords and view transform to compute the view ray direction for your particular pixel. Having the ray direction and camera position you just use them the same as currently.

还有另一种方式来做到这一点,你可以试试:

让我们假设你有一个立方体(0,0,0) - >(1,1,1),并为每个角落,你指定的颜色基于其位置,如(1,0,0)是红色的,等等

Let's say you have a cube (0,0,0)->(1,1,1) and for each corner you assign a color based on its position, like (1,0,0) is red, etc.

现在每一个多维数据集前表面的纹理和立方体回面对第二纹理帧绘制。

Now for every frame you draw your cube front faces to the texture, and cube back faces to the second texture.

在最后的渲染,你可以使用这两种纹理来获得键入退出 3D矢量,已经在质地空间,这使得最终的着色器简单得多。

In the final rendering you can use both textures to get enter and exit 3D vectors, already in the texture space, which makes your final shader much simpler.

您可以在这里读到更好的描述:

You can read better descriptions here:

http://graphicsrunner.blogspot.com/2009/01/体绘制-101.html

http://web.cse.ohio-state.edu/~tong / VR /

这篇关于使用在OpenGL着色器显示像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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