Files
UnrealEngineUWP/Engine/Shaders/Private/CommonViewUniformBuffer.ush
Jon Cain 598e504146 Initial orthogonal rendering fix for Point and Spot lights with light framework setup for future ortho rendering fixes
- Common.ush change of runtime check for IsOrthoProjection() function calls to minimise cost to 1ALU
- Add 2 new functions, ScreenVectorFromScreenRect and GetScreenPositionForProjectionMatrix which return corrected values depending on projection type
- Converted CommonViewUniformBuffer to read from the new ViewUniformBuffer TanAndInvTanHalfFOV vector. This means that the static projection matrix values used by these functions are assigned in SceneView.cpp. Ortho rendering does not use these values, so these functions only need to return 1.0f for each value for ortho, and moving this to a constant vector means we avoid unnecessary IsOrthoProjection checks in the shader code.
- Added a few helper functions for the above to SceneView.h/.cpp, including a correction for the ScreenToClip matrix which is now reused in multiple locations, including for shadow rendering, rather than being hard coded.
- Utilised these changes to correct the problems with Point and Spot lights+shadows in ortho perspective, and also corrects some minor artifacts that occur with directional light in ortho.

#jira UE-40089
#rb Jason.Hoerner, Jason.Nadro
#preflight 6408c712b0544ef0b4afc961
#fyi Guillaume.Abadie

[CL 24634679 by Jon Cain in ue5-main branch]
2023-03-14 09:59:54 -04:00

42 lines
1.2 KiB
Plaintext

// Copyright Epic Games, Inc. All Rights Reserved.
/*=============================================================================
CommonViewUniformBuffer.usf: Common view uniform buffer specifics
=============================================================================*/
#pragma once
/*
* @return tan(View.FieldOfViewWideAngles * .5)
*/
float2 GetTanHalfFieldOfView()
{
return View.TanAndInvTanHalfFOV.xy;
}
float2 GetPrevTanHalfFieldOfView()
{
return View.PrevTanAndInvTanHalfFOV.xy;
}
// might be used by Custom material expressions (still best to wrap the custom node in a material function)
// @return 1 / tan(View.FieldOfViewWideAngles * .5)
float2 GetCotanHalfFieldOfView()
{
return View.TanAndInvTanHalfFOV.zw;
}
// might be used by Custom material expressions (still best to wrap the custom node in a material function)
// @return previous 1 / tan(View.FieldOfViewWideAngles * .5)
float2 GetPrevCotanHalfFieldOfView()
{
return View.PrevTanAndInvTanHalfFOV.zw;
}
// Return the index of the frame.
uint GetPowerOfTwoModulatedFrameIndex(uint Pow2Modulus)
{
// Bit masking of an uniform parameter is a scalar operation on modern hardware.
return View.StateFrameIndex & uint(Pow2Modulus - 1);
}