Custom Multipass Anti Aliasing
-
On 12/01/2016 at 03:20, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R14+
Platform:
Language(s) : C++ ;---------
Hey there,so a very basic example from VideoPostData::Execute() :
// Render the color and object buffer data. if (vps->vd && vps->render && vps->vp == VIDEOPOSTCALL_RENDER && !vps->open && colorBuffer_ != 0) { VPBuffer* colorBuf = vps->render->GetBuffer(VPBUFFER_POSTEFFECT, colorBuffer_); LONG const xres = colorBuf->GetInfo(VPGETINFO_XRESOLUTION); LONG const yres = colorBuf->GetInfo(VPGETINFO_YRESOLUTION); LONG const cpp = colorBuf->GetInfo(VPGETINFO_CPP); Bool hit; Ray ray; SurfaceIntersection si; for (LONG y = 0; y < yres; ++y) { for (LONG x = 0; x < xres; ++x) { // Find the first polygon that hits the ray for the current pixel. vps->vd->GetRay(x, y, &ray); hit = vps->vd->TraceGeometry(&ray, MAXREALr, vps->vd->lhit, &si); if (!hit || !si.op || !si.op->link) { continue; } SReal pixel[3] = {1.0, 1.0, 1.0}; colorBuf->SetLine(x, y, 1, &pixel, 32, false); } } }
This works perfectly fine. Example for a simple cube:
My problem is that I have no idea how to apply anti aliasing to the buffer. Ideally it should be the
same anti aliasing that is defined in the render settings. Are there any examples that I might have
missed in my searches? Or does anyone have an idea how to do it?Thanks in advance,
Niklas -
On 12/01/2016 at 11:38, xxxxxxxx wrote:
in general, antialisaing is a "blurring" filter. "it is not actually blurring, but just understand it like this"
colorBuf->SetLine(x, y, 1, &pixel, 32, false);
here lies the problem, for a simple Gaussian AA filter, you need to set the current pixel,
and weighting the neighboring pixels! for example "value[x - 1] = v * 0.6", "weight[x - 1] += .." at the end, value[x - 1] /= weight[x - 1] "if weight != 0" this will blend pixels together. some good references:
https://github.com/mmp/pbrt-v2/blob/master/src/filters/gaussian.cpp
https://github.com/mmp/pbrt-v2/blob/master/src/film/image.cpp