Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active October 12, 2023 03:31
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save unitycoder/c5847a82343a8e721035 to your computer and use it in GitHub Desktop.
Save unitycoder/c5847a82343a8e721035 to your computer and use it in GitHub Desktop.
UNITY_MATRIX_IT_MV[] Vectors in Shader
UNITY_MATRIX_IT_MV[0].xyz = ???
UNITY_MATRIX_IT_MV[1].xyz = Camera Up
UNITY_MATRIX_IT_MV[2].xyz = Camera Forward
float3 forward = -normalize(UNITY_MATRIX_V._m20_m21_m22);
float3 up = normalize(UNITY_MATRIX_V._m10_m11_m12);
float3 right = normalize(UNITY_MATRIX_V._m00_m01_m02);
float3 cameraUp = unity_CameraInvProjection[1].xyz;
float3 camRight = cross(unity_CameraInvProjection[2].xyz, cameraUp);
float3 cameraForward = cross(cameraUp, camRight);
Camera right direction = UNITY_MATRIX_V[0].xyz = mul((float3x3)UNITY_MATRIX_V,float3(1,0,0));
Camera up direction = UNITY_MATRIX_V[1].xyz = mul((float3x3)UNITY_MATRIX_V,float3(0,1,0));
Camera forward direction = UNITY_MATRIX_V[2].xyz = mul((float3x3)UNITY_MATRIX_V,float3(0,0,1));
Camera position = _WorldSpaceCameraPos = mul(UNITY_MATRIX_V,float4(0,0,0,1)).xyz;
//http://forum.unity3d.com/threads/get-main-camera-up-direction.189947/#post-1297952
// camera right
float3 right = cross(cameraUp, cameraForward);
// ??
float4 objWorldPos=float4(_Object2World._m03,_Object2World._m13,_Object2World._m23, 1);
// references
// http://makegamessa.com/discussion/3368/facing-billboards-shader-in-unity
// http://www.codinglabs.net/article_world_view_projection_matrix.aspx
// http://answers.unity3d.com/questions/557922/rotate-a-mesh-on-world-y-axis-using-a-cg-vertex-sh.html
// scaling http://forum.unity3d.com/threads/scaling-in-the-vertex-shader.197815/
// billboarding http://forum.unity3d.com/threads/leaf-card-billboards-camera-facing-matrix.186667/#post-1278929
// http://forum.unity3d.com/threads/stream-out-for-geometry-shader.179377/
// https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html
// https://forum.unity.com/threads/standard-surface-shader-billboard.513060/#post-3359378
@patricknelson
Copy link

Great reference, thanks for putting this here 👍

@STARasGAMES
Copy link

Thanks!

@sunrise1028
Copy link

thx guy ,help me a lot

@tanat44
Copy link

tanat44 commented Oct 13, 2021

Awesome!

@ipud2
Copy link

ipud2 commented Dec 7, 2022

Nothing to preview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment