应用基于顶点着色器的几何变形的3D场景通用拾取解决方案 [英] Generic picking solution for 3D scenes with vertex-shader-based geometry deformation applied

查看:99
本文介绍了应用基于顶点着色器的几何变形的3D场景通用拾取解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为3D场景实现导航技术(在带有OpenGL的OpenSceneGraph中).除其他事项外,用户应该能够单击屏幕上的场景对象以向其移动.

I'm trying to implement a navigation technique for 3D scenes (in OpenSceneGraph with OpenGL). Among other things the user should be able to click on an scene object on the screen to move towards it.

导航技术应集成到另一个项目中,该项目使用顶点着色器将全局变形应用于场景几何.这就是问题所在:由于使用顶点着色器使几何变形,因此将鼠标光标位置取消投影到用户实际选择的地点的世界坐标并不是一件容易的事.但是在导航技术中,我需要这些坐标来执行正确的相机移动.

The navigation technique should be integrated into another project which uses a vertex shader to apply a global deformation to the scene geometry. And here is the problem: Since the geometry is deformed using a vertex shader, it is not straight forward to un-project the mouse cursor position to the world coordinates of the spot the user actually selected. But I need those coordinates to perform the proper camera movement in my navigation technique.

执行此非投影的一种方法是修改顶点着色器(用于变形),使其也将顶点的原始位置和法线存储在单独的纹理中.然后,可以在鼠标位置读取那些纹理以获得所需的值.

One way of performing this un-projection would be to modify the vertex shader (used for the deformation) to let it also store the vertex' original position and normal in separate textures. Afterwards one could read those textures at the mouse position to get the desired values.

现在,正如我所说,顶点着色器属于另一个我实际上不想触摸的项目.我的导航技术的目标之一是尽可能通用,也可以轻松地集成到其他项目中.

Now, as I said, the vertex shader belongs to another project which I actually don't want to touch. One goal of my navigation technique is to be as generic as possible to be easily integrated into other projects as well.

这是一个问题:OpenSceneGraph或OpenGL中是否有我到目前为止没有考虑的功能?有什么可以让我独立于顶点着色器编码器来获取片段的世界坐标的吗?

So here is the question: Is there any feature in OpenSceneGraph or OpenGL that I did not consider so far? Anything that allows me to get the world coordinates of a fragment, independently of the vertex shader coder?

推荐答案

好吧,您始终可以执行OpenGL选择操作: http://www.glprogramming.com/red/chapter13.html

Well, you could always do an OpenGL selection operation: http://www.glprogramming.com/red/chapter13.html

或者,您可以栅格化为一个非常小的(1px * 1px)帧缓冲区,用户单击该缓冲区,然后读取z缓冲区并将未获得的Z值投影到世界空间中.

Alternately, you could rasterize to a very small (1px*1px) framebuffer where the user clicked, read back the z-buffer and unproject the Z value you got into world space.

这篇关于应用基于顶点着色器的几何变形的3D场景通用拾取解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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