Search Unity

3d mesh reconstruction from panorama image

Discussion in 'General Graphics' started by lyzband, Dec 17, 2018.

  1. lyzband

    lyzband

    Joined:
    Nov 30, 2012
    Posts:
    3
    Hello there,

    I need some help with reconstructing 3d mesh from panorama image since I am lack of 3d environmental development.

    xyz values of each vertice are already given so I can generate a mesh with them but the I am stuck in warping/folding the source image to wrap the generated mesh.

    It might sound similar to cube map generation, but the problem is that the source image is not always cube-formed. It can be any kind of prisms.

    How can I wrap the 3d mesh with panorama image as attached with given values of corners, edges and xyz?
     
    Last edited: Dec 19, 2018
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    The easiest solution is to use a cubemap still. It doesn't matter that the resulting room isn't always a cube. You just need a shader that passes in the float3 local space vertex position as the UVWs for the cubemap's uv.

    Code (CSharp):
    1. Shader "Cubemap Room"
    2. {
    3.     Properties
    4.     {
    5.         _CubeTex ("Room Interior", Cube) = {}
    6.     }
    7.     SubShader
    8.     {
    9.         Pass
    10.         {
    11.             CGPROGRAM
    12.             #pragma vertex vert
    13.             #pragma fragment frag
    14.             #include "UnityCG.cginc"
    15.  
    16.             void vert(appdata_base v, out float4 pos : SV_POSITION, out float3 uvw : TEXCOORD0)
    17.             {
    18.                 pos = UnityObjectToClipPos(v.vertex.xyz);
    19.                 uvw = v.vertex.xyz;
    20.             }
    21.  
    22.             uniform samplerCUBE _CubeTex;
    23.  
    24.             fixed4 frag(float3 uvw : TEXCOORD0)
    25.             {
    26.                 return texCUBE(_CubeTex, uvw);
    27.             }
    28.             ENDCG
    29.         }
    30.     }
    31. }
     
    lyzband likes this.
  3. lyzband

    lyzband

    Joined:
    Nov 30, 2012
    Posts:
    3
    Hello @bgolus I do appreciate your answer it really helps me.

    The following is the result of the wrapped mesh which your source code is applied.
    (I used a different image from the original post)

    But as you can see the suggested green lines(which are the output of testing model) and edges of mesh do not match perfect.
    I guess that’s because I just used a random pano-to-cubemap tool from internet to convert cube map while my faces are neither square nor rectangle but more like distorted rectangles(any kinds of tetragons).

    For those reasons, I think I should manually convert my panorama image into cube map. Could you give me any suggestions?
     
    Last edited: Dec 19, 2018
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    Unity can convert 360 panoramas to cubemaps automatically. Just put the panorama texture into your assets folder, and change the Shape to Cube. Assuming the 360 panorama is in the usual equirectangular form, it should convert perfectly.
     
    lyzband likes this.
  5. lyzband

    lyzband

    Joined:
    Nov 30, 2012
    Posts:
    3
    YES it is working perfect
    thanks a lot!
     
  6. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    300
    Hi i am tring to use the shade but i get this error:


    Shader error in 'NewUnlitShader': Parse error: syntax error, unexpected '{', expecting TVAL_STRING at line 5

    Any hint how to solve it?