Stereographic projection and world bending

Hello everyone,

I would like to create a “world-bending” shader using Unity’s Shader Graph Editor (and the Universal Render Pipeline). I want to make a shader that bends the world around you into a sphere.
For that I’m using the stereographic projection to map every vertex of my world to a sphere.
I’m only dealing with a flat plane for now so I’m just mapping using the x and z coordinates only.
The formula to map 2d point (x,y) into a 3d sphere (x,y,z) of radius 1 is the following:

And I tested it in GeoGebra to check if it worked:

So what I did is :

  • First, create two 2D vectors containing the x and z position of both the camera and the current vertex using Split and Vector2 nodes
  • Then substract those two vectors in order to have the position of the vertex relative to the camera’s position
  • Then, normalize this vector
  • This will be the input to my custom function that take a 2D vector and calculate the 3D position on the sphere using the Custom Function Node (I multiply the output by 100 in order to have a sphere of radius 100 in unity)
  • Finally, convert back the vector to the object’s frame of reference with the Transform node

But I can’t get it to work. Just nothing appears, where am I wrong ?

Here is a screen of my Shader Graph Editor along with my custom function’s code (click on it for a better view):


Any help is welcome!

Curious if you ever made progress on this issue. I was looking into this idea too recently and haven’t found any examples just yet.

This tutorial is spot on

It’s the same effect that games like Animal Crossing use for bending the horizon, and the same concept can be extended to 3 dimensions.

Also this asset seems to cover the same idea and take it a few steps further Curved World | VFX Shaders | Unity Asset Store