Library to render signed distance fields with raymarching in Unity.
- Attach a
Raymarchercomponent to the camera.
- Select the material used to render. Two materials are included in the package,
RaymarcherUnionandRaymarcherSmoothUnion.
- Add a
RaymarchPrimitivecomponent to a gameobject.
- Select the parameters and material used to render the primitive.
- Add the
RaymarchPrimitivecomponent to the primitives list of theRaymarchercomponent.
Now you can move, rotate or scale the raymarch primitive with the Unity transform tools.
It is also posible to implement a more complex interaction between primitives creating a raymarcher shader. To create a raymarcher shader go to the context menu Create > Raymarcher Shader. The shader contains the function RaymarchData SignedDistanceField(float3 position) that is executed in the fragment shader. The function does the following calculations:
- Iterates over the primitives array.
- Transforms the target position from world space to the primitive local space.
- Calculates the distance using the signed distance function of the primitive at the transformed position.
- The union operator
data.distance = opUnion(data.distance, d)is applied to the primitives. Other operators can be found in the files SignedDistanceOperations.hlsl and SignedDistanceBooleanOperations.hlsl. - Returns the data of the closest primitive.







