Games101 第六课笔记 作业2附加题

第6课笔记

pre-filter模糊->sample采样

f=1/T

傅里叶变换:flitering频率变换

aliases走样:采样频率低导致失真

averaging平均

fliter滤波器

convolution卷积:信号与滤波器点乘

时域->傅里叶变换->频域

卷积定理:时域乘积=频域卷积,反之亦然

冲激函数

antialiasing反走样:
1.增加采样率
2.先模糊后采样

模糊:低通滤波:去掉高频信息
用一定大小的低通滤波器进行卷积

三个抗锯齿方案:
MSAA:模糊+采样,划分像素求平均
MSAA没有提高采样率,只是求一定范围内平均值给当前采样点,范围不一定规则,像素可能会被复用,能减少消耗

FXAA:快速近似抗锯齿,先得到有锯齿的图,再通过图像匹配算法找到边界,换成没有锯齿的边界,速度很快

TAA:复用上一帧,简单高效

super resolution:超分辨率
场景:小图拉大时全是锯齿
DLSS:深度学习超分辨率/超采样


总结

数学太难了qaq,前面傅里叶变换部分没怎么听懂,得抽空再学


作业

用 super-sampling 处理 Anti-aliasing : 你可能会注意到,当我们放大图像时,图像边缘会有锯齿感。我们可以用 super-sampling 来解决这个问题,即对每个像素进行 2 * 2 采样,并比较前后的结果 (这里 并不需要考虑像素与像素间的样本复用)。需要注意的点有,对于像素内的每一个样本都需要维护它自己的深度值,即每一个像素都需要维护一个 sample list。最后,如果你实现正确的话,你得到的三角形不应该有不正常的黑边。

void rst::rasterizer::rasterize_triangle(const Triangle& tri) {
    auto v = tri.toVector4();
    
    // TODO : Find out the bounding box of current triangle.
    // iterate through the pixel and find if the current pixel is inside the triangle
    int l, r, b, t;
    l = floor(std::min(v[0][0], std::min(v[1][0], v[2][0])));
    r = ceil( std::max(v[0][0], std::max(v[1][0], v[2][0])));
    b = floor(std::min(v[0][1], std::min(v[1][1], v[2][1])));
    t = ceil( std::max(v[0][1], std::max(v[1][1], v[2][1])));

    float n[2] = {0.25,0.75};// MASS范围

    for (int x = l; x < r; x++) {
        for (int y = b; y < t; y++) {
            int count = 0; // 记录在三角形内的点数
            float dep = 0; // 记录最小深度
            for (int i = 1; i <= 4; i++) {
                float xi = (float)x + n[(i+1)%2];
                float yi = (float)y + n[i/3];

                auto [alpha, beta, gamma] = computeBarycentric2D(xi, yi, tri.v);
                float w_reciprocal = 1.0/(alpha / v[0].w() + beta / v[1].w() + gamma / v[2].w());
                float z_interpolated = alpha * v[0].z() / v[0].w() + beta * v[1].z() / v[1].w() + gamma * v[2].z() / v[2].w();
                z_interpolated *= w_reciprocal;
                dep = std::min(dep, z_interpolated);

                if (insideTriangle(xi, yi, &v[0])) {
                    count++;
                }
            }
            if (count > 0) {
                if (depth_buf[get_index(x, y)] > dep) {
                    depth_buf[get_index(x, y)] = dep;
                    Vector3f point((float)x, (float)y, 0);
                    set_pixel(point, tri.getColor() * count / 4.);
                }
            }
        }
    }
}

效果图

未使用MASS:
未使用MASS

使用MASS:有点问题,可以看到绿三角形边缘有黑边
使用MASS

posted @ 2021-02-25 18:58  一语子  阅读(254)  评论(0)    收藏  举报