Skip to content

Commit

Permalink
Add UV Sky shader
Browse files Browse the repository at this point in the history
  • Loading branch information
synergiance committed Jun 27, 2020
1 parent b2b9884 commit 14d5f68
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
8 changes: 8 additions & 0 deletions UV Sky/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# UV Sky
A 360° video skybox shader.

## Download
Download the shader [here](UVSky.shader) and drag it into a shaders folder.

## How To Use
Create a new material, use the shader select to select `Synergiance/Skybox/UV Sky`, drag your desired texture into the texture slot. Use the slider below to adjust the orientation.
59 changes: 59 additions & 0 deletions UV Sky/UVSky.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Shader "Synergiance/Skybox/UV Sky"
{
Properties {
[NoScaleOffset] _MainTex ("Texture", 2D) = "default" {}
_Rotation ("Rotation (Degrees)", Range(-180, 180)) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

#define ONE_OVER_PI 0.31830988618

#if defined(USING_STEREO_MATRICES)
#define _ActualWorldSpaceCameraPos unity_StereoWorldSpaceCameraPos[unity_StereoEyeIndex]
#else
#define _ActualWorldSpaceCameraPos _WorldSpaceCameraPos
#endif

struct appdata {
float4 vertex : POSITION;
};

struct v2f {
float4 vertex : SV_POSITION;
float3 worldPos : TEXCOORD0;
};

sampler2D _MainTex;
float _Rotation;

v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
return o;
}

fixed4 frag (v2f i) : SV_Target {
float3 viewDir = i.worldPos.xyz - _ActualWorldSpaceCameraPos.xyz;
float longitude = atan2(viewDir.x, viewDir.z);
float latitude = atan2(length(viewDir.xz), viewDir.y);
float2 uv = float2(longitude * 0.5, latitude) * ONE_OVER_PI;
uv.x += _Rotation / 360;
fixed4 col = tex2D(_MainTex, uv);
return col;
}
ENDCG
}
}
}

0 comments on commit 14d5f68

Please sign in to comment.