Hey everyone,
I'm trying to implement something like RE:Map and I pretty much have it working close to perfect.
The issue no is that even using 16 bit UV pass edges stay jagged and I'd like to do some supersampling, but I have no clue on what the best way forward is.
The code was clean and readable until I started hacking away at giving supersampling a go. :/
This is the mess I've currently going. (Note this is my first time playing around with the SDK.)
static PF_Err RemapFunc16( void *refcon, A_long xL, A_long yL, PF_Pixel16 *in, PF_Pixel16 *out) { PF_Err err = PF_Err_NONE; double tmp_u, tmp_v; PF_Fixed sample_u, sample_v; RemapInfo *contextP = reinterpret_cast<RemapInfo*>(refcon); if (contextP) { // Define `in_data` (required for PF_SUBPIXEL_SAMPLE) PF_InData *in_data = contextP->in_data; AEGP_SuiteHandler suites(in_data->pica_basicP); if (contextP->supersamplingMode != 1) // Supersampling!? { int ss; if (contextP->supersamplingMode == 2) ss = 2; // 2x Supersampling! else if (contextP->supersamplingMode == 3) ss = 4; // 4x Supersampling! else if (contextP->supersamplingMode == 4) ss = 8; // 8x Supersampling! double divisor = 1 / ((double)ss + 2.0); int half = ss / 2; double src_u, src_v; int totalSamples = ss * ss; double sampleWeight = 1.0 / (double)totalSamples; A_u_short red = 0; A_u_short green = 0; A_u_short blue = 0; A_u_short alpha = 0; A_long xLF = ((A_long)xL << 16); A_long yLF = ((A_long)yL << 16); PF_Fixed sample_src_u, sample_src_v; //PF_Fixed sample_u, sample_v; for (int x = -half; x <= half; x++) { // Get supersampled u source src_u = (double)x * divisor; //src_u += xLF; sample_src_u = xLF + LONG2FIX(src_u); for (int y = -half; y <= half; y++) { // Get supersampled v source src_v = (double)y * divisor; //src_v += yLF; sample_src_v = yLF + LONG2FIX(src_v); // Set source point to `sourceLayer` contextP->samp_pb.src = contextP->sourceLayerData; // Sample src color suites.Sampling16Suite1()->subpixel_sample16(in_data->effect_ref, sample_src_u, sample_src_v, &contextP->samp_pb, out); // Get UV based on Red/Green from input pixel tmp_u = ((double)out->red / (double)PF_MAX_CHAN16); tmp_v = ((double)out->green / (double)PF_MAX_CHAN16); tmp_u *= (double)contextP->textureLayer->u.ld.width; tmp_v *= (double)contextP->textureLayer->u.ld.height; sample_u = LONG2FIX(tmp_u); sample_v = LONG2FIX(tmp_v); // Set source point to `textureLayer` contextP->samp_pb.src = &contextP->textureLayer->u.ld; // Sample from `map` at UV and set `out` pixel. suites.Sampling16Suite1()->subpixel_sample16(in_data->effect_ref, sample_u, sample_v, &contextP->samp_pb, out); /* red += (A_u_short)(out->red * sampleWeight); green += (A_u_short)(out->green * sampleWeight); blue += (A_u_short)(out->blue * sampleWeight); alpha += (A_u_short)(out->alpha * sampleWeight); */ } } //out->red = (A_u_short)red; //out->green = (A_u_short)green; //out->blue = (A_u_short)blue; //out->alpha = (A_u_short)alpha; } else { // No Supersampling! // Get UV based on Red/Green from input pixel tmp_u = ((double)in->red / (double)PF_MAX_CHAN16); tmp_v = ((double)in->green / (double)PF_MAX_CHAN16); tmp_u *= (double)contextP->textureLayer->u.ld.width; tmp_v *= (double)contextP->textureLayer->u.ld.height; sample_u = LONG2FIX(tmp_u); sample_v = LONG2FIX(tmp_v); // Set source point to `textureLayer` contextP->samp_pb.src = &contextP->textureLayer->u.ld; // Sample from `map` at UV and set `out` pixel. suites.Sampling16Suite1()->subpixel_sample16(in_data->effect_ref, sample_u, sample_v, &contextP->samp_pb, out); } if (contextP->preserveAlpha == TRUE) { out->alpha *= (in->alpha / PF_MAX_CHAN16); } } return err; }