Search Unity

Question Stereographic projection and world bending

Discussion in 'Shader Graph' started by Kazuya_Yoshimisu, May 9, 2020.

  1. Kazuya_Yoshimisu

    Kazuya_Yoshimisu

    Joined:
    Oct 20, 2019
    Posts:
    2
    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!
     
  2. kholera

    kholera

    Joined:
    Mar 6, 2014
    Posts:
    9
    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.
     
  3. eyeballTickler

    eyeballTickler

    Joined:
    Jun 13, 2015
    Posts:
    7