top of page
  • Writer's pictureFloney Yang

Collision Detection for Raymarch Objects

Updated: Apr 19, 2021

Development Updates this week

Interview with Filipe Deó

Filipe Deó is a former engineer/researcher in Computer Graphics and the author of a published research article on non-Euclidean geometries, Geometry independent game encapsulation for non-Euclidean geometries. Here are what I learned from our interview:

1. Filipe built his research using 2D engines (CoffeeScript/js IIRC) and WebGL.

2. To leverage the uniqueness of non-Euclidean geometries/higher-dimensional space is hard, and there are not a lot of games that have successfully produced good results. Most of the game in this area have some sort of academic drive behind them (e.g. HyperRogue, Jeff Weeks hyperbolic games, etc.), including his own game(demo:

3. The real challenge is the playability of this type of game: How to make players understand and enjoy the game world logic? How to find a good game mechanic that fits into the higher dimensional game concept?

Collision Detection for Raymarch Objects

In order to achieve the collision detection effects for raymarched mesh, I need to find a way to compute distance function data using a shader. However, this is quite hard to achieve since the shader file type is not designed for calculation. In order to achieve collision detection with raymarch shader, I implemented several steps:

1. After carefully studying/watching @Jelle Vermandere’s youtube videos on raymarching, I moved all the distance functions from raymarch shader to a separate file with .cginc(DistanceFunction.cginc) format that can both be used in shader and Unity inspector.

2. Based on the information I found from @Sebastian Lague’s source code for his raymarcher project, I implemented a C# file that initializes a 4D object class containing all the information needed for different 4D shapes. By making this a C# file, I can easily manipulate the shape data in Unity inspector and use a set parameter function to send those data to raymarch shader.

3. I added a capsule as a player object and added 14 empty objects used as transform positions that cover all colliding faces on this capsule as children to the player object. Then I use a Collider script to loop through those 14 transform positions to calculate their distance from the raymarch objects based on the distance function. And if the distance is smaller than 0, the player is moved in the opposite direction.

Camera Rendering Cost for 4D Objects

Using the method I learned from @Jelle Vermandere’s video, I used a ComputeBuffer component in Unity render and added a 2D quad with a camera render texture to render the pixels onto a less resolution 2D quad canvas.


I successfully created “imperfect” collision detection for some basic raymarch objects. But when the player is at the back of the objects, the calculation for collision still has some issues: sometimes the player doesn’t collide with objects when the camera ray doesn’t hit the player directly.

Objectives for next week

1. I will continue working on collision detection for 4D objects to achieve better collision results.

2. I will start experimenting with game ideas combined with the current experimental results.

3. Interview with The developer of Hyperbolica to gain more information on hyperbolic space.

4. I will try to implement fractals if one of the three objectives above encounters issues.

Learning Resources:

1. Ray Marching/Distance functions:

2. Sebastian Lague Github:

3. Jelle Vermandere youtube videos:

bottom of page