相关疑难解决方法(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
查看次数

如何在给定视图空间深度值和ndc xy的情况下恢复视图空间位置

我正在写一个延迟着色器,我正试图更紧密地收拾我的gbuffer.但是,我似乎无法正确计算视图空间深度的视图位置

// depth -> (gl_ModelViewMatrix * vec4(pos.xyz, 1)).z; where pos is the model space position
// fov -> field of view in radians (0.62831855, 0.47123888)
// p -> ndc position, x, y [-1, 1]
vec3 getPosition(float depth, vec2 fov, vec2 p)
{
vec3 pos;
pos.x = -depth * tan( HALF_PI - fov.x/2.0 ) * (p.x);
pos.y = -depth * tan( HALF_PI - fov.y/2.0 ) * (p.y);
pos.z = depth;
return pos;
}
Run Code Online (Sandbox Code Playgroud)

计算出的位置是错误的.我知道这是因为我仍然在gbuffer中存储正确的位置并使用它进行测试.

c++ glsl perspectivecamera coordinate-transformation

7
推荐指数
2
解决办法
3743
查看次数

如何计算给定坐标处相机可见的矩形的大小?

我制作了一个小 Three.js 应用程序,它将一堆圆圈从画布底部移动到顶部:

let renderer, scene, light, circles, camera;

initialize();
animate();

function initialize() {
  renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  scene = new THREE.Scene();

  light = new THREE.AmbientLight();
  scene.add(light);

  circles = new THREE.Group();
  scene.add(circles);

  camera = new THREE.PerspectiveCamera(45, renderer.domElement.clientWidth / renderer.domElement.clientHeight, 1);
  camera.position.z = circles.position.z + 500;
}


function animate() {
  // Update each circle.
  Array.from(circles.children).forEach(circle => {
    if (circle.position.y < visibleBox(circle.position.z).max.y) {
      circle.position.y += 4;
    } else {
      circles.remove(circle);
    }
  });

  // Create …
Run Code Online (Sandbox Code Playgroud)

javascript frustum perspectivecamera three.js

4
推荐指数
1
解决办法
1588
查看次数

如何从投影矩阵中提取相机参数

我有一个具有一定投影矩阵的透视相机,我只想从中提取流、近平面和远平面。我知道 Three.js 中有一个函数:

.updateProjectionMatrix()
Run Code Online (Sandbox Code Playgroud)

它根据上面列出的参数创建一个投影矩阵,基本上我想要相反的过程。

javascript projection-matrix three.js

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

变换模型矩阵

使用 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
查看次数