public Matrix4x4 viewMatrix ;
public Matrix4x4 projMatrix ;
public Matrix4x4 nonJitteredProjMatrix ;
public Vector4 cameraPositionWS ;
public Vector4 worldSpa ceC ameraPos;
public float detViewMatrix ;
public Vector4 screenSize ;
public Frustum frustum ;
public Vector2 taaFrameRotation ;
public Vector4 depthBufferParams ;
public Vector4 frustumParams ;
public Vector4 zBufferParams ;
public Vector4 unity_OrthoParams ;
public Vector4 projectionParams ;
public Vector4 screenParams ;
public PostProcessRenderContext postprocessRenderContext ;
public bool isFirstFrame { get ; private set ; }
// Ref: An Efficient Depth Linearization Method for Oblique View Frustums, Eq. 6.
// TODO: pass this as "_Depth BufferParams" if the projection matrix is oblique.
// TODO: pass this as "_Z BufferParams" if the projection matrix is oblique.
public Vector4 invProjParam
{
get
// In stereo, this corresponds to the center eye position
var pos = camera . transform . position ;
cameraPositionWS = pos ;
worldSpa ceC ameraPos = pos ;
if ( ShaderConfig . s_CameraRelativeRendering ! = 0 )
{
float scale = projMatrix [ 2 , 3 ] / ( f * n ) * ( f - n ) ;
bool depth_0_1 = Mathf . Abs ( scale ) < 1.5f ;
bool reverseZ = scale > 0 ;
bool flipProj = projMatrix . inverse . MultiplyPoint ( new Vector3 ( 0 , 1 , 0 ) ) . y < 0 ;
depthBufferParams = new Vector4 ( - 1 + f / n , 1 , - 1 / f + 1 / n , 1 / f ) ;
zBufferParams = new Vector4 ( - 1 + f / n , 1 , - 1 / f + 1 / n , 1 / f ) ;
depthBufferParams = new Vector4 ( 1 - f / n , f / n , 1 / f - 1 / n , 1 / n ) ;
zBufferParams = new Vector4 ( 1 - f / n , f / n , 1 / f - 1 / n , 1 / n ) ;
projectionParams = new Vector4 ( flipProj ? - 1 : 1 , n , f , 1.0f / f ) ;
frustumParams = new Vector4 ( n , f , orthoWidth , orthoHeight ) ;
unity_OrthoParams = new Vector4 ( orthoWidth , orthoHeight , 0 , camera . orthographic ? 1 : 0 ) ;
frustum = Frustum . Create ( viewProjMatrix , depth_0_1 , reverseZ ) ;
m_CameraScaleBias . x = ( float ) m_ActualWidth / maxWidth ;
m_CameraScaleBias . y = ( float ) m_ActualHeight / maxHeight ;
screenSize = new Vector4 ( screenWidth , screenHeight , 1.0f / screenWidth , 1.0f / screenHeight ) ;
screenSize = new Vector4 ( screenWidth , screenHeight , 1.0f / screenWidth , 1.0f / screenHeight ) ;
screenParams = new Vector4 ( screenSize . x , screenSize . y , 1 + screenSize . z , 1 + screenSize . w ) ;
}
// Stopgap method used to extract stereo combined matrix state.
}
// Set up UnityPerView CBuffer.
public void SetupGlobalParams ( CommandBuffer cmd , float curren tT ime, float previous Time)
public void SetupGlobalParams ( CommandBuffer cmd , float time , float last Time)
{
cmd . SetGlobalMatrix ( HDShaderIDs . _ViewMatrix , viewMatrix ) ;
cmd . SetGlobalMatrix ( HDShaderIDs . _InvViewMatrix , viewMatrix . inverse ) ;
cmd . SetGlobalMatrix ( HDShaderIDs . _InvViewProjMatrix , viewProjMatrix . inverse ) ;
cmd . SetGlobalMatrix ( HDShaderIDs . _NonJitteredViewProjMatrix , nonJitteredViewProjMatrix ) ;
cmd . SetGlobalMatrix ( HDShaderIDs . _PrevViewProjMatrix , prevViewProjMatrix ) ;
cmd . SetGlobalVector ( HDShaderIDs . _CameraPositionWS , cameraPositionWS ) ;
cmd . SetGlobalVector ( HDShaderIDs . _WorldSpaceCameraPos , worldSpaceCameraPos ) ;
cmd . SetGlobalVector ( HDShaderIDs . _DepthBufferParams , depthBufferParams ) ;
cmd . SetGlobalVector ( HDShaderIDs . _FrustumParams , frustumParams ) ;
cmd . SetGlobalVector ( HDShaderIDs . _ZBufferParams , zBufferParams ) ;
cmd . SetGlobalVector ( HDShaderIDs . _ProjectionParams , projectionParams ) ;
cmd . SetGlobalVector ( HDShaderIDs . unity_OrthoParams , unity_OrthoParams ) ;
cmd . SetGlobalVector ( HDShaderIDs . _ScreenParams , screenParams ) ;
cmd . SetGlobalVector ( HDShaderIDs . _TaaFrameRotation , taaFrameRotation ) ;
cmd . SetGlobalVectorArray ( HDShaderIDs . _FrustumPlanes , frustumPlaneEquations ) ;
float ct = animateMaterials ? curren tT ime : 0 ;
float pt = animateMaterials ? previous Time : 0 ;
float ct = animateMaterials ? time : 0 ;
float pt = animateMaterials ? last Time : 0 ;
cmd . SetGlobalVector ( HDShaderIDs . _Current Time , new Vector4 ( ct * 0.05f , ct , ct * 2.0f , ct * 3.0f ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _PreviousTime , new Vector4 ( pt * 0.05f , pt , pt * 2.0f , pt * 3.0f ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _DeltaTime , new Vector4 ( dt , 1.0f / dt , sdt , 1.0f / sdt ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _SinCurrent Time , new Vector4 ( Mathf . Sin ( ct * 0.125f ) , Mathf . Sin ( ct * 0.25f ) , Mathf . Sin ( ct * 0.5f ) , Mathf . Sin ( ct ) ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _CosCurrent Time , new Vector4 ( Mathf . Cos ( ct * 0.125f ) , Mathf . Cos ( ct * 0.25f ) , Mathf . Cos ( ct * 0.5f ) , Mathf . Cos ( ct ) ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _Time , new Vector4 ( ct * 0.05f , ct , ct * 2.0f , ct * 3.0f ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _LastTime , new Vector4 ( pt * 0.05f , pt , pt * 2.0f , pt * 3.0f ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . unity _DeltaTime, new Vector4 ( dt , 1.0f / dt , sdt , 1.0f / sdt ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _SinTime , new Vector4 ( Mathf . Sin ( ct * 0.125f ) , Mathf . Sin ( ct * 0.25f ) , Mathf . Sin ( ct * 0.5f ) , Mathf . Sin ( ct ) ) ) ;
cmd . SetGlobalVector ( HDShaderIDs . _CosTime , new Vector4 ( Mathf . Cos ( ct * 0.125f ) , Mathf . Cos ( ct * 0.25f ) , Mathf . Cos ( ct * 0.5f ) , Mathf . Cos ( ct ) ) ) ;
}
public void SetupGlobalStereoParams ( CommandBuffer cmd )