Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JackMini36 · Sep 24, 2018 at 09:55 AM · vrshaderstiling360stereo

Shader does not take tiling into account

So I am using this shader provided by Unity to make a 360 player. It works great for Mono videos, however when used for Stereo it is not working because the tiling values are not taken into account.

Here is the shader:

 Shader "360/Equirectangular"
 {
     Properties
     {
         _MainTex ("Diffuse (RGB) Alpha (A)", 2D) = "gray" {}
     }
 
     SubShader
     {
         Pass
         {
             Tags {"LightMode" = "Always"}
 
             Cull Front
 
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma target 3.0
 
             #include "UnityCG.cginc"
 
             struct v2f
             {
                 float4 pos : SV_POSITION;
                 float3 normal : TEXCOORD0;
             };
 
             v2f vert(float4 vertex : POSITION, float3 normal : NORMAL)
             {
                 v2f outCoords = { UnityObjectToClipPos(vertex), normal };
                 return outCoords;
             }
 
             #define ONE_OVER_PI .31830988618379067154F
 
             inline float2 ToRadialCoords(float3 coords)
             {
                 float3 normalizedCoords = normalize(coords);
                 float latitude = acos(normalizedCoords.y);
                 float longitude = atan2(normalizedCoords.z, normalizedCoords.x);
                 float2 sphereCoords = float2(longitude, latitude) * ONE_OVER_PI;
                 return float2(0.5F - sphereCoords.x * 0.5F, 1.0F - sphereCoords.y);
             }
 
             sampler2D _MainTex;
 
             fixed4 frag(v2f i) : SV_Target
             {
                 float2 equirectangularUV = ToRadialCoords(i.normal);
                 return tex2D(_MainTex, equirectangularUV);
             }
             ENDCG
         }
     }
     FallBack "VertexLit"
 }

Any ideas how to solve the tiling problem?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image madks13 · Sep 24, 2018 at 03:41 PM 0
Share

When you say 360, is it 360 like a 360 picture kind or 360 as in viewving a textured object from all angles kind? Also, stereo? Be more specific and add some details to your context. Not everyone that can help you knows what you are talking about.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Sep 24, 2018 at 10:52 PM

Well you have to take the tiling and offset into account yourself. Usually the incoming uv coordinates are modified through the TRANSFORM_TEX macro, but since it's your shader it's up to you how you want to affect the uvs. Keep in mind that TRANSFORM_TEX is just a macro and you have to declare the required variable yourself. See this question for reference


The macro is defined inside the Unity.cginc file (inside \Editor\Data\CGIncludes) and simply looks like this:

 #define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)

So all it actually does is multiplying the given coordinate by the "xy" component and adding the zw component. The xy is the scaling while the zw contains the offset. So in your case you need to declare this variable:

 float4 _MainTex_ST;

and do this:

 float2 equirectangularUV = TRANSFORM_TEX(ToRadialCoords(i.normal), _MainTex);

Which will actually translate to

 float2 equirectangularUV = ToRadialCoords(i.normal).xy * _MainTex_ST.xy + _MainTex_ST.zw;

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

360 video resolution (Gear VR) 1 Answer

360 video stitching bad when using Sphere Mesh and VideoClip 2 Answers

How Can I Combine Stereo Screen? 0 Answers

NVidia Flex VR Shader rendering issue 1 Answer

Play flat(not 360/180) stereo video in unity 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges