Hi I've made a beveled cube by doing an intersection on all of the edges of a cube with a bunch of planes. I have a couple of technical difficulties and am also wondering if this the most efficient way to go about doing this. Basically I've taken the cube and intersected it 12 times with 12 different planes to cut off the 12 edges. I think I could do the same thing by intersecting the cube with 3 rotated cubes but I'm not sure if that would be more efficient if I needed to use a rotation matrix to rotate the cubes.
float bevCube (vec3 p, vec3 s, float b)
{
float cCut= b + length(vec3(1.0,1.0,1.0)*b) - length(vec3(1.0,1.0,0.0)*b);
float box = sdBox(p,s);
//Top edges
float cut1 = sdPlane(p,normalize(vec4(0.0,1.0,1.0,-b)));
float cut2 = sdPlane(p,normalize(vec4(0.0,1.0,-1.0,-b)));
float cut3 = sdPlane(p,normalize(vec4(1.0,1.0,0.0,-b)));
float cut4 = sdPlane(p,normalize(vec4(-1.0,1.0,0.0,-b)));
float m1 = max(max(max(cut1,cut2),cut3),cut4);
//bottom edges
float cut5 = sdPlane(p,normalize(vec4(0.0,-1.0,1.0,-b)));
float cut6 = sdPlane(p,normalize(vec4(0.0,-1.0,-1.0,-b)));
float cut7 = sdPlane(p,normalize(vec4(1.0,-1.0,0.0,-b)));
float cut8 = sdPlane(p,normalize(vec4(-1.0,-1.0,0.0,-b)));
float m2 = max(max(max(cut5,cut6),cut7),cut8);
//vertical edges
float cut9 = sdPlane(p,normalize(vec4(1.0,0.0,1.0,-b)));
float cut10 = sdPlane(p,normalize(vec4(-1.0,0.0,1.0,-b)));
float cut11 = sdPlane(p,normalize(vec4(1.0,0.0,-1.0,-b)));
float cut12 = sdPlane(p,normalize(vec4(-1.0,0.0,-1.0,-b)));
float m3 = max(max(max(cut9,cut10),cut11),cut12);
//top corners
float cut13 = sdPlane(p,normalize(vec4(1.0,1.0,1.0,-cCut)));
float cut14 = sdPlane(p,normalize(vec4(-1.0,1.0,1.0,-cCut)));
float cut15 = sdPlane(p,normalize(vec4(1.0,1.0,-1.0,-cCut)));
float cut16 = sdPlane(p,normalize(vec4(-1.0,1.0,-1.0,-cCut)));
float m4 = max(max(max(cut13,cut14),cut15),cut16);
//bottom corners
float cut17 = sdPlane(p,normalize(vec4(1.0,-1.0,1.0,-cCut)));
float cut18 = sdPlane(p,normalize(vec4(-1.0,-1.0,1.0,-cCut)));
float cut19 = sdPlane(p,normalize(vec4(1.0,-1.0,-1.0,-cCut)));
float cut20 = sdPlane(p,normalize(vec4(-1.0,-1.0,-1.0,-cCut)));
float m5 = max(max(max(cut17,cut18),cut19),cut20);
return max(max(max(max(max(box,m1),m2),m3),m4),m5);
So my first question is this - is this the best way to go about doing this? I would like to use this a building block for a fractal so it be nice if it was the least amount of processing possible
If so I'm having one problem with this method. In order to bevel the corners after the edges have been beveled I've used another 8 planes to cut these corners. I can't seem to figure out the proper distance to cut this corner in relation to the cut edges. I've tried to take the length of the distance to the corner - length to the edge and adding that to distance of the bevel but it isn't right. Would anyone have any insight on how to do this calculation?
Below are two images. One of what it should look like at all bevel scales and another at using the cCut line of code above.