Advertisement
dnnkeeper

Unity_PhotosphereShader

Jun 11th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. Shader "PhotosphereSky"
  2. {
  3.     Properties {
  4.         _MainTex ("", 2D) = "white" {}
  5.     }
  6.     SubShader
  7.     {
  8.         Tags { "Queue"="Background" "RenderType"="Background" }
  9.         Cull Off ZWrite Off Fog { Mode Off }
  10.        
  11.         Pass {
  12.            
  13.             CGPROGRAM
  14.             #pragma vertex vert
  15.             #pragma fragment frag
  16.            
  17.             #include "UnityCG.cginc"
  18.             #include "Lighting.cginc"
  19.  
  20.             #define PI 3.141592653589793
  21.  
  22.             uniform sampler2D _MainTex;
  23.  
  24.             struct v2f
  25.             {
  26.                 float4 pos : SV_POSITION;
  27.                 float2 uv : TEXCOORD0;
  28.                 float3 dir : TEXCOORD1;
  29.             };
  30.  
  31.             v2f vert(appdata_base v)
  32.             {
  33.                 v2f OUT;
  34.  
  35.                 OUT.pos = mul (UNITY_MATRIX_MVP, float4(v.vertex.xyz,1.0));
  36.                 OUT.uv =
  37.                 v.texcoord.xy;
  38.                
  39.                 OUT.dir =
  40.                 v.vertex.xyz;
  41.                 //mul(_Object2World, v.vertex).xyz;
  42.                 //- _WorldSpaceCameraPos;
  43.                
  44.                 return OUT;
  45.             }
  46.            
  47.             float4 frag(v2f IN) : COLOR
  48.             {
  49.                 float3 d = -normalize(IN.dir);
  50.  
  51.                 float2 uv =
  52.                 float2(0.5+atan2(d.z,d.x)/(2*PI),0.5-asin(d.y)/PI);
  53.  
  54.                 half4 col;
  55.                
  56.                 //anti-seam conditions
  57.                 if ( uv.x < 0.001){
  58.                     col = tex2D(_MainTex, float2(0.0, uv.y) );
  59.                    
  60.                 }
  61.                 else if ( uv.x > 0.999){
  62.                     col = tex2D(_MainTex, float2(1.0, uv.y) );
  63.                 }
  64.                 else
  65.                 {
  66.                     col =
  67.                     tex2D(_MainTex, uv );
  68.                 }
  69.                
  70.                 return col;
  71.             }
  72.  
  73.             ENDCG
  74.         }
  75.     }
  76.     Fallback off
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement