FSR2 tests in Unity based on built-in render pipeline
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

33 lines
1.1 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace FidelityFX
{
[RequireComponent(typeof(Camera), typeof(Fsr2ImageEffect))]
public class Fsr2ImageEffectHelper : MonoBehaviour
{
private Camera _renderCamera;
private Fsr2ImageEffect _imageEffect;
private void OnEnable()
{
_renderCamera = GetComponent<Camera>();
_imageEffect = GetComponent<Fsr2ImageEffect>();
}
private void OnPreCull()
{
if (_imageEffect == null || !_imageEffect.enabled)
return;
var originalRect = _renderCamera.rect;
float upscaleRatio = Fsr2.GetUpscaleRatioFromQualityMode(_imageEffect.qualityMode);
// Render to a smaller portion of the screen by manipulating the camera's viewport rect
_renderCamera.aspect = (_renderCamera.pixelWidth * originalRect.width) / (_renderCamera.pixelHeight * originalRect.height);
_renderCamera.rect = new Rect(0, 0, originalRect.width / upscaleRatio, originalRect.height / upscaleRatio);
}
}
}