Skip to content
TheChatArchiveThe Chat Archive
Qwenqwen-14b-chat· Alibaba (Qwen)Hugging Face Arena Human Preference 55K

Give me the glsl for an implicit function that represents the union of a box and a…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4-0314’s answer.
  1. 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.

  2. Qwen Assistant

    Here is an example of GLSL code for an implicit function that represents the union of a box and a sphere:

    vec3 signedDistanceFromBoxSphereIntersection(vec3 boxMin, vec3 boxMax, vec3 spherePos, float sphereRadius)
    {
        // Calculate the distance from the sphere position to the corner of the box
        float distToCorner = length(boxMin - spherePos);
    
        // If the sphere is outside the box, return a large negative distance
        if (distToCorner > boxMax.x + sphereRadius || distToCorner > boxMax.y + sphereRadius || distToCorner > boxMax.z + sphereRadius)
        {
            return vec3(-1.0);
        }
    
        // Calculate the distance from the sphere position to the center of the box
        float distToCenter = length(boxMin + (boxMax - boxMin) / 2.0 - spherePos);
    
        // If the sphere is inside the box, return a large positive distance
        if (distToCenter < sphereRadius)
        {
            return vec3(1.0);
        }
    
        // Otherwise, the sphere is intersecting the box, so calculate the signed distance
        // using the cross product of the vector from the sphere position to the corner
        // of the box and the vector from the sphere position to the center of the box
        vec3 cornerToSphere = spherePos - boxMin;
        vec3 centerToSphere = boxMin + (boxMax - boxMin) / 2.0 - spherePos;
        return cross(cornerToSphere, centerToSphere) / length(cornerToSphere);
    }
    

    This function takes as input the minimum and maximum coordinates of the box, the position of the sphere, and the radius of the sphere. It returns a 3D vector representing the signed distance from the sphere to the box. A positive distance indicates that the sphere is outside the box, a negative distance indicates that the sphere is inside the box, and a value of 0 indicates that the sphere is intersecting the box.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.