- Home /
Equirectangular camera projection of a scene in Unity
I am looking for a way to do an equirectangular render of a scene in Unity. I don't want to use a cube map or other equirectangular image and project it onto an inverted sphere like many examples I found online. I want to output my current scene in Unity to an equirectangular projection in the game window.
I thought of using a replacement shader on my camera that converts all the cartesian coordinates of each object to spherical coordinates and then pass the spherical coordinates to the output vertex. After all this my projection in the game window seems really messed up.
Following is the vertex shader I used to make the transformation.
v2f vert (appdata v)
{
v2f o;
float3 pos = UnityObjectToViewPos(v.vertex);
float azimuth = atan2(pos.y, pos.x);
float radius = sqrt((pos.x * pos.x) + (pos.y * pos.y) + (pos.z * pos.z));
float elevation = asin(pos.z / radius);
o.vertex = UnityObjectToClipPos(v.vertex);
o.vertex.x = azimuth;
o.vertex.y = elevation;
o.vertex.z = radius;
o.vertex.w = 1.0;
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
Your answer
Follow this Question
Related Questions
Image Effect - Screen coordinates 1 Answer
Render everything in black, but the enemies in red 2 Answers
Best way to swap between view modes 0 Answers
CommandBuffer's CameraEvent ordering not in sync with shader rendering queue? 1 Answer
"Motion vectors" and "depth with normals" from camera's target texture 1 Answer