0
Raytracer를 개인 프로젝트로 작성하려고하는데 기본적인 재귀, 메쉬 지오메트리 및 레이 삼각형 교차가 있습니다. . 그럴듯한 이미지를 얻으려고하고 있지만 모든 픽셀 행이 똑같아서 직선을 수직으로 제공한다는 문제가 발생합니다.Raytracing - 스크린을 통해 카메라에서 촬영 한 광선이 y 축에서 벗어나지 않습니다. C++
: 나는 카메라 기능에서 생성 된 모든 픽셀 위치가 y 축에서 동일하지만 (나는 그것의 게으른 내가 알고, 너무 벡터로 내 정점 구조를 사용) 여기 내 벡터 수학의 문제를 찾을 수 있다는 것을 발견void Renderer::CameraShader()
{
//compute the width and height of the screen based on angle and distance of the near clip plane
double widthRad = tan(0.5*m_Cam.angle)*m_Cam.nearClipPlane;
double heightRad = ((double)m_Cam.pixelRows/(double)m_Cam.pixelCols)*widthRad;
//get the horizontal vector of the camera by crossing the direction angle with an
Vertex cross = ((m_Cam.direction - m_Cam.origin).CrossProduct(Vertex(0, 1, 0)).Normalized(0.0001))*widthRad;
//get the up/down vector of the camera by crossing the horizontal vector with the direction vector
Vertex crossDown = m_Cam.direction.CrossProduct(cross).Normalized(0.0001)*heightRad;
//generate rays per pixel row and column
for (int i = 0; i < m_Cam.pixelCols;i++)
{
for (int j = 0; j < m_Cam.pixelRows; j++)
{
Vertex pixelPos = m_Cam.origin + (m_Cam.direction - m_Cam.origin).Normalized(0.0001)*m_Cam.nearClipPlane //vector of the screen center
- cross + (cross*((i/(double)m_Cam.pixelCols)*widthRad*2)) //horizontal vector based on i
+ crossDown - (crossDown*((j/(double)m_Cam.pixelRows)*heightRad*2)); //vertical vector based on j
//cast a ray through according screen pixel to get color
m_Image[i][j] = raycast(m_Cam.origin, pixelPos - m_Cam.origin, p_MaxBounces);
}
}
}
코드의 주석에 어떤 일이 일어나기를 바랍니다.
사람은 문제가 도움이
디버거에서 실행하는 동안 특이한 점을 발견 했습니까? 'crossDown'은 맞습니까? 'm_Image'는'[x] [y]'에 의해 색인이 만들어지기로되어 있습니까? 대부분의 그래픽 API는 픽셀을'[y] [x]'로 정렬합니다. – DanielKO
그리고 당신은 저를 해결책에 데려왔습니다! –