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.
61 lines
2.3 KiB
61 lines
2.3 KiB
using UnityEngine;
|
|
|
|
namespace ArmASR
|
|
{
|
|
/// <summary>
|
|
/// A collection of callbacks required by the ASR process.
|
|
/// This allows some customization by the game dev on how to integrate ASR upscaling into their own game setup.
|
|
/// </summary>
|
|
public interface IAsrCallbacks
|
|
{
|
|
/// <summary>
|
|
/// Apply a mipmap bias to in-game textures to prevent them from becoming blurry as the internal rendering resolution lowers.
|
|
/// This will need to be customized on a per-game basis, as there is no clear universal way to determine what are "in-game" textures.
|
|
/// The default implementation will simply apply a mipmap bias to all 2D textures, which will include things like UI textures and which might miss things like terrain texture arrays.
|
|
///
|
|
/// Depending on how your game organizes its assets, you will want to create a filter that more specifically selects the textures that need to have this mipmap bias applied.
|
|
/// You may also want to store the bias offset value and apply it to any assets that are loaded in on demand.
|
|
/// </summary>
|
|
void ApplyMipmapBias(float biasOffset);
|
|
|
|
void UndoMipmapBias();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Default implementation of IAsrCallbacks.
|
|
/// These are fine for testing but a proper game will want to extend and override these methods.
|
|
/// </summary>
|
|
public class AsrCallbacksBase: IAsrCallbacks
|
|
{
|
|
protected float CurrentBiasOffset = 0;
|
|
|
|
public virtual void ApplyMipmapBias(float biasOffset)
|
|
{
|
|
if (float.IsNaN(biasOffset) || float.IsInfinity(biasOffset))
|
|
return;
|
|
|
|
CurrentBiasOffset += biasOffset;
|
|
|
|
if (Mathf.Approximately(CurrentBiasOffset, 0f))
|
|
{
|
|
CurrentBiasOffset = 0f;
|
|
}
|
|
|
|
foreach (var texture in Resources.FindObjectsOfTypeAll<Texture2D>())
|
|
{
|
|
if (texture.mipmapCount <= 1)
|
|
continue;
|
|
|
|
texture.mipMapBias += biasOffset;
|
|
}
|
|
}
|
|
|
|
public virtual void UndoMipmapBias()
|
|
{
|
|
if (CurrentBiasOffset == 0f)
|
|
return;
|
|
|
|
ApplyMipmapBias(-CurrentBiasOffset);
|
|
}
|
|
}
|
|
}
|