Search Unity

I want my camera to render like a 360 video. Is it possible?

Discussion in 'General Graphics' started by danBourquin, Sep 18, 2019.

  1. danBourquin

    danBourquin

    Joined:
    Nov 16, 2016
    Posts:
    34
    Hello guys,

    I'm looking to create a game where the camera will render the word like a 360° video on youtube but flat.
    I want a rectangle with the world a bend inside it and where the player can see all over himself in one screen. It has to look like the following picture , but only one half is enought for me, I don't want to make 3D.



    The picture comes from a unity blog article about capturing a video on a 360° format.
    I look for the same render but I dont want to capture a video. The player should be able to play and seing this render..
    Do you have any clue in what direction can I search for informations about making that ? Maybe I can solve this problem by making a shader who'll move the vextex and bend the world ?

    I'm interested in any solution no matter if it's a paid asset, or maybe hire someone or making my own shader.
    For now I'm stuck because I don't know in what direction I should search. And maybe it's not possible..

    Thank you for your help and sorry for my english.

    Dan
     
  2. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    Try google "Quake 360 camera", if I remember correctly you can get full source of this project.
     
  3. danBourquin

    danBourquin

    Joined:
    Nov 16, 2016
    Posts:
    34
    Thank you I'll take a loot at the source code. I presume it's a shader or something. Any other clues?
     
  4. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    It's shader have two problem:
    1st age of screen is warp zone, I think it can be fixed with geometry shader, but I never use them before.
    2nd Far away objects become too small too fast.


    Code (CSharp):
    1. Shader "Unlit/CylProj"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.     }
    7.     SubShader
    8.     {
    9.         Tags { "RenderType"="Opaque" }
    10.         LOD 100
    11.  
    12.         Pass
    13.         {
    14.             CGPROGRAM
    15.             #pragma vertex vert
    16.             #pragma fragment frag
    17.             // make fog work
    18.             #pragma multi_compile_fog
    19.  
    20.             #include "UnityCG.cginc"
    21.  
    22.             struct appdata
    23.             {
    24.                 float4 vertex : POSITION;
    25.                 float2 uv : TEXCOORD0;
    26.             };
    27.  
    28.             struct v2f
    29.             {
    30.                 float2 uv : TEXCOORD0;
    31.                 UNITY_FOG_COORDS(1)
    32.                 float4 vertex : SV_POSITION;
    33.             };
    34.  
    35.             sampler2D _MainTex;
    36.             float4 _MainTex_ST;
    37.  
    38.             v2f vert (appdata v)
    39.             {
    40.                 v2f o;
    41.  
    42.                 float4 worldPos = mul(unity_ObjectToWorld, v.vertex);
    43.  
    44.                 float angleY = atan2(worldPos.z, worldPos.x);
    45.                 angleY/=UNITY_TWO_PI;
    46.                 float dist = length(worldPos);
    47.  
    48.                 worldPos.z = dist;
    49.                 worldPos.x = angleY;
    50.  
    51.                 worldPos.y/=10;
    52.                 worldPos.y *= -1;
    53.                 worldPos.w = 0.5;
    54.  
    55.                 worldPos.z /= 100;
    56.                 worldPos.z = 0.5-worldPos.z;
    57.  
    58.  
    59.                 o.vertex = worldPos;
    60.  
    61.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    62.                 return o;
    63.             }
    64.  
    65.             fixed4 frag (v2f i) : SV_Target
    66.             {
    67.                 // sample the texture
    68.                 fixed4 col = tex2D(_MainTex, i.uv);
    69.                 UNITY_APPLY_FOG(i.fogCoord, col);
    70.                 return col;
    71.             }
    72.             ENDCG
    73.         }
    74.     }
    75. }
    76.  
     
    Last edited: Sep 19, 2019
  5. danBourquin

    danBourquin

    Joined:
    Nov 16, 2016
    Posts:
    34
    Thank you for the shader and the video. It's very helpfull.
    This cylindral projection is a good start. Has the shader have to be applied on each object ? Would be possible to make a shader like a post-processing effect who make the job ?
     
  6. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    I think you may do render to cubemap then do opposite thing to what I did in that shader: remap x axis of camera space(angle) to xz component of vector and use a Y component as is. Then you get that vector and sample with them from cubemap.
    I suspect Unity already have tool for render a panoramic texture, and you just missed it somehow.