Give me the glsl for an implicit function that represents the union of a box and a…
- User
Give me the glsl for an implicit function that represents the union of a box and a sphere. The sphere should be positioned at the corner of the box.
- Assistant
Here's a GLSL function that represents the union of a box and a sphere, with the sphere positioned at the corner of the box.
vec3 boxSize = vec3(1.0, 1.0, 1.0); // Set the dimensions of the box float sphereRadius = 1.0; // Set the radius of the sphere float sdBox(vec3 p, vec3 b) { vec3 d = abs(p) - b; return min(max(d.x, max(d.y, d.z)), 0.0) + length(max(d, 0.0)); } float sdSphere(vec3 p, float r) { return length(p) - r; } float unionOp(float d1, float d2) { return min(d1, d2); } float scene(vec3 p) { vec3 boxCorner = boxSize * 0.5; float boxDist = sdBox(p - boxCorner, boxSize * 0.5); float sphereDist = sdSphere(p - boxCorner, sphereRadius); return unionOp(boxDist, sphereDist); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.