FPMColor MatrixTransformer(Coordinates where, RenderFlags flags, void *context) { MatrixTransformerContext *cx = context; Vector v = CoordsGetVector(where); v = OOVectorMultiplyMatrix(v, cx->transform); where = MakeCoordsVector(v); return cx->source(where, flags, cx->sourceContext); }
FPMColor CosineBlurFilter(Coordinates where, RenderFlags flags, void *context) { Vector outV = CoordsGetVector(where); FPMColor colorAccum = kFPMColorClear; float weightAccum = 0.0f; SampleFace(outV, make_vector(0, 0, 1), make_vector(0, 1, 0), make_vector( 1, 0, 0), context, flags, &colorAccum, &weightAccum); SampleFace(outV, make_vector(0, 0, 1), make_vector(0, 1, 0), make_vector(-1, 0, 0), context, flags, &colorAccum, &weightAccum); SampleFace(outV, make_vector(1, 0, 0), make_vector(0, 0, 1), make_vector(0, 1, 0), context, flags, &colorAccum, &weightAccum); SampleFace(outV, make_vector(1, 0, 0), make_vector(0, 0, 1), make_vector(0, -1, 0), context, flags, &colorAccum, &weightAccum); SampleFace(outV, make_vector(0, 1, 0), make_vector(1, 0, 0), make_vector(0, 0, 1), context, flags, &colorAccum, &weightAccum); SampleFace(outV, make_vector(0, 1, 0), make_vector(1, 0, 0), make_vector(0, 0, -1), context, flags, &colorAccum, &weightAccum); weightAccum = 1.0f / weightAccum; colorAccum.r *= weightAccum; colorAccum.g *= weightAccum; colorAccum.b *= weightAccum; colorAccum.a = 1.0f; return colorAccum; }
static FPMColor ReadCube(Coordinates where, RenderFlags flags, void *context) { assert(context != NULL); ReadCubeContext *cx = context; // The largest coordinate component determines which face we’re looking at. Vector coords = CoordsGetVector(where); float ax = fabsf(coords.x); float ay = fabsf(coords.y); float az = fabsf(coords.z); FPMPoint faceOffset; float x, y; assert(ax != 0.0f || ay != 0.0f || az != 0.0f); if (ax > ay && ax > az) { x = coords.z / ax; y = -coords.y / ax; if (0 < coords.x) { x = -x; faceOffset = cx->pxPos; } else { faceOffset = cx->nxPos; } } else if (ay > ax && ay > az) { x = coords.x / ay; y = coords.z / ay; if (0 < coords.y) { faceOffset = cx->pyPos; } else { y = -y; faceOffset = cx->nyPos; } } else { x = coords.x / az; y = -coords.y / az; if (0 < coords.z) { faceOffset = cx->pzPos; } else { x = -x; faceOffset = cx->nzPos; } } x = x * cx->halfWidth + cx->halfWidth; y = y * cx->halfHeight + cx->halfHeight; #if 0 if (x < 0.0 || x > (cx->halfWidth * 2.0 - 1.0)) printf("x: %g (width: %g)\n", x, cx->halfWidth * 2.0); if (y < 0.0 || y > (cx->halfHeight * 2.0 - 1.0)) printf("y: %g (height: %g)\n", y, cx->halfHeight * 2.0); #endif if (1)//(1 <= x && x <= cx->maxX && 1 <= y && y <= cx->maxY) { FPMColor result = FPMSampleLinearClamp(cx->pm, x + faceOffset.x, y + faceOffset.y); if (result.a < 0.95) { result = (FPMColor){ 10, 0, 0, 1 }; printf("%g, %g\n", x, y); } return result; } else { // Deal with nasty edge cases. return ReadCubeEdge(cx, x, y, coords); } }