Last active
February 13, 2022 00:46
-
-
Save shivaduke28/86f0c4ae63c623bfb314bb073ea0dfc5 to your computer and use it in GitHub Desktop.
VRでテクスチャをスクリーンスペースに表示するやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float _Alpha; | |
sampler2D _MainTex; | |
float4 _MainTex_TexelSize; | |
float _Scale; | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
float4 screenPos : TEXCOOR0; | |
float aspect : TEXCOORD1; | |
}; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.screenPos = ComputeScreenPos(o.vertex); | |
// (tex h / tex w) * (screen w / screen h) | |
o.aspect = _MainTex_TexelSize.w * _MainTex_TexelSize.x * _ScreenParams.x * (_ScreenParams.w - 1); | |
return o; | |
} | |
fixed4 frag(v2f i) : SV_Target | |
{ | |
half4 col; | |
float2 uv = i.screenPos.xy / i.screenPos.w; | |
#if UNITY_SINGLE_PASS_STEREO | |
float4 scaleOffset = unity_StereoScaleOffset[unity_StereoEyeIndex]; | |
uv = (uv - scaleOffset.zw) / scaleOffset.xy; | |
#endif | |
float a = i.aspect; | |
uv.x = uv.x * a - (a - 1) * 0.5; | |
uv -= 0.5; | |
uv *= _Scale; | |
uv += 0.5; | |
col.rgb = tex2D(_MainTex, uv).rgb; | |
col.a = _Alpha; | |
return col; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment