AmplifyOcclusion icon indicating copy to clipboard operation
AmplifyOcclusion copied to clipboard

Doesn't properly work with orthographic camera

Open STARasGAMES opened this issue 2 years ago • 0 comments

Title.

The problem is that depth texture produced by orthographic camera is linear, not exponential like in a perspective camera. Therefore, using LinearEyeDepth is not correct for orthographic camera.

To fix this issue you need to change GTAO.cginc At line ~30 change from

inline half4 ConvertDepth( const half2 aUV, const half aSampledDepth )
{
	const half viewDepth = LinearEyeDepth( aSampledDepth );

...

to

float CorrectDepth(float rawDepth)
{
	float persp = LinearEyeDepth(rawDepth);
	float ortho = (_ProjectionParams.z-_ProjectionParams.y)*(1-rawDepth)+_ProjectionParams.y;
	return lerp(persp,ortho,unity_OrthoParams.w);
}

inline half4 ConvertDepth( const half2 aUV, const half aSampledDepth )
{
	const half viewDepth = CorrectDepth( aSampledDepth );

...

Hope this helps someone.

STARasGAMES avatar May 31 '22 17:05 STARasGAMES