1
\$\begingroup\$

I'm creating a game in Unity. I have a iso sphere or polygon sphere, and I want to project a 360 video on the inside of the polygon sphere.

I've learned thow to put a 360 video on the inside of a sphere, following this thread, but how can I do it inside a polygon sphere, since the 360 video was created based on a sphere but not a polygon sphere?

Shader "Flip Normals" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
    }
    SubShader {

        Tags { "RenderType" = "Opaque" }

        Cull Off

        CGPROGRAM

        #pragma surface surf Lambert vertex:vert
        sampler2D _MainTex;

        struct Input {
            float2 uv_MainTex;
            float4 color : COLOR;
        };

        void vert(inout appdata_full v) {
            v.normal.xyz = v.normal * -1;
        }

        void surf (Input IN, inout SurfaceOutput o) {
             fixed3 result = tex2D(_MainTex, IN.uv_MainTex);
             o.Albedo = result.rgb;
             o.Alpha = 1;
        }

        ENDCG

    }

      Fallback "Diffuse"
}
\$\endgroup\$
1
\$\begingroup\$

The principle isn't really any different.

Inside the fragment shader you compute a latitude & longitude by converting the shaded point's offset from the center of the sphere from Cartesian to spherical coordinates.

Then you use that lat/long pair as the texture coordinate to look up into your video texture (assuming your video is in equirectangular projection - you'd use different formulas for other projections)

Even with a mesh that's already unwrapped in lat-long format, you should really do this mapping in the shader anyway - affine texture mapping alone can't handle the distortion at the poles of the sphere correctly.

You can see an example of this texture mapping distortion and how to fix it with a shader in one of my earlier answers on the subject.

\$\endgroup\$
  • \$\begingroup\$ can you please provide a more detailed instruction? Or links to related links or tutorials where I can learn? I'm quite new to Unity and don't have much experience with shader to achieve this. \$\endgroup\$ – practicemakesperfect Apr 10 '18 at 23:33
  • \$\begingroup\$ Yep - linked to one of my earlier answers. Don't forget to search; chances are you're not the first one to have a particular problem. ;) I've added a 360-video tag to the 11 questions we have on the subject so far to make them easier to find. \$\endgroup\$ – DMGregory Apr 10 '18 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.