Illufox Kusanagi PORTFOLIO // V2.0 BOOT
WEBGL 2.0
+
000%
3D ASSET COMPILATION INITIALIZING SHADER PIPELINE
PIPELINE: THREE.JS + DRACOTARGET: 60 FPSSTATUS: DECOMPRESSING
← BACK TO BLOG ARCHIVE
Systems & C++2026-06-148 min read

High-Performance Vector Shape Decomposition in C++ & OpenCL

Reverse-engineering livery memory layers and accelerating primitive scoring loops

#C++ #OpenCL #Qt #Reverse Engineering #GPU

In racing simulators like Forza Horizon, player livery editors restrict decals to a predefined library of primitive geometric shapes. Recreating intricate anime characters or complex corporate logos by hand can take dozens of tedious hours.

1. The Core Genetic Optimization Algorithm

Horizon Canvas treats image reconstruction as an optimization problem: given a target raster image, discover the sequence, transformations, and colors of $N$ geometric primitives (squares, circles, polygons) that minimize the Mean Squared Error (MSE) loss against the target.

struct ShapePrimitive {
    int type;
    float x, y;
    float scaleX, scaleY;
    float rotation;
    uint32_t colorRGBA;
};

double computeFitness(const ImageBuffer& current, const ImageBuffer& target) {
    double mse = 0.0;
    for (size_t i = 0; i < current.pixelCount; ++i) {
        double diff = current.data[i] - target.data[i];
        mse += diff * diff;
    }
    return mse / current.pixelCount;
}

2. GPU Acceleration via OpenCL Compute Kernels

Running millions of rasterization and scoring evaluations on the CPU takes minutes per shape. By moving the shape rasterizer to custom OpenCL compute kernels on the GPU, we parallelized pixel fitness comparisons across thousands of stream processors, yielding a 45x speedup.

__kernel void rasterize_and_score(
    __global const uchar4* targetImage,
    __global const ShapePrimitive* shapes,
    __global float* fitnessOutputs,
    const int width,
    const int height
) {
    int gid = get_global_id(0);
    // Parallelized pixel diff accumulator
}

3. Direct Memory Injection Pipeline

Once optimized shape vectors are generated, the standalone Qt C++ application writes coordinates and color parameters directly into game memory structures, allowing instant in-game livery rendering without manual placement.