#7420 Score: 0
decay
Participant

个人理解:无论是msaa还是ssaa都需要把depth buffer和frame buffer都开成原来的n倍,而msaa和ssaa的区别在于ssaa是直接进行完整的n遍渲染,最后再把这些渲染的结果平均起来;msaa则是进行n次光栅化,但着色只进行一次,并且认为着色点仍然是像素中心,而不是四个子像素的位置,最后根据光栅化时的结果将相应的frame buffer更新到新的着色值。
写一下伪代码更清晰一些:


rasterization_ssaa:
    for(x : xmin ~ xmax):
        for(y : ymin ~ ymax):
             for(subsample : n):
                 if(depth_test(subsample) == success):
                     update(depth_buffer[subsample])
                     sample_buffer[subsample] = shading(subsample, other_info)
             frame_buffer[sample] = avg(sample_buffer)

rasterization_msaa:
    for(x : xmin ~ xmax):
        for(y : ymin ~ ymax):
             // 着色发生在内部采样循环外面,因此只着色一次,提高了效率
             pixel_color = shading(sample, other_info)
             for(subsample : n):
                 if(depth_test(subsample) == success):
                     update(depth_buffer[subsample])
                     sample_buffer[subsample] = pixel_color
             frame_buffer[sample] = avg(sample_buffer)

可以在文刀大大的回答以及learnopengl中找到类似的结论:
https://www.zhihu.com/question/20236638/answer/44821615
https://learnopengl.com/Advanced-OpenGL/Anti-Aliasing
不过对于你可能还有个问题,就是作业2中的着色其实就是对像素进行颜色插值,所以实际上对于作业2来说,msaa和ssaa其实是差不太多的。至于你和楼主遇到的黑边,是因为你们没有开n倍的frame buffer,只要让frame buffer把每个子采样点的颜色记住就不会出问题。
我用上述思路在作业3中实现了msaa,最后附上blinn-phong着色的效果图对比图,右边是4xmsaa的,可以看到虽然还是有一些狗牙,但平滑了不少.(吐槽一下,作业3的insideTriangle函数直接把参数定义成了int,坑了我好久)