ytgui / temp

0 stars 0 forks source link

graphic phrases 5 builtins #89

Closed ytgui closed 4 years ago

ytgui commented 5 years ago
//
// https://www.jianshu.com/p/df878a386bec
// clip space position to texture coordinate
// bottom_left = (0, 0), top_right = (1, 1)
// for current triangle it could be (0.4, 0.5) - (0.6, 0.5) - (0.5, 0.67)
//
// after above function, coordinate between [0, w]
// so we need to use it with textureProj()
//
inline float4 ComputeScreenPos (float4 pos)
{
  float4 o = pos * 0.5f;
  o.xy = float2(o.x, o.y*_ProjectionParams.x) + o.w;
  o.zw = pos.zw;
  return o;
}
// MVP transform
// https://learnopengl.com/Getting-started/Coordinate-Systems
// Clip coordinates are processed from range [-w, w] to [-1.0, 1.0] and
// determine which vertices will end up on the screen.
o.vertex = UnityObjectToClipPos(v.vertex);
float4 UnityObjectToClipPos(float3 pos) Transforms a point from object space to the camera’s clip space in homogeneous coordinates. This is the equivalent of mul(UNITY_MATRIX_MVP, float4(pos, 1.0)), and should be used in its place.
float3 UnityObjectToViewPos(float3 pos) Transforms a point from object space to view space. This is the equivalent of mul(UNITY_MATRIX_MV, float4(pos, 1.0)).xyz, and should be used in its place.
ytgui commented 5 years ago

https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html

Name Value
UNITY_MATRIX_MVP Current model view projection matrix.
UNITY_MATRIX_MV Current model * view matrix.
UNITY_MATRIX_V Current view matrix.
UNITY_MATRIX_P Current projection matrix.
UNITY_MATRIX_VP Current view * projection matrix.
UNITY_MATRIX_T_MV Transpose of model * view matrix.
UNITY_MATRIX_IT_MV Inverse transpose of model * view matrix.
unity_ObjectToWorld Current model matrix.
unity_WorldToObject Inverse of current world matrix.

https://forum.unity.com/threads/what-does-the-function-computescreenpos-in-unitycg-cginc-do.294470/