Returning a material ID alongside the SDF distance lets the raymarcher know which object was hit for shading
A basic map() returns only a distance. To shade different objects differently (floor green, body yellow, eyes white), map() must also return which object is closest. This is done by packing distance and material ID into a vec2 (or vec4 for more data): the raymarcher propagates this pair and the shading code branches on the ID. The union operator (min) must compare distances and keep the corresponding ID. This transforms a pure geometry function into a full scene description.
Examples
vec2 map(vec3 p){ vec2 floor=vec2(p.y+0.1, 1.0); vec2 body=vec2(sdEllipsoid(p,r), 2.0); return floor.x<body.x?floor:body; }
Assessment
What breaks if you use floor division instead of a float comparison when determining which material was hit? Describe a specific visual artifact.