Last active
October 24, 2021 16:42
-
-
Save shivaduke28/8a0ca981e7f5e198fe8e52783b415d6b to your computer and use it in GitHub Desktop.
skybox uv sphere shader
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
// ref: https://qiita.com/aa_debdeb/items/2739745b3ab1a003d767 | |
Shader "Skybox/UV" | |
{ | |
Properties | |
{ | |
[NoScaleOffset] _Tex ("Tex", 2D) = "white" {} | |
_Scale("Scale", float) = 1 | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
"RenderType"="Background" | |
"Queue"="Background" | |
"PreviewType"="SkyBox" | |
} | |
Pass | |
{ | |
ZWrite Off | |
Cull Off | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
static const float PI = 3.14159265f; | |
sampler2D _Tex; | |
float _Scale; | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float3 texcoord : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
float3 texcoord : TEXCOORD0; | |
}; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.texcoord = v.texcoord; | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
float3 p = i.texcoord; | |
float l_xz = length(float2(p.x, p.z)); | |
float y = (atan2(p.y, l_xz) / PI) + 0.5; | |
float x = (atan2(p.x, p.z) / PI + 1) * 0.5; | |
x = frac(x * _Scale); | |
y = frac(y * _Scale); | |
fixed4 col = tex2D(_Tex, float2(x,y)); | |
col.rgb *= col.a; | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment