Video player as texture, can't set tiling
I am developing a stereoscopic 360 video player to play 3d 360 videos. I have a 2k test video that has a horizontal split separating the two sources. My plan is to render this using a video player component on a couple of unity spheres which will be shown to each eye via layers. To make each sphere play the right portion of the video I planed to use separate materials for each sphere with the left one having tiling and offset of 0.5 on the y axis and the right one having 0.5 tiling and 0 on offset. When I run the player though the tiling sets itself to 1 and reverts back to my settings when the player turns off.
Is this a feature of the video texture that I'm misunderstanding? How do I set the tiling on my video texture?
UPDATE: I've made some progress, I noticed that when the video starts playing it was inserting a generated texture into the spheres shader so I manually made a render texture in my assets folder, assigned it to the shader and also assigned it as the target texture of the video player (nice side benefit of this is I only need 1 video player). Now the settings don't reset, they just don't do anything. The values stay in place when I play the video but the video is still showing everything rather than just the top and bottom half (one in each sphere that is) as I was expecting. I'm half way here now, if anyone can give me a nudge in the right direction I'd really appreciate it.
Answer by al1006g · Jul 26, 2017 at 02:13 PM
i have the same problem but i somehow solved it by scripting the shader.
i created a new float4 Vector and multiply the xy to the tiling, and add the zw to the offset. It works successfully but i used separate materials for 2 sphere.
I am new to Unity and Shader so this is the only way i could think of.
Here is my shader code:
Shader "Unlit/newShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Vector ("myVector", Vector) = (1,1,0,0)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
Cull Front
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Vector;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
//o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
_MainTex_ST.x = _MainTex_ST.x * _Vector.x;
_MainTex_ST.y = _MainTex_ST.y * _Vector.y;
_MainTex_ST.z = _MainTex_ST.z + _Vector.z;
_MainTex_ST.w = _MainTex_ST.w + _Vector.w;
o.uv = v.uv.xy * _MainTex_ST.xy + _MainTex_ST.zw;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Just change the value in the myVector and it will do the tiling and offset.
I hope this helps.