OnPreCullはカメラがシーンをカリングする前に呼び出されます
カリングはオブジェクトがカメラから見えるかどうかを決めます。OnPreCullはこの処理の前に 呼び出されます。 この関数は、この関数が記述されたスクリプトにCameraがアタッチされていて有効である場合のみ呼び出されます。 カメラの表示パラメータを変更したい場合に(例えば、 fieldOfView や Transform)、 変更を行うために最適なのはこのOnPreCullになります。シーンオブジェクトの表示は /OnPreCull/ 後のカメラのパラメータを基にして決定されます。
// Attach this to a camera.
// Inverts the vie of the camera so everything rendered by it, is flipped
// This will only work on Unity - PRO
function OnPreCull () {
camera.ResetWorldToCameraMatrix ();
camera.ResetProjectionMatrix ();
camera.projectionMatrix = camera.projectionMatrix * Matrix4x4.Scale(Vector3 (1, -1, 1));
}
// Set it to true so we can watch the flipped Objects
function OnPreRender () {
GL.SetRevertBackfacing (true);
}
// Set it to false again because we don't want to affect all other cameras.
function OnPostRender () {
GL.SetRevertBackfacing (false);
}
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void OnPreCull() { camera.ResetWorldToCameraMatrix(); camera.ResetProjectionMatrix(); camera.projectionMatrix = camera.projectionMatrix * Matrix4x4.Scale(new Vector3(1, -1, 1)); } void OnPreRender() { GL.SetRevertBackfacing(true); } void OnPostRender() { GL.SetRevertBackfacing(false); } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): def OnPreCull() as void: camera.ResetWorldToCameraMatrix() camera.ResetProjectionMatrix() camera.projectionMatrix = (camera.projectionMatrix * Matrix4x4.Scale(Vector3(1, -1, 1))) def OnPreRender() as void: GL.SetRevertBackfacing(true) def OnPostRender() as void: GL.SetRevertBackfacing(false)