- Home /

# True Non-Euclidean Space

Can a truly non-Euclidean space be implemented in Unity (using unlit shaders)?

For example, on a spherical surface, from the perspective of the camera I can see an object in front of me, and as I approach it, it becomes larger. However, once I pass the object, the object is now translated to its maximum distance from my current position, only it is still in my forward view. Thus, there is no perception of local curvature; the world appears flat from the camera's perspective, but the perception of distance and angle is manipulated to be consistent with non-Euclidean properties.

I am deliberately excluding examples such as Portal, and cases that involve portals, because these are more accurately described as impossible spaces, and do not have a single veridical representation that can be assessed as accurate or not.

Do you want your objects to reside in normal euclidean space, but just be drawn differently? If so, you probably want to look at manually setting the camera's projection matrix. WHAT values to use for that kind of projection matrix, I don't think I can help with.

Interesting idea. I'm not sure that manipulating the projection matrix will generate the desired effect. For example, for an observer at any given point on a sphere, you will be able to see the back of your head located at the maximum distance on the horizon. So, I'm hoping the effect can be achieved by constantly updating the position of game objects in the view frustum. My concern is that constantly transforming the position of game objects in the update will be computationally demanding. Fortunately, I only need to do this for a few objects.

**Answer** by Baxter900
·
Oct 22, 2015 at 08:12 AM

To my knowledge, no, you can't use true non-euclidean space. However, there are two ways I can think of to simulate it.

The first way is to use a shader. This seems to be what you were asking in actuality, but it's not true non-euclidean space. Rather, everything would exist in euclidean space, and would just appear to be non-euclidean. For example, let's take translating euclidean to spherical space. You'd want to use a sphere instead of any actual planes in order for things to look normal, then you'd have to warp each asset such that with the offset through the translation, the mesh still looks normal. You'd then make a sphere without a collider, and make it as big as the world space is. You'd then want to write a volumetric shader which skews light such that it rotates around the center of the object. This should provide the effect you're looking for, but it would be a pain in the neck to manage. You'd need to mess with the rotation of the character a ton, and manually make gravity. It would be tricky to work with, because all of the Unity methods still operate in euclidean space, and you'd be effectively working in spherical space.

The other way to make this effect is just to simulate it. There's a bunch of jumping through hoops that you'd have to do, but essentially, here's the rundown. Create a floor plane with the edges surrounded by wall planes orthogonal to the first plane with render textures on them. Attach a camera to the center of each bordering plane and slightly in front, then bind the render texture of each plane to the camera on the opposite plane. You'll have to mess with the FOV until it looks right on them. Next, just attach a script so that if anything interactive collides with a plane, it's transported to the opposite side. There, now you have a simulation of spherical space in euclidean space.

Now this method isn't perfect (for example, perpendicular lines still don't intersect), but it's a good start. You can't make truly non-euclidean space in an engine built for euclidean space, simple as that. Note that, as with truly spherical space, this would show the objects repeating infinitely into the distance. Anyway, hope this helps!!!

EDIT: Two extra things I thought of, the wall planes should be infinitely high, and they should actually not be planes, but rather, cubes which extend into the space you can't enter. Just make sure to include the objects distance from the surface when determining where to teleport it.

First, I'd like to thank you and @Bunny83 for taking the time to contemplate some of the design considerations with me and much of what you have described has been immensely helpful.

Taken together, I agree that the current best solution is to simulate NE space, rather than fully, mathematically, generate it.

@Baxter900, many of your suggestions are promising starting points. For example, setting up orthogonal cubes with render textures on opposite faces. Also, your idea for a volumetric shader to rotate light around the center of the sphere sounds exactly right, but implementing that might be outside my scope.

That being said, @Bunny83, your suggestion to convert to spherical coordinates is also an interesting suggestion, and what I had consider initially. Although, as you mentioned, frustum culling is an obvious drawback, but might be avoided by duplicating geometry for some objects.

There are several assets and open source packages that will enable curved surfaces (screen space and otherwise) and circular gravity. I'm contemplating whether I can invert one of these effects to achieve a similar NE effect. For example, create a sphere, apply circular gravity, then apply screen space (anti)curvature to invert curvature of the geometry, which might result in the rotation / position changes consistent with an NE space. Not clear, will have to test.

**Answer** by Bunny83
·
Oct 21, 2015 at 09:01 PM

Your description sounds a bit strange and is missing some facts. Since a spherical space wraps around itself you're missing the fact that you'll see endless versions of your object, not just one. If you stand right beside your object you can also see it at `n*2*R*PI`

distance where n is a whole number. You can't really render such an infinite space. You can unroll it and render some iterations. However a sherical space viewed as infinite linear space has extreme distortions near the center and at a higher distance above your "surface".

In your linear space up and down would represent going along the a ray that starts at the center of your sphere. Once you reach the center you can't go further down. At the center you actually have a singularity. Likewise you have a singularity at `n*R*PI`

for any whole number n (which is half the distance around the sphere) So if you stick a pole into the other side of the sphere you would see it wrapped around the horizon, no matter in what direction you look.

Keep in mind that for example a box in the spherical space would need to have a reversed frustum shape (where the focal point is the sphere's center) in order to appear like a cube in the linear projection. Also keep in mind that any rotation that is not around the sphere's normal axis will heavily distort the object. This effect get's worse the farther you get from the surface of your sphere

What would be the purpose of such a space? As far as i know the space you describe is actually also an euclidean space. Like the a N-Sphere space. In an elliptic or hyperbolic space (which are actual non-Euclidean spaces) you don't get those features you were talking about. You don't get back to where you started in those spaces.

This project is exclusively for scientific purposes, specifically in terms of visual cognition and human performance.

The purpose would be to investigate how humans develop representations for non-Euclidean (NE) spaces. There is similar work investing four dimensional spatial representations, but not for Euclidean space. Importantly, this research question is distinct from whether or not individuals are able of conceptualizing, or reasoning about, NE space; the answer, of course, is rhetorical given it's existence in the first place.

I agree there are some practical limitations to implementing a 'true' NE virtual space, including infinite recursions and so forth. Although, I believe it is possible to create a reasonable facsimile of navigation through a NE space, by implementing some of the major considerations, including what you have outlined above. However, I am not concerned with movements through the sphere, but along it's surface, at which point - as you mentioned - perturbations will occur in the relative position and rotation (and sheer?) of the game objects.

One possibility is to create a straight line path along the curve of the surface, thus preventing free exploration and associated distortions. For obvious reasons, this would be a major methodological problem, but probably a good starting point.

Unfortunately i don't have time to try some implementations since i'm away for a week. However I think there's no way to do that with a simple matrix transformation since a 4x4 matrix can only perform affine transformations.

The easiest solution would be to positioning all objects on a real sphere in the normal cartesian system and manually convert all objects / vertices into spherical coordinates. Now just treat the spherical coordinates like cartesian coordinates. So the both angles would represent the x and z direction and the radius y. This will give you a finite rectangle with the objects more or less correctly "distorted". Keep in mind that a simple cube can never look curved unless it has enough subdivided vertices.

When you do the cartesian to spherical coordinates you (the camera) should always represent the center of the rectangle. That rectangle just need to be repeated in both axis as far / often as you want or your PC can handle.

It's going to be very tricky to implement this in a shader especially since you have to ensure that the meshes aren't frustum culled. One solution is to preprocess all meshes and place all meshrenderer right in front of the camera and offset the actual vertices accordingly to match the actual position on the sphere. Then it's possible to do the cartesian to spherical conversion in the shader.

Another solution would be to simple rebuild the scene as rectangle from the source objects manually in a script. This has the advantage that the actual scene is flat which simplifies physics and other things.

**Answer** by bntr
·
Dec 08, 2017 at 04:33 AM

I use Vertex Shader to relocate all vertices according to elliptic geometry: https://bntr.itch.io/sfera

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.