相关疑难解决方法(0)

如何在片段着色器中使用gl_FragCoord.z在现代OpenGL中线性渲染深度?

我阅读了很多关于使用片段着色器获取深度的信息.

http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=234519

但我还是不知道这是否gl_FragCoord.z是线性的.

GLSL规范称屏幕上的范围为[0,1]而未提及线性与否.

我认为线性是至关重要的,因为我将使用渲染模型来匹配Kinect的深度图.

那么如果它不是线性的,那么如何在世界空间中线性化呢?

opengl shader glsl depth-buffer depth

9
推荐指数
3
解决办法
9822
查看次数

变换模型矩阵

使用 glm 设置 ViewMatrix 很容易:

glm::lookAt(Position, Direction, UpVector);
Run Code Online (Sandbox Code Playgroud)

但是如果我尝试将 funktion 与 modelMatrix 一起使用,我会得到令人困惑的值(模型的位置不正确,而且旋转看起来也不正确)。我只想以与设置相机相同的方式设置对象。我可以使用 lookAt 功能并在之后进行一些更改吗?还是我必须为此编写自己的功能?如果是这样,如何?

我用这个固定了位置:

m_Orientation = glm::lookAtLH(Position, Direction, UpVector);
m_Orientation[3][0] = -m_Orientation[3][0];
m_Orientation[3][1] = -m_Orientation[3][1];
m_Orientation[3][2] = -m_Orientation[3][2];
Run Code Online (Sandbox Code Playgroud)

也在 vertexshader 里面我用这个:

gl_Position = CameraMatrix * ModelMatrix * Pos;
Run Code Online (Sandbox Code Playgroud)

其中 CameraMatrix 是一个 viewProjectionMatrix,ModelMatrix(我的问题)和 Pos 是我的顶点在模型空间中的位置

c++ opengl coordinate-transformation glm-math

0
推荐指数
1
解决办法
1999
查看次数