public ShaderParameters(Transform objTransform, Camera camera) { var projectionMatrix = MyUtility.GetProjectMatrix(camera.fieldOfView, camera.aspect, camera.nearClipPlane, camera.farClipPlane); var viewMatrix = MyUtility.GetViewMatrix(camera); var modelMatrix = MyUtility.GetModelMatrix(objTransform); var time = Time.time; var sinTime = Mathf.Sin(time); var cosTime = Mathf.Cos(time); var deltaTime = Time.deltaTime; var smoothDeltaTime = Time.smoothDeltaTime; // Built-in shader variables unity_ObjectToWorld = modelMatrix; // M UNITY_MATRIX_V = viewMatrix; // V UNITY_MATRIX_P = projectionMatrix; // P unity_WorldToObject = objTransform.worldToLocalMatrix; UNITY_MATRIX_MV = UNITY_MATRIX_V * unity_ObjectToWorld; UNITY_MATRIX_MVP = UNITY_MATRIX_P * UNITY_MATRIX_MV; UNITY_MATRIX_VP = UNITY_MATRIX_P * UNITY_MATRIX_V; UNITY_MATRIX_T_MV = UNITY_MATRIX_MV.transpose; UNITY_MATRIX_IT_MV = UNITY_MATRIX_T_MV.inverse; // Camera and screen (TODO) // Time _Time = new Vector4(time / 20.0f, time, time * 2.0f, time * 3.0f); // Time since level load (t/20, t, t*2, t*3), use to animate things inside the shaders. _SinTime = new Vector4(sinTime / 8.0f, sinTime / 4.0f, sinTime / 2.0f, sinTime); // Sine of time: (t/8, t/4, t/2, t). _CosTime = new Vector4(cosTime / 8.0f, cosTime / 4.0f, cosTime / 2.0f, cosTime); // Cosine of time: (t/8, t/4, t/2, t). unity_DeltaTime = new Vector4(deltaTime, 1.0f / deltaTime, smoothDeltaTime, 1.0f / smoothDeltaTime); // Delta time: (dt, 1/dt, smoothDt, 1/smoothDt). }
void OnGUI() { // output GUI.DrawTexture(new Rect(0, 0, tex.width, tex.height), tex); if (!IsDebuging) { return; } // debug MyUtility.LogPoint(new Rect(0, 0, 100, 20), $"Obj Count:{inputObj.Count}", textColor, 20); MyUtility.LogPoint(new Rect(0, 20, 100, 20), $"resolution:{tex.width}x{tex.height}", textColor, 20); var posY = 0; var offset = 120; posY -= offset; var str = $"==== unity_project matrix ====\n{MyCamera.projectionMatrix}"; MyUtility.LogPoint(new Rect(0, MyCamera.pixelHeight + posY, 200, 150), str, textColor, 20); posY -= offset; var myProjectMatrix = MyUtility.GetProjectMatrix(MyCamera.fieldOfView, MyCamera.aspect, MyCamera.nearClipPlane, MyCamera.farClipPlane); str = $"==== my_project matrix ====\n{myProjectMatrix}"; MyUtility.LogPoint(new Rect(0, MyCamera.pixelHeight + posY, 200, 150), str, textColor, 20); posY -= offset; str = $"==== unity_view matrix ====\n{MyCamera.worldToCameraMatrix}"; MyUtility.LogPoint(new Rect(0, MyCamera.pixelHeight + posY, 200, 150), str, textColor, 20); posY -= offset; var myViewMatrix = MyUtility.GetViewMatrix(MyCamera); str = $"==== my_view matrix ====\n{myViewMatrix}"; MyUtility.LogPoint(new Rect(0, MyCamera.pixelHeight + posY, 200, 150), str, textColor, 20); posY -= offset; /* debug model matrix * var obj = inputObj[0]; * str = $"==== unity_local2World matrix ====\n{obj.transform.localToWorldMatrix}"; * MyUtility.LogPoint(new Rect(0, MyCamera.pixelHeight + posY, 200, 150), str, textColor, 20); * posY -= offset; * str = $"==== my_local2World matrix ====\n{MyUtility.GetModelMatrix(obj.transform)}"; * MyUtility.LogPoint(new Rect(0, MyCamera.pixelHeight + posY, 200, 150), str, textColor, 20); */ }