a repository for recording different projection views (equirectangular, rectinlinear/gnomonic).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

94 lines
2.1 KiB

//Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Conversion/CubemapToEquirectangularGnomic" {
Properties{
_MainTex("Cubemap (RGB)", CUBE) = "" {}
_EquiRotation("Rotation X", Float) = 1.0
_EquiRotationY("Rotation Y", Float) = 1.0
_FOVScale_X("FOV X", Float) = 0.45
_FOVScale_Y("FOV Y", Float) = 0.1
}
Subshader{
Pass {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#define PI 3.141592653589793
#define TWOPI 6.283185307179587
#define PI_2 1.570796326794897
struct v2f {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
samplerCUBE _MainTex;
float _EquiRotation;
float _EquiRotationY;
float _FOVScale_X;
float _FOVScale_Y;
v2f vert(appdata_img v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
return o;
}
fixed4 frag(v2f i) : COLOR
{
float2 q = i.uv;
float2 cp = (float2(PI + _EquiRotation,PI_2) * 2.0 - 1.0) * float2(PI, PI_2); // [-PI, PI], [-PI_2, PI_2]
// Convert screen coord in gnomonic mapping to spherical coord in [PI/2, PI]
float2 convertedScreenCoord = (q.xy * 2.0 - 1.0) * float2(_FOVScale_X, _FOVScale_Y) * float2(PI, PI_2);
float x = convertedScreenCoord.x;
float y = convertedScreenCoord.y;
float rou = sqrt(x * x + y * y);
float c = atan(rou);
float sin_c = sin( c );
float cos_c = cos( c );
float lat = asin(cos_c * sin(cp.y) + (y * sin_c * cos(cp.y)) / rou);
float lon = cp.x + atan2(x * sin_c, rou * cos(cp.y) * cos_c - y * sin(cp.y) * sin_c);
lat = (lat / PI_2 + 1.0) * 1.0;
lon = (lon / PI + 1.0) * 0.5; //[0, 1]
float2 final = float2(lon, lat) * float2(TWOPI, PI);
final.x = final.x;
final.y = final.y + _EquiRotationY;
float3 unit = float3(0,0,0);
unit.x = sin(final.y) * sin(final.x) * -1;
unit.y = cos(final.y * -1);
unit.z = sin(final.y) * cos(final.x) * -1;
return texCUBE(_MainTex, unit);
}
ENDCG
}
}
Fallback Off
}