FVector4f FSceneView::GetScreenPositionScaleBias(const FIntPoint& BufferSize, const FIntRect& ViewRect) const
{
const float InvBufferSizeX = 1.0f / BufferSize.X;
const float InvBufferSizeY = 1.0f / BufferSize.Y;
// to bring NDC (-1..1, 1..-1) into 0..1 UV for BufferSize textures
return FVector4f(
ViewRect.Width() * InvBufferSizeX / +2.0f,
ViewRect.Height() * InvBufferSizeY / (-2.0f * GProjectionSignY),
// Warning: note legacy flipped Y and X
(ViewRect.Height() / 2.0f + ViewRect.Min.Y) * InvBufferSizeY,
(ViewRect.Width() / 2.0f + ViewRect.Min.X) * InvBufferSizeX
);
}
void FSceneView::SetupViewRectUniformBufferParameters(FViewUniformShaderParameters& ViewUniformShaderParameters,
const FIntPoint& BufferSize,
const FIntRect& EffectiveViewRect,
const FViewMatrices& InViewMatrices,
const FViewMatrices& InPrevViewMatrices) const
{
checkfSlow(EffectiveViewRect.Area() > 0, TEXT("Invalid-size EffectiveViewRect passed to CreateUniformBufferParameters [%d * %d]."), EffectiveViewRect.Width(), EffectiveViewRect.Height());
ensureMsgf((BufferSize.X > 0 && BufferSize.Y > 0), TEXT("Invalid-size BufferSize passed to CreateUniformBufferParameters [%d * %d]."), BufferSize.X, BufferSize.Y);
ViewUniformShaderParameters.ViewRectMin = FVector4f(EffectiveViewRect.Min.X, EffectiveViewRect.Min.Y, 0.0f, 0.0f);
ViewUniformShaderParameters.ViewSizeAndInvSize = FVector4f(EffectiveViewRect.Width(), EffectiveViewRect.Height(), 1.0f / float(EffectiveViewRect.Width()), 1.0f / float(EffectiveViewRect.Height()));
ViewUniformShaderParameters.ViewRectMinAndSize = FUintVector4(EffectiveViewRect.Min.X, EffectiveViewRect.Min.Y, EffectiveViewRect.Width(), EffectiveViewRect.Height());
// The light probe ratio is only different during separate forward translucency when r.SeparateTranslucencyScreenPercentage != 100
ViewUniformShaderParameters.LightProbeSizeRatioAndInvSizeRatio = FVector4f(1.0f, 1.0f, 1.0f, 1.0f);
// Calculate the vector used by shaders to convert clip space coordinates to texture space.
const float InvBufferSizeX = 1.0f / BufferSize.X;
const float InvBufferSizeY = 1.0f / BufferSize.Y;
ViewUniformShaderParameters.ScreenPositionScaleBias = GetScreenPositionScaleBias(BufferSize, EffectiveViewRect);
ViewUniformShaderParameters.BufferSizeAndInvSize = FVector4f(BufferSize.X, BufferSize.Y, InvBufferSizeX, InvBufferSizeY);
ViewUniformShaderParameters.BufferBilinearUVMinMax = FVector4f(
InvBufferSizeX * (EffectiveViewRect.Min.X + 0.5),
InvBufferSizeY * (EffectiveViewRect.Min.Y + 0.5),
InvBufferSizeX * (EffectiveViewRect.Max.X - 0.5),
InvBufferSizeY * (EffectiveViewRect.Max.Y - 0.5));
/* Texture Level-of-Detail Strategies for Real-Time Ray Tracing https://developer.nvidia.com/raytracinggems Equation 20 */
float RadFOV = (UE_PI / 180.0f) * FOV;
ViewUniformShaderParameters.EyeToPixelSpreadAngle = FPlatformMath::Atan((2.0f * FPlatformMath::Tan(RadFOV * 0.5f)) / BufferSize.Y);
ViewUniformShaderParameters.MotionBlurNormalizedToPixel = FinalPostProcessSettings.MotionBlurMax * EffectiveViewRect.Width() / 100.0f;
{
// setup a matrix to transform float4(SvPosition.xyz,1) directly to TranslatedWorld (quality, performance as we don't need to convert or use interpolator)
// new_xy = (xy - ViewRectMin.xy) * ViewSizeAndInvSize.zw * float2(2,-2) + float2(-1, 1);
// transformed into one MAD: new_xy = xy * ViewSizeAndInvSize.zw * float2(2,-2) + (-ViewRectMin.xy) * ViewSizeAndInvSize.zw * float2(2,-2) + float2(-1, 1);
float Mx = 2.0f * ViewUniformShaderParameters.ViewSizeAndInvSize.Z;
float My = -2.0f * ViewUniformShaderParameters.ViewSizeAndInvSize.W;
float Ax = -1.0f - 2.0f * EffectiveViewRect.Min.X * ViewUniformShaderParameters.ViewSizeAndInvSize.Z;
float Ay = 1.0f + 2.0f * EffectiveViewRect.Min.Y * ViewUniformShaderParameters.ViewSizeAndInvSize.W;
// http://stackoverflow.com/questions/9010546/java-transformation-matrix-operations
ViewUniformShaderParameters.SVPositionToTranslatedWorld = FMatrix44f(
FMatrix(FPlane(Mx, 0, 0, 0),
FPlane(0, My, 0, 0),
FPlane(0, 0, 1, 0),
FPlane(Ax, Ay, 0, 1)) * InViewMatrices.GetInvTranslatedViewProjectionMatrix());
}
// Compute coefficients which takes a screen UV and converts to Viewspace.xy / ViewZ
float InvTanHalfFov = InViewMatrices.GetProjectionMatrix().M[0][0];
float Ratio = UnscaledViewRect.Width() / (float)UnscaledViewRect.Height();
float InvFovFixX = 1.0f / (InvTanHalfFov);
float InvFovFixY = 1.0f / (Ratio * InvTanHalfFov);
ViewUniformShaderParameters.ScreenToViewSpace.X = BufferSize.X * ViewUniformShaderParameters.ViewSizeAndInvSize.Z * 2 * InvFovFixX;
ViewUniformShaderParameters.ScreenToViewSpace.Y = BufferSize.Y * ViewUniformShaderParameters.ViewSizeAndInvSize.W * -2 * InvFovFixY;
ViewUniformShaderParameters.ScreenToViewSpace.Z = -((ViewUniformShaderParameters.ViewRectMin.X * ViewUniformShaderParameters.ViewSizeAndInvSize.Z * 2 * InvFovFixX) + InvFovFixX);
ViewUniformShaderParameters.ScreenToViewSpace.W = (ViewUniformShaderParameters.ViewRectMin.Y * ViewUniformShaderParameters.ViewSizeAndInvSize.W * 2 * InvFovFixY) + InvFovFixY;
ViewUniformShaderParameters.ViewResolutionFraction = EffectiveViewRect.Width() / (float)UnscaledViewRect.Width();
// TODO: This should really call FPackedView::CalcTranslatedWorldToSubpixelClip, but since FSceneView is in the Engine module we can't pull in the Renderer.
const FVector2f SubpixelScale = FVector2f( 0.5f * EffectiveViewRect.Width() * NANITE_SUBPIXEL_SAMPLES,
-0.5f * EffectiveViewRect.Height() * NANITE_SUBPIXEL_SAMPLES);
const FVector2f SubpixelOffset = FVector2f( (0.5f * EffectiveViewRect.Width() + EffectiveViewRect.Min.X) * NANITE_SUBPIXEL_SAMPLES,
(0.5f * EffectiveViewRect.Height() + EffectiveViewRect.Min.Y) * NANITE_SUBPIXEL_SAMPLES);
ViewUniformShaderParameters.TranslatedWorldToSubpixelClip = FMatrix44f(InViewMatrices.GetTranslatedViewProjectionMatrix()) * FScaleMatrix44f(FVector3f(SubpixelScale, 1.0f)) * FTranslationMatrix44f(FVector3f(SubpixelOffset, 0.0f));
}
void FSceneView::SetupCommonViewUniformBufferParameters(
FViewUniformShaderParameters& ViewUniformShaderParameters,
const FIntPoint& BufferSize,
int32 NumMSAASamples,
const FIntRect& EffectiveViewRect,
const FViewMatrices& InViewMatrices,
const FViewMatrices& InPrevViewMatrices) const
{
QUICK_SCOPE_CYCLE_COUNTER(STAT_SetupCommonViewUniformBufferParameters);
FVector4f LocalDiffuseOverrideParameter = DiffuseOverrideParameter;
FVector2D LocalRoughnessOverrideParameter = RoughnessOverrideParameter;
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
{
// assuming we have no color in the multipliers
float MinValue = LocalDiffuseOverrideParameter.X;
float MaxValue = MinValue + LocalDiffuseOverrideParameter.W;
float NewMinValue = FMath::Max(MinValue, CVarDiffuseColorMin.GetValueOnRenderThread());
float NewMaxValue = FMath::Min(MaxValue, CVarDiffuseColorMax.GetValueOnRenderThread());
LocalDiffuseOverrideParameter.X = LocalDiffuseOverrideParameter.Y = LocalDiffuseOverrideParameter.Z = NewMinValue;
LocalDiffuseOverrideParameter.W = NewMaxValue - NewMinValue;
}
{
float MinValue = LocalRoughnessOverrideParameter.X;
float MaxValue = MinValue + LocalRoughnessOverrideParameter.Y;
float NewMinValue = FMath::Max(MinValue, CVarRoughnessMin.GetValueOnRenderThread());
float NewMaxValue = FMath::Min(MaxValue, CVarRoughnessMax.GetValueOnRenderThread());
LocalRoughnessOverrideParameter.X = NewMinValue;
LocalRoughnessOverrideParameter.Y = NewMaxValue - NewMinValue;
}
#endif
const FRelativeViewMatrices RelativeMatrices = FRelativeViewMatrices::Create(InViewMatrices, InPrevViewMatrices);
const FLargeWorldRenderPosition AbsoluteViewOrigin(InViewMatrices.GetViewOrigin());
const FVector ViewTileOffset = AbsoluteViewOrigin.GetTileOffset();
ViewUniformShaderParameters.NumSceneColorMSAASamples = NumMSAASamples;
ViewUniformShaderParameters.ViewToTranslatedWorld = FMatrix44f(InViewMatrices.GetOverriddenInvTranslatedViewMatrix()); // LWC_TODO: Precision - Validate all float variant casts here.
ViewUniformShaderParameters.TranslatedWorldToClip = FMatrix44f(InViewMatrices.GetTranslatedViewProjectionMatrix());
ViewUniformShaderParameters.RelativeWorldToClip = RelativeMatrices.RelativeWorldToClip;
ViewUniformShaderParameters.ClipToRelativeWorld = RelativeMatrices.ClipToRelativeWorld;;
ViewUniformShaderParameters.TranslatedWorldToView = FMatrix44f(InViewMatrices.GetOverriddenTranslatedViewMatrix());
ViewUniformShaderParameters.TranslatedWorldToCameraView = FMatrix44f(InViewMatrices.GetTranslatedViewMatrix());
ViewUniformShaderParameters.CameraViewToTranslatedWorld = FMatrix44f(InViewMatrices.GetInvTranslatedViewMatrix());
ViewUniformShaderParameters.ViewToClip = RelativeMatrices.ViewToClip;
ViewUniformShaderParameters.ViewToClipNoAA = FMatrix44f(InViewMatrices.GetProjectionNoAAMatrix());
ViewUniformShaderParameters.ClipToView = RelativeMatrices.ClipToView;
ViewUniformShaderParameters.ClipToTranslatedWorld = FMatrix44f(InViewMatrices.GetInvTranslatedViewProjectionMatrix());
ViewUniformShaderParameters.ViewForward = (FVector3f)InViewMatrices.GetOverriddenTranslatedViewMatrix().GetColumn(2);
ViewUniformShaderParameters.ViewUp = (FVector3f)InViewMatrices.GetOverriddenTranslatedViewMatrix().GetColumn(1);
ViewUniformShaderParameters.ViewRight = (FVector3f)InViewMatrices.GetOverriddenTranslatedViewMatrix().GetColumn(0);
ViewUniformShaderParameters.HMDViewNoRollUp = (FVector3f)InViewMatrices.GetHMDViewMatrixNoRoll().GetColumn(1);
ViewUniformShaderParameters.HMDViewNoRollRight = (FVector3f)InViewMatrices.GetHMDViewMatrixNoRoll().GetColumn(0);
ViewUniformShaderParameters.InvDeviceZToWorldZTransform = InvDeviceZToWorldZTransform;
ViewUniformShaderParameters.RelativeWorldViewOrigin = (FVector4f)(InViewMatrices.GetOverriddenInvTranslatedViewMatrix().TransformPosition(FVector(0)) - InViewMatrices.GetPreViewTranslation() - ViewTileOffset);
ViewUniformShaderParameters.ViewTilePosition = AbsoluteViewOrigin.GetTile();
ViewUniformShaderParameters.MatrixTilePosition = RelativeMatrices.TilePosition;
ViewUniformShaderParameters.RelativeWorldCameraOrigin = FVector3f(InViewMatrices.GetViewOrigin() - ViewTileOffset);
ViewUniformShaderParameters.TranslatedWorldCameraOrigin = FVector3f(InViewMatrices.GetViewOrigin() + InViewMatrices.GetPreViewTranslation());
ViewUniformShaderParameters.RelativePreViewTranslation = FVector3f(InViewMatrices.GetPreViewTranslation() + ViewTileOffset);
ViewUniformShaderParameters.PrevViewToClip = FMatrix44f(InPrevViewMatrices.GetProjectionMatrix());
ViewUniformShaderParameters.PrevClipToView = RelativeMatrices.PrevClipToView;
ViewUniformShaderParameters.PrevTranslatedWorldToClip = FMatrix44f(InPrevViewMatrices.GetTranslatedViewProjectionMatrix());
// EffectiveTranslatedViewMatrix != InViewMatrices.TranslatedViewMatrix in the shadow pass
// and we don't have EffectiveTranslatedViewMatrix for the previous frame to set up PrevTranslatedWorldToView
// but that is fine to set up PrevTranslatedWorldToView as same as PrevTranslatedWorldToCameraView
// since the shadow pass doesn't require previous frame computation.
ViewUniformShaderParameters.PrevTranslatedWorldToView = FMatrix44f(InPrevViewMatrices.GetOverriddenTranslatedViewMatrix());
ViewUniformShaderParameters.PrevViewToTranslatedWorld = FMatrix44f(InPrevViewMatrices.GetOverriddenInvTranslatedViewMatrix());
ViewUniformShaderParameters.PrevTranslatedWorldToCameraView = FMatrix44f(InPrevViewMatrices.GetTranslatedViewMatrix());
ViewUniformShaderParameters.PrevCameraViewToTranslatedWorld = FMatrix44f(InPrevViewMatrices.GetInvTranslatedViewMatrix());
ViewUniformShaderParameters.PrevRelativeWorldCameraOrigin = FVector3f(InPrevViewMatrices.GetViewOrigin() - ViewTileOffset);
// previous view world origin is going to be needed only in the base pass or shadow pass
// therefore is same as previous camera world origin.
ViewUniformShaderParameters.PrevRelativeWorldViewOrigin = ViewUniformShaderParameters.PrevRelativeWorldCameraOrigin;
ViewUniformShaderParameters.PrevTranslatedWorldCameraOrigin = FVector3f(InPrevViewMatrices.GetViewOrigin() + InPrevViewMatrices.GetPreViewTranslation());
ViewUniformShaderParameters.RelativePrevPreViewTranslation = FVector3f(InPrevViewMatrices.GetPreViewTranslation() + ViewTileOffset);
ViewUniformShaderParameters.PrevClipToRelativeWorld = RelativeMatrices.PrevClipToRelativeWorld;
// Convert global clipping plane to translated world space
const FPlane4f TranslatedGlobalClippingPlane(GlobalClippingPlane.TranslateBy(InViewMatrices.GetPreViewTranslation()));
ViewUniformShaderParameters.GlobalClippingPlane = FVector4f(TranslatedGlobalClippingPlane.X, TranslatedGlobalClippingPlane.Y, TranslatedGlobalClippingPlane.Z, -TranslatedGlobalClippingPlane.W);
ViewUniformShaderParameters.FieldOfViewWideAngles = FVector2f(2.f * InViewMatrices.ComputeHalfFieldOfViewPerAxis()); // LWC_TODO: Precision loss
ViewUniformShaderParameters.PrevFieldOfViewWideAngles = FVector2f(2.f * InPrevViewMatrices.ComputeHalfFieldOfViewPerAxis()); // LWC_TODO: Precision loss
ViewUniformShaderParameters.DiffuseOverrideParameter = LocalDiffuseOverrideParameter;
ViewUniformShaderParameters.SpecularOverrideParameter = SpecularOverrideParameter;
ViewUniformShaderParameters.NormalOverrideParameter = NormalOverrideParameter;
ViewUniformShaderParameters.RoughnessOverrideParameter = FVector2f(LocalRoughnessOverrideParameter); // LWC_TODO: Precision loss
ViewUniformShaderParameters.WorldCameraMovementSinceLastFrame = FVector3f(InViewMatrices.GetViewOrigin() - InPrevViewMatrices.GetViewOrigin());
ViewUniformShaderParameters.CullingSign = bReverseCulling ? -1.0f : 1.0f;
ViewUniformShaderParameters.NearPlane = InViewMatrices.ComputeNearPlane();
ViewUniformShaderParameters.MaterialTextureMipBias = 0.0f;
ViewUniformShaderParameters.MaterialTextureDerivativeMultiply = 1.0f;
ViewUniformShaderParameters.ResolutionFractionAndInv = FVector2f(1.0f, 1.0f);
ViewUniformShaderParameters.bCheckerboardSubsurfaceProfileRendering = 0;
const FMatrix44f ScreenToClip(FPlane4f(1, 0, 0, 0),
FPlane4f(0, 1, 0, 0),
FPlane4f(0, 0, ProjectionMatrixUnadjustedForRHI.M[2][2], 1),
FPlane4f(0, 0, ProjectionMatrixUnadjustedForRHI.M[3][2], 0));
ViewUniformShaderParameters.ScreenToRelativeWorld = ScreenToClip * ViewUniformShaderParameters.ClipToRelativeWorld;
ViewUniformShaderParameters.ScreenToTranslatedWorld = FMatrix44f(FMatrix(
FPlane(1, 0, 0, 0),
FPlane(0, 1, 0, 0),
FPlane(0, 0, ProjectionMatrixUnadjustedForRHI.M[2][2], 1),
FPlane(0, 0, ProjectionMatrixUnadjustedForRHI.M[3][2], 0))
* InViewMatrices.GetInvTranslatedViewProjectionMatrix());
ViewUniformShaderParameters.MobileMultiviewShadowTransform = FMatrix44f(FMatrix(
FPlane(1, 0, 0, 0),
FPlane(0, 1, 0, 0),
FPlane(0, 0, InViewMatrices.GetProjectionMatrix().M[2][2], 1),
FPlane(0, 0, InViewMatrices.GetProjectionMatrix().M[3][2], 0)) *
InViewMatrices.GetInvTranslatedViewProjectionMatrix() *
FTranslationMatrix(-InViewMatrices.GetPreViewTranslation()));
ViewUniformShaderParameters.PrevScreenToTranslatedWorld = FMatrix44f(FMatrix(
FPlane(1, 0, 0, 0),
FPlane(0, 1, 0, 0),
FPlane(0, 0, ProjectionMatrixUnadjustedForRHI.M[2][2], 1),
FPlane(0, 0, ProjectionMatrixUnadjustedForRHI.M[3][2], 0))
* InPrevViewMatrices.GetInvTranslatedViewProjectionMatrix());
{
FVector DeltaTranslation = InPrevViewMatrices.GetPreViewTranslation() - InViewMatrices.GetPreViewTranslation();
FMatrix InvViewProj = InViewMatrices.ComputeInvProjectionNoAAMatrix() * InViewMatrices.GetTranslatedViewMatrix().GetTransposed();
FMatrix PrevViewProj = FTranslationMatrix(DeltaTranslation) * InPrevViewMatrices.GetTranslatedViewMatrix() * InPrevViewMatrices.ComputeProjectionNoAAMatrix();
ViewUniformShaderParameters.ClipToPrevClip = FMatrix44f(InvViewProj * PrevViewProj); // LWC_TODO: Precision loss?
}
{
FVector DeltaTranslation = InPrevViewMatrices.GetPreViewTranslation() - InViewMatrices.GetPreViewTranslation();
FMatrix InvViewProj = InViewMatrices.GetInvProjectionMatrix() * InViewMatrices.GetTranslatedViewMatrix().GetTransposed();
FMatrix PrevViewProj = FTranslationMatrix(DeltaTranslation) * InPrevViewMatrices.GetTranslatedViewMatrix() * InPrevViewMatrices.GetProjectionMatrix();
ViewUniformShaderParameters.ClipToPrevClipWithAA = FMatrix44f(InvViewProj * PrevViewProj); // LWC_TODO: Precision loss?
}
// LWC_TODO: precision loss? These values are probably quite small and easily within float range.
ViewUniformShaderParameters.TemporalAAJitter = FVector4f(
(float)InViewMatrices.GetTemporalAAJitter().X, (float)InViewMatrices.GetTemporalAAJitter().Y,
(float)InPrevViewMatrices.GetTemporalAAJitter().X, (float)InPrevViewMatrices.GetTemporalAAJitter().Y );
ViewUniformShaderParameters.DebugViewModeMask = Family->UseDebugViewPS() ? 1 : 0;
ViewUniformShaderParameters.UnlitViewmodeMask = !Family->EngineShowFlags.Lighting || Family->EngineShowFlags.PathTracing ? 1 : 0;
ViewUniformShaderParameters.OutOfBoundsMask = Family->EngineShowFlags.VisualizeOutOfBoundsPixels ? 1 : 0;
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
float OverrideTimeMaterialExpression = CVarOverrideTimeMaterialExpressions.GetValueOnRenderThread();
if (OverrideTimeMaterialExpression >= 0.0f)
{
ViewUniformShaderParameters.PrevFrameGameTime = OverrideTimeMaterialExpression;
ViewUniformShaderParameters.PrevFrameRealTime = OverrideTimeMaterialExpression;
ViewUniformShaderParameters.GameTime = OverrideTimeMaterialExpression;
ViewUniformShaderParameters.RealTime = OverrideTimeMaterialExpression;
ViewUniformShaderParameters.DeltaTime = 0.0f;
}
else
#endif
{
ViewUniformShaderParameters.PrevFrameGameTime = Family->Time.GetWorldTimeSeconds() - Family->Time.GetDeltaWorldTimeSeconds();
ViewUniformShaderParameters.PrevFrameRealTime = Family->Time.GetRealTimeSeconds() - Family->Time.GetDeltaRealTimeSeconds();
ViewUniformShaderParameters.GameTime = Family->Time.GetWorldTimeSeconds();
ViewUniformShaderParameters.RealTime = Family->Time.GetRealTimeSeconds();
ViewUniformShaderParameters.DeltaTime = Family->Time.GetDeltaWorldTimeSeconds();
}
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
static FIntPoint LockedCursorPos = CursorPos;
if (CVarFreezeMouseCursor.GetValueOnRenderThread() == 0 && CursorPos.X >= 0 && CursorPos.Y >= 0)
{
LockedCursorPos = CursorPos;
}
ViewUniformShaderParameters.CursorPosition = LockedCursorPos;
#endif
ViewUniformShaderParameters.Random = FMath::Rand();
ViewUniformShaderParameters.FrameNumber = Family->FrameNumber;
ViewUniformShaderParameters.CameraCut = bCameraCut ? 1 : 0;
ViewUniformShaderParameters.MinRoughness = FMath::Clamp(CVarGlobalMinRoughnessOverride.GetValueOnRenderThread(), 0.02f, 1.0f);
//to tail call keep the order and number of parameters of the caller function
SetupViewRectUniformBufferParameters(ViewUniformShaderParameters, BufferSize, EffectiveViewRect, InViewMatrices, InPrevViewMatrices);
}
/** Creates the view's uniform buffers given a set of view transforms. */
void FViewInfo::SetupUniformBufferParameters(
const FViewMatrices& InViewMatrices,
const FViewMatrices& InPrevViewMatrices,
FBox* OutTranslucentCascadeBoundsArray,
int32 NumTranslucentCascades,
FViewUniformShaderParameters& ViewUniformShaderParameters) const
{
check(Family);
const FSceneTexturesConfig& SceneTexturesConfig = GetSceneTexturesConfig();
// Create the view's uniform buffer.
// Mobile multi-view is not side by side
const FIntRect EffectiveViewRect = (bIsMobileMultiViewEnabled) ? FIntRect(0, 0, ViewRect.Width(), ViewRect.Height()) : ViewRect;
// Scene render targets may not be created yet; avoids NaNs.
FIntPoint EffectiveBufferSize = SceneTexturesConfig.Extent;
EffectiveBufferSize.X = FMath::Max(EffectiveBufferSize.X, 1);
EffectiveBufferSize.Y = FMath::Max(EffectiveBufferSize.Y, 1);
// TODO: We should use a view and previous view uniform buffer to avoid code duplication and keep consistency
SetupCommonViewUniformBufferParameters(
ViewUniformShaderParameters,
EffectiveBufferSize,
SceneTexturesConfig.NumSamples,
EffectiveViewRect,
InViewMatrices,
InPrevViewMatrices
);
}
ViewRect:默认是窗口大小分辨率,该值会随着ScreenPercent变化,相乘就是结果。比如1920x1080,SP设置50%,那就是960x540
EffectiveBufferSize: 最小值是窗口大小分辨率,SP低于100%,数值不变,SP大于100%,相乘。如SP200%,1920x1080就是4940x2160.
void FRendererModule::CreateAndInitSingleView(FRHICommandListImmediate& RHICmdList, class FSceneViewFamily* ViewFamily, const struct FSceneViewInitOptions* ViewInitOptions)
{
// Create and add the new view
FViewInfo* NewView = new FViewInfo(*ViewInitOptions);
ViewFamily->Views.Add(NewView);
FViewInfo* View = (FViewInfo*)ViewFamily->Views[0];
View->ViewRect = View->UnscaledViewRect;
View->InitRHIResources();
}
// Use this to reinitialize the object each frame for the hovered viewport.
void ResetFromSceneView(const FSceneView& SceneView)
{
UnscaledViewRect = SceneView.UnscaledViewRect;
ViewMatrices.ResetFromSceneView(SceneView);
bIsPerspectiveProjection = SceneView.IsPerspectiveProjection();
ViewLocation = SceneView.ViewLocation;
}
FSceneView::FSceneView(const FSceneViewInitOptions& InitOptions)
: Family(InitOptions.ViewFamily)
, State(InitOptions.SceneViewStateInterface)
, DynamicMeshElementsShadowCullFrustum(nullptr)
, PreShadowTranslation(FVector::ZeroVector)
, ViewActor(InitOptions.ViewActor)
, PlayerIndex(InitOptions.PlayerIndex)
, Drawer(InitOptions.ViewElementDrawer)
, UnscaledViewRect(InitOptions.GetConstrainedViewRect())
, UnconstrainedViewRect(InitOptions.GetViewRect())
, MaxShadowCascades(10)
/**
* Initialization constructor. Passes all parameters to FSceneView constructor
*/
FViewInfo::FViewInfo(const FSceneViewInitOptions& InitOptions)
: FSceneView(InitOptions)
, IndividualOcclusionQueries((FSceneViewState*)InitOptions.SceneViewStateInterface, 1)
, GroupedOcclusionQueries((FSceneViewState*)InitOptions.SceneViewStateInterface, FOcclusionQueryBatcher::OccludedPrimitiveQueryBatchSize)
, CustomVisibilityQuery(nullptr)
{
Init();
}