Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yorung/62f69d3e5260a3bffeb1 to your computer and use it in GitHub Desktop.
Save yorung/62f69d3e5260a3bffeb1 to your computer and use it in GitHub Desktop.
A Stereographic Projection example using a Photo Sphere as source
float4 mainPS(VsToPs inp) : SV_Target
{
float2 scale = float2(4.0f / 3.0f, 1) * 3; // scale & aspect ratio
float2 plane = inp.screenPos.xy * scale;
float3 dir = float3(plane.x * 2, plane.y * 2, -1 + dot(plane, plane)) / (1 + dot(plane, plane));
dir = dir.xzy; // y is upper
float longitude = atan2(dir.x, dir.z) * (180 / 3.14159265f);
float latitude = asin(dir.y) * (180 / 3.14159265f);
return gTexture.Sample(samplerState, float2(longitude, latitude) / float2(360, -180) + 0.5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment