screenSize = new Vector4 ( screenWidth , screenHeight , 1.0f / screenWidth , 1.0f / screenHeight ) ;
}
public void UpdateStereoDependentState ( FrameSettings frameSettings , Camera camera , ref ScriptableCullingParameters cullingParams )
{
if ( ! frameSettings . enableStereo )
return ;
// What constants in UnityPerPass need updating for stereo considerations?
// _ViewProjMatrix - It is used directly for generating tesselation factors. This should be the same
// across both eyes for consistency, and to keep shadow-generation eye-independent
// _ViewParam - Used for isFrontFace determination, should be the same for both eyes. There is the scenario
// where there might be multi-eye sets that are divergent enough where this assumption is not valid,
// but that's a future problem
// _InvProjParam - Intention was for generating linear depths, but not currently used. Will need to be stereo-ized if
// actually needed.
// _FrustumPlanes - Also used for generating tesselation factors. Should be fine to use the combined stereo VP
// to calculate frustum planes.
// TODO: I really should be calculating my own combined view/proj in the Update code
var stereoCombinedViewMatrix = cullingParams . cullStereoView ;
var pos = camera . transform . position ;
var relPos = pos ; // World-origin-relative
if ( ShaderConfig . s_CameraRelativeRendering ! = 0 )
{
// Zero out the translation component.
stereoCombinedViewMatrix . SetColumn ( 3 , new Vector4 ( 0 , 0 , 0 , 1 ) ) ;
relPos = Vector3 . zero ; // Camera-relative
}
viewMatrix = stereoCombinedViewMatrix ;
var stereoCombinedProjMatrix = cullingParams . cullStereoProj ;
projMatrix = GL . GetGPUProjectionMatrix ( stereoCombinedProjMatrix , true ) ;
viewParam = new Vector4 ( viewMatrix . determinant , 0.0f , 0.0f , 0.0f ) ;
// Warning: near and far planes appear to be broken (or rather far plane seems broken)
GeometryUtility . CalculateFrustumPlanes ( viewProjMatrix , frustumPlanes ) ;
for ( int i = 0 ; i < 4 ; i + + )
{
// Left, right, top, bottom.
frustumPlaneEquations [ i ] = new Vector4 ( frustumPlanes [ i ] . normal . x , frustumPlanes [ i ] . normal . y , frustumPlanes [ i ] . normal . z , frustumPlanes [ i ] . distance ) ;
}
// Near, far.
Vector4 forward = new Vector4 ( camera . transform . forward . x , camera . transform . forward . y , camera . transform . forward . z , 0.0f ) ;
// We need to switch forward direction based on handness (Reminder: Regular camera have a negative determinant in Unity and reflection probe follow DX convention and have a positive determinant)
forward = viewParam . x < 0.0f ? forward : - forward ;
frustumPlaneEquations [ 4 ] = new Vector4 ( forward . x , forward . y , forward . z , - Vector3 . Dot ( forward , relPos ) - camera . nearClipPlane ) ;
frustumPlaneEquations [ 5 ] = new Vector4 ( - forward . x , - forward . y , - forward . z , Vector3 . Dot ( forward , relPos ) + camera . farClipPlane ) ;
}
void ConfigureStereoMatrices ( )
{
for ( uint eyeIndex = 0 ; eyeIndex < 2 ; eyeIndex + + )