https://github.com/adcimon/com.adcimon.raymarching
Raymarching library.
https://github.com/adcimon/com.adcimon.raymarching
raymarching unity
Last synced: 1 day ago
JSON representation
Raymarching library.
- Host: GitHub
- URL: https://github.com/adcimon/com.adcimon.raymarching
- Owner: adcimon
- License: mit
- Created: 2019-07-02T20:53:18.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-02T17:57:30.000Z (about 2 years ago)
- Last Synced: 2026-03-07T03:43:45.338Z (4 months ago)
- Topics: raymarching, unity
- Language: HLSL
- Homepage: https://youtu.be/AVqy9PmbVVs
- Size: 19 MB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Raymarching
Library to render signed distance fields with raymarching in Unity.



## Usage
1. Attach a `Raymarcher` component to the camera.

2. Select the material used to render. Two materials are included in the package, `RaymarcherUnion` and `RaymarcherSmoothUnion`.

3. Add a `RaymarchPrimitive` component to a gameobject.

4. Select the parameters and material used to render the primitive.

5. Add the `RaymarchPrimitive` component to the primitives list of the `Raymarcher` component.

Now you can move, rotate or scale the raymarch primitive with the Unity transform tools.
## Advanced
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:
1. Iterates over the primitives array.
2. Transforms the target position from world space to the primitive local space.
3. Calculates the distance using the signed distance function of the primitive at the transformed position.
4. The union operator `data.distance = opUnion(data.distance, d)` is applied to the primitives. Other operators can be found in the files [SignedDistanceOperations.hlsl](ShaderLibrary/SignedDistanceOperations.hlsl) and [SignedDistanceBooleanOperations.hlsl](ShaderLibrary/SignedDistanceBooleanOperations.hlsl).
5. Returns the data of the closest primitive.