+
+
+ fprintf(fp, "SDRSTART\n");
+ fprintf(fp, "float eval_sdf(in vec3 p)\n");
+ fprintf(fp, "{\n");
+ rect = lvl->rects;
+ for(i=0; i<num; i++) {
+ float cx = (rect->x - 0.5f + rect->w * 0.5f) * lvl->scale;
+ float cy = (rect->y - 0.5f + rect->h * 0.5f) * lvl->scale;
+ float rx = (rect->w + 0.1f) * lvl->scale * 0.5f;
+ float ry = (rect->h + 0.1f) * lvl->scale * 0.5f;
+
+ if(i == 0) {
+ fprintf(fp, "\tfloat d = boxdist(p - vec3(%f, 0.0, %f), vec3(%f, 1.0, %f));\n",
+ cx, cy, rx, ry);
+ } else {
+ fprintf(fp, "\td = min(d, boxdist(p - vec3(%f, 0.0, %f), vec3(%f, 1.0, %f)));\n",
+ cx, cy, rx, ry);
+ }
+ rect++;
+ }
+ fprintf(fp, "\treturn d;\n}\n");
+ fprintf(fp, "SDREND\n\n");