Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bdunderscore/d77bab9e8b63dc430cdd47c8ca0f8135 to your computer and use it in GitHub Desktop.
Save bdunderscore/d77bab9e8b63dc430cdd47c8ca0f8135 to your computer and use it in GitHub Desktop.
#define VR_EPSILON 0.0001
#define DESKTOP_FOV 60.0
#define FOV_EPSILON 0.01
#define ROT_EPSILON 0.0001
bool isOrthographic()
{
return UNITY_MATRIX_P[3][3] == 1;
}
bool isInMirror()
{
return unity_CameraProjection[2][0] != 0.f || unity_CameraProjection[2][1] != 0.f;
}
bool isPlayerView() {
// VR view?
#if defined(USING_STEREO_MATRICES)
return 1;
#endif
#if 1
if (isOrthographic()) {
return 0;
}
// Check desktop FOV
float t = unity_CameraProjection._m11;
const float Rad2Deg = 180 / UNITY_PI;
float fov = atan(1.0f / t) * 2.0 * Rad2Deg;
if (abs(fov - DESKTOP_FOV) >= FOV_EPSILON) {
return 0;
}
// Check Y axis rotation
float3 y_vec = float3(0, 1, 0) + _WorldSpaceCameraPos;
float4 center_vec = UnityWorldToClipPos(_WorldSpaceCameraPos);
float4 projected = UnityWorldToClipPos(y_vec);
float4 offset = center_vec - projected;
if (abs(offset.x) >= ROT_EPSILON) {
return 0;
}
#endif
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment