다음은 내가 DOF를 생성하기 위해 작성한 코드입니다.
void generateDOFfromEye(Image& img, const Camera& camera, Scene scene, float focusPoint)
{
float pixelWidth = 1.0f/(float) img.width;
float pixelHeight = 1.0f/(float) img.height;
for (int y = 0; y < img.height; ++y)
{
for (int x = 0; x < img.width; ++x)
{
Color output(0,0,0,0);
img(x, y) = Color(0,0,0,0);
//Center of the current pixel
float px = (x * pixelWidth) - 0.5;
float py = (y * pixelHeight) - 0.5;
Ray cameraSpaceRay = Ray(Vector(0,0,0,1), Vector(px, py, 1.0f, 0.0f));
Ray ray = camera.Transform() * cameraSpaceRay;
int depth = 0;
int focaldistance = 2502;
Color blend(0,0,0,0);
//Stratified Sampling i.e. Random sampling (with 16 samples) inside each pixel to add DOF
for(int i = 0; i < 16; i++)
{
//random values between [-1,1]
float rw = (static_cast<float>(rand() % RAND_MAX)/RAND_MAX) * 2.0f - 1.0f;
float rh = (static_cast<float>(rand() % RAND_MAX)/RAND_MAX) * 2.0f - 1.0f;
// Since eye position is (0,0,0,1) I generate samples around that point with a 3x3 aperture size window.
float dx = ((rw) * 3 * pixelWidth) - 0.5;
float dy = ((rh) * 3 * pixelHeight) - 0.5;
//Now here I compute point P in the scene where I want to focus my scene
Vector P = Vector(0,0,0,1) + focusPoint * ray.Direction();
Vector dir = P - Vector(dx, dy, 0.0f, 1.0f);
ray = Ray(Vector(dx,dy,0.0f,1.0f), dir);
ray = camera.Transform() * ray;
//Calling the phong shader to render the scene
blend += phongShader(scene, ray, depth, output);
}
blend /= 16.0f;
img(x, y) += blend;
}
}
}
이제 코드에는 아무 것도 표시되지 않습니다.아래 그림과 같이하지만 무엇입니까 결과는 focuspoint > 500
의 가치 단지 흐린 이미지입니다 :이 코드에서 어떤 문제가 있는지 알 수있는 경우 ![enter image description here](https://i.stack.imgur.com/x7ZcN.jpg)
은 매우 도움이 :) 감사 할 것이다!
내 카메라 (또는 눈) 위치 주변에 샘플 지점을 몇 개 찍는 것과 비슷하지 않습니까? 그런 다음이 모든 장면에서 내 장면을 렌더링합니다. 장면의 어딘가에 초점 포인트를 정의하여 이미지면의 각 픽셀에 대해 각 샘플 지점에서 초점에있는 지점까지 광선을 전송합니다. – sinner
음, 예, 실제로는 동일합니다. 물론 전체 장면의 렌더를 누적하는 대신 픽셀 단위로 색상을 누적 할 수 있습니다. – IneQuation
내 말은 : 취향과 비슷하지 않습니다 : - 내 카메라 (또는 눈) 위치 주변에 약간의 샘플 포인트가 있습니다. - 그런 다음 각 샘플 지점에서 이미지면의 각 픽셀을 통해 초점 지점으로 광선을 보내서이 모든 위치에서 내 장면을 렌더링합니다. 미안하지만 눈 위치, 이미지 평면, 초점 평면 및 장면의 관점에서 설명 할 수 있다면 꽤 쉽게 이해할 수 있습니다. – sinner