Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Video VideoPlayer Tiling?

Discussion in 'Audio & Video' started by mark-007, Nov 2, 2017.

  1. mark-007

    mark-007

    Joined:
    Mar 4, 2015
    Posts:
    27
    Hi All,

    I'm using the new VideoPlayer component to display a monoscopic 2D video (360 on Android). I need to adjust the tiling (eg set Y to -1 to flip the texture) but on playing the VideoPlayer resets this to 1 when playing, then sets it back to -1 when I stop the app.

    I found another thread where someone asked about this and is having the same issue but there appears to be no answer just a workaround...

    http://answers.unity3d.com/questions/1366010/video-player-as-texture-cant-set-tiling.html

    Is it a bug that the VideoPlayer sets the tiling? Is there any way to stop it from doing so?

    I note the response above that one can edit shaders, but that didn't work for me (not sure why yet). I also note that I can use "GoogleVR/Video Unlit Shader" and this correctly flips the texture - but the quality of the video using this texture seems quite poor (at least when used for 360).

    I'll likely be learning how to edit shaders in the next few days but wondered if this issue is by design or is a bug or if anyone knew any way to fix this without editing the shader.

    Thanks in advance :)
     
  2. mark-007

    mark-007

    Joined:
    Mar 4, 2015
    Posts:
    27
    Inspired by the other thread mentioned above (which unfortunately I couldn't get working for some reason) and the source of the GoogleVR/Unlit Video Shader, here is the shader that works for me which is a copy of the Unlit/Texture shader with a "Flip Y" option... It doesn't flip normals as the model I'm using already has normals flipped, but to do that I think you simply add "Cull Front" to Pass, please correct me if I'm wrong.


    Code (CSharp):
    1. Shader "Unlit/UnlitVideo"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.         [Toggle(FLIP_Y)] _FlipY ("Flip Y", Float) = 0
    7.     }
    8.     SubShader
    9.     {
    10.         Tags { "RenderType"="Opaque" }
    11.         LOD 100
    12.  
    13.         Pass
    14.         {
    15.             CGPROGRAM
    16.             #pragma vertex vert
    17.             #pragma fragment frag
    18.             // make fog work
    19.             #pragma multi_compile_fog
    20.             #pragma multi_compile ___ FLIP_Y
    21.        
    22.             #include "UnityCG.cginc"
    23.  
    24.             struct appdata
    25.             {
    26.                 float4 vertex : POSITION;
    27.                 float2 uv : TEXCOORD0;
    28.             };
    29.  
    30.             struct v2f
    31.             {
    32.                 float2 uv : TEXCOORD0;
    33.                 UNITY_FOG_COORDS(1)
    34.                 float4 vertex : SV_POSITION;
    35.             };
    36.  
    37.             sampler2D _MainTex;
    38.             float4 _MainTex_ST;
    39.        
    40.             v2f vert (appdata v)
    41.             {
    42.                 v2f o;
    43.                 o.vertex = UnityObjectToClipPos(v.vertex);
    44.  
    45.                 #ifdef FLIP_Y // Inspired by GoogleVR/Video Unlit Shader
    46.                     v.uv.y = 1.0 - v.uv.y;
    47.                 #endif  // FLIP_Y
    48.  
    49.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    50.                 UNITY_TRANSFER_FOG(o,o.vertex);
    51.  
    52.                 return o;
    53.             }
    54.        
    55.             fixed4 frag (v2f i) : SV_Target
    56.             {
    57.                 // sample the texture
    58.                 fixed4 col = tex2D(_MainTex, i.uv);
    59.                 // apply fog
    60.                 UNITY_APPLY_FOG(i.fogCoord, col);
    61.                 return col;
    62.             }
    63.             ENDCG
    64.         }
    65.     }
    66. }