새소식

인기 검색어

게임 개발/그래픽스

수퍼 샘플링 (Supersampling)

  • -

https://en.wikipedia.org/wiki/Supersampling

 

Supersampling - Wikipedia

From Wikipedia, the free encyclopedia Spatial anti-aliasing method Calculating the end color value Comparison of a rendered scene without (left side) and with supersampling anti-aliasing applied (right). (Not applying AA is analogous to a nearest-neighbor

en.wikipedia.org

supersampling off vs supersampling on

곡면의 계단현상을 개선할 수 있다.

수퍼샘플링의 개념

한픽셀에서 하나의 ray를 쏴서 계산하는 것이 아닌, 각 픽셀에서 여러개의 ray를 쏴서 평균을 낸다.

위의 위키 페이지를 참고하면 꼭 4개의 ray 평균을 내는 방식이 아닌 여러 방식이 있음을 확인 할 수 있다.

다만 수퍼샘플링은 훨씬 많은 ray를 계산해야되기 때문에 엄청 느려진다.

따라서, real time rendering 환경에서는 blur 기법을 사용하는 경우도 있다.

 

vec3 traceRay2x2(vec3 eyePos, vec3 pixelPos, const float dx, const int recursiveLevel)
{
    if (recursiveLevel == 0)
    {
        Ray myRay{pixelPos, glm::normalize(pixelPos - eyePos)};
        return traceRay(myRay);
    }

    const float subdx = 0.5f * dx;

    vec3 pixelColor(0.0f);
    pixelPos = vec3(pixelPos.x - subdx * 0.5f, pixelPos.y - subdx * 0.5f, pixelPos.z);

    for (int j = 0; j < 2; j++)
    {
        for (int i = 0; i < 2; i++)
        {
            vec3 subPos(pixelPos.x + static_cast<float>(i) * subdx, pixelPos.y + static_cast<float>(j) * subdx, pixelPos.z);
            Ray sub_ray{ subPos, glm::normalize(subPos - eyePos) };
            pixelColor += traceRay2x2(eyePos, subPos, subdx, recursiveLevel - 1);
        }
    }

    return pixelColor * 0.25f;
}

 

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.