Compare commits
No commits in common. "0d410f9c5e86c9c6b4e4220be99d37fe64dcc2e2" and "bbcd4de0b8548665c6ede2886c580c7faef7ffc8" have entirely different histories.
0d410f9c5e
...
bbcd4de0b8
@ -9,23 +9,17 @@ namespace AxibugEmuOnline.Client
|
|||||||
{
|
{
|
||||||
public abstract class FilterEffect
|
public abstract class FilterEffect
|
||||||
{
|
{
|
||||||
public bool Enable { get; set; }
|
public BoolParameter Enable = new BoolParameter(false);
|
||||||
|
|
||||||
[Range(0.1f, 4f)]
|
|
||||||
public FloatParameter RenderScale;
|
|
||||||
|
|
||||||
public abstract string Name { get; }
|
public abstract string Name { get; }
|
||||||
public IReadOnlyCollection<EditableParamerter> EditableParam => m_editableParamList.AsReadOnly();
|
public IReadOnlyCollection<EditableParamerter> EditableParam => m_editableParamList.AsReadOnly();
|
||||||
|
|
||||||
List<EditableParamerter> m_editableParamList;
|
List<EditableParamerter> m_editableParamList;
|
||||||
Material m_material;
|
Material m_material;
|
||||||
protected virtual float m_defaultRenderScale { get => 1f; }
|
|
||||||
protected abstract string ShaderName { get; }
|
protected abstract string ShaderName { get; }
|
||||||
private static int m_iResolutionID = Shader.PropertyToID("_iResolution");
|
|
||||||
|
|
||||||
public FilterEffect()
|
public FilterEffect()
|
||||||
{
|
{
|
||||||
RenderScale = new FloatParameter(m_defaultRenderScale);
|
|
||||||
GetEditableFilterParamters();
|
GetEditableFilterParamters();
|
||||||
m_material = new Material(Shader.Find(ShaderName));
|
m_material = new Material(Shader.Find(ShaderName));
|
||||||
OnInit(m_material);
|
OnInit(m_material);
|
||||||
@ -37,6 +31,7 @@ namespace AxibugEmuOnline.Client
|
|||||||
{
|
{
|
||||||
var parameters = (from t in GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)
|
var parameters = (from t in GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)
|
||||||
where t.FieldType.IsSubclassOf(typeof(FilterParameter))
|
where t.FieldType.IsSubclassOf(typeof(FilterParameter))
|
||||||
|
where t.DeclaringType.IsSubclassOf(typeof(FilterEffect))
|
||||||
orderby t.MetadataToken
|
orderby t.MetadataToken
|
||||||
select t);
|
select t);
|
||||||
|
|
||||||
@ -59,7 +54,7 @@ namespace AxibugEmuOnline.Client
|
|||||||
|
|
||||||
public void Render(Texture src, RenderTexture result)
|
public void Render(Texture src, RenderTexture result)
|
||||||
{
|
{
|
||||||
m_material.SetVector(m_iResolutionID, new Vector4(result.width, result.height));
|
m_material.SetTexture("_MainTex", src);
|
||||||
OnRenderer(m_material, src, result);
|
OnRenderer(m_material, src, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,9 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
using static AxibugEmuOnline.Client.FilterEffect;
|
using static AxibugEmuOnline.Client.FilterEffect;
|
||||||
using static AxibugEmuOnline.Client.FilterManager;
|
|
||||||
|
|
||||||
namespace AxibugEmuOnline.Client
|
namespace AxibugEmuOnline.Client
|
||||||
{
|
{
|
||||||
@ -50,63 +48,41 @@ namespace AxibugEmuOnline.Client
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RenderTexture result = null;
|
private RenderTexture result = null;
|
||||||
public void ExecuteFilterRender(Texture src, RawImage renderGraphic)
|
public Texture ExecuteFilterRender(Texture src)
|
||||||
{
|
{
|
||||||
//获得激活的滤镜
|
|
||||||
Filter activeFilter = null;
|
|
||||||
foreach (var filter in Filters)
|
|
||||||
{
|
|
||||||
if (!filter.m_setting.Enable) continue;
|
|
||||||
activeFilter = filter;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (activeFilter == null)
|
|
||||||
{
|
|
||||||
renderGraphic.texture = src;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var resolution = GetRawImageScreenResolution(renderGraphic);
|
|
||||||
int resWidth = (int)(resolution.x * activeFilter.m_setting.RenderScale.GetValue());
|
|
||||||
int resHeight = (int)(resolution.y * activeFilter.m_setting.RenderScale.GetValue());
|
|
||||||
|
|
||||||
|
#if UNITY_PSP2
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
result = RenderTexture.GetTemporary(Screen.width / 2, Screen.height / 2);
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
result = RenderTexture.GetTemporary(resWidth, resHeight);
|
result = RenderTexture.GetTemporary(Screen.width, Screen.height);
|
||||||
}
|
}
|
||||||
else if (result.width != resWidth || result.height != resHeight)
|
else if (result.width != Screen.width || result.height != Screen.height)
|
||||||
{
|
{
|
||||||
RenderTexture.ReleaseTemporary(result);
|
RenderTexture.ReleaseTemporary(result);
|
||||||
result = RenderTexture.GetTemporary(resWidth, resHeight);
|
result = RenderTexture.GetTemporary(Screen.width, Screen.height);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
bool anyFilterEnable = false;
|
||||||
|
foreach (var filter in Filters)
|
||||||
|
{
|
||||||
|
if (!filter.m_setting.Enable.GetValue()) continue;
|
||||||
|
filter.m_setting.Render(src, result);
|
||||||
|
anyFilterEnable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
activeFilter.m_setting.Render(src, result);
|
if (anyFilterEnable)
|
||||||
|
return result;
|
||||||
renderGraphic.texture = result;
|
else
|
||||||
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 GetRawImageScreenResolution(RawImage rawImage)
|
|
||||||
{
|
|
||||||
// 获取 RawImage 的 RectTransform
|
|
||||||
RectTransform rectTransform = rawImage.rectTransform;
|
|
||||||
|
|
||||||
// 获取 RawImage 在屏幕上的四个顶点的世界坐标
|
|
||||||
Vector3[] corners = new Vector3[4];
|
|
||||||
rectTransform.GetWorldCorners(corners);
|
|
||||||
|
|
||||||
// 左下角和右上角的屏幕坐标
|
|
||||||
Vector2 bottomLeft = RectTransformUtility.WorldToScreenPoint(rawImage.canvas.worldCamera, corners[0]);
|
|
||||||
Vector2 topRight = RectTransformUtility.WorldToScreenPoint(rawImage.canvas.worldCamera, corners[2]);
|
|
||||||
|
|
||||||
// 计算宽度和高度
|
|
||||||
float width = topRight.x - bottomLeft.x;
|
|
||||||
float height = topRight.y - bottomLeft.y;
|
|
||||||
|
|
||||||
return new Vector2(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary> 关闭滤镜预览 </summary>
|
/// <summary> 关闭滤镜预览 </summary>
|
||||||
public void ShutDownFilterPreview()
|
public void ShutDownFilterPreview()
|
||||||
{
|
{
|
||||||
@ -127,8 +103,8 @@ namespace AxibugEmuOnline.Client
|
|||||||
{
|
{
|
||||||
foreach (var selfFiler in Filters)
|
foreach (var selfFiler in Filters)
|
||||||
{
|
{
|
||||||
if (selfFiler != filter) selfFiler.m_setting.Enable = false;
|
if (selfFiler != filter) selfFiler.m_setting.Enable.Override(false);
|
||||||
else selfFiler.m_setting.Enable = true;
|
else selfFiler.m_setting.Enable.Override(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +115,7 @@ namespace AxibugEmuOnline.Client
|
|||||||
{
|
{
|
||||||
//关闭所有后处理效果
|
//关闭所有后处理效果
|
||||||
foreach (var filter in Filters)
|
foreach (var filter in Filters)
|
||||||
filter.m_setting.Enable = false;
|
filter.m_setting.Enable.Override(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -37,6 +37,7 @@ public sealed class FixingPixelArtGrille : FilterEffect
|
|||||||
|
|
||||||
protected override void OnRenderer(Material renderMat, Texture src, RenderTexture result)
|
protected override void OnRenderer(Material renderMat, Texture src, RenderTexture result)
|
||||||
{
|
{
|
||||||
|
renderMat.SetVector("_iResolution", new Vector4(result.width, result.height, 0, 0));
|
||||||
renderMat.SetVector("_res", new Vector4(DrawResolution.GetValue().x, DrawResolution.GetValue().y, 0, 0));
|
renderMat.SetVector("_res", new Vector4(DrawResolution.GetValue().x, DrawResolution.GetValue().y, 0, 0));
|
||||||
renderMat.SetFloat("_hardScan", HardScan.GetValue());
|
renderMat.SetFloat("_hardScan", HardScan.GetValue());
|
||||||
renderMat.SetFloat("_hardPix", HardPix.GetValue());
|
renderMat.SetFloat("_hardPix", HardPix.GetValue());
|
||||||
|
|||||||
@ -9,6 +9,7 @@ public sealed class LCDPostEffect : FilterEffect
|
|||||||
|
|
||||||
protected override void OnRenderer(Material renderMat, Texture src, RenderTexture result)
|
protected override void OnRenderer(Material renderMat, Texture src, RenderTexture result)
|
||||||
{
|
{
|
||||||
|
renderMat.SetVector("_iResolution", new Vector4(result.width, result.height, 0, 0));
|
||||||
Graphics.Blit(src, result, renderMat);
|
Graphics.Blit(src, result, renderMat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,9 +13,11 @@ public sealed class MattiasCRT : FilterEffect
|
|||||||
private LocalKeyword _kw_qualityLow;
|
private LocalKeyword _kw_qualityLow;
|
||||||
private LocalKeyword _kw_qualityMid;
|
private LocalKeyword _kw_qualityMid;
|
||||||
private LocalKeyword _kw_qualityHigh;
|
private LocalKeyword _kw_qualityHigh;
|
||||||
|
private int _pid_iResolution;
|
||||||
|
|
||||||
protected override void OnInit(Material renderMat)
|
protected override void OnInit(Material renderMat)
|
||||||
{
|
{
|
||||||
|
_pid_iResolution = Shader.PropertyToID("_iResolution");
|
||||||
_kw_qualityLow = new LocalKeyword(renderMat.shader, "_QUALITY_LOW");
|
_kw_qualityLow = new LocalKeyword(renderMat.shader, "_QUALITY_LOW");
|
||||||
_kw_qualityMid = new LocalKeyword(renderMat.shader, "_QUALITY_MID");
|
_kw_qualityMid = new LocalKeyword(renderMat.shader, "_QUALITY_MID");
|
||||||
_kw_qualityHigh = new LocalKeyword(renderMat.shader, "_QUALITY_HIGH");
|
_kw_qualityHigh = new LocalKeyword(renderMat.shader, "_QUALITY_HIGH");
|
||||||
@ -23,6 +25,7 @@ public sealed class MattiasCRT : FilterEffect
|
|||||||
|
|
||||||
protected override void OnRenderer(Material renderMat, Texture src, RenderTexture result)
|
protected override void OnRenderer(Material renderMat, Texture src, RenderTexture result)
|
||||||
{
|
{
|
||||||
|
renderMat.SetVector(_pid_iResolution, new Vector4(result.width, result.height, 0, 0));
|
||||||
renderMat.DisableKeyword(_kw_qualityLow);
|
renderMat.DisableKeyword(_kw_qualityLow);
|
||||||
renderMat.DisableKeyword(_kw_qualityMid);
|
renderMat.DisableKeyword(_kw_qualityMid);
|
||||||
renderMat.DisableKeyword(_kw_qualityHigh);
|
renderMat.DisableKeyword(_kw_qualityHigh);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
using Assets.Script.AppMain.Filter;
|
using Assets.Script.AppMain.Filter;
|
||||||
using AxibugEmuOnline.Client;
|
using AxibugEmuOnline.Client;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Rendering;
|
using UnityEngine.Rendering;
|
||||||
@ -47,6 +47,7 @@ public class RetroArchMattiasCRTGlow : FilterEffect
|
|||||||
m_multipPassCmd.Clear();
|
m_multipPassCmd.Clear();
|
||||||
|
|
||||||
m_multipPassCmd.GetTemporaryRT(m_wrapRT, result.width, result.height);
|
m_multipPassCmd.GetTemporaryRT(m_wrapRT, result.width, result.height);
|
||||||
|
renderMat.SetVector("_iResolution", new Vector2(result.width, result.height));
|
||||||
|
|
||||||
renderMat.SetFloat(m_gamma_ID, InputGamma.GetValue());
|
renderMat.SetFloat(m_gamma_ID, InputGamma.GetValue());
|
||||||
renderMat.SetFloat(m_horiz_gauss_width_ID, GaussianWidth.GetValue());
|
renderMat.SetFloat(m_horiz_gauss_width_ID, GaussianWidth.GetValue());
|
||||||
|
|||||||
@ -16,6 +16,6 @@ public class UIFilterPreviewer : MonoBehaviour
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
App.filter.ExecuteFilterRender(m_src, m_rawImg);
|
m_rawImg.texture = App.filter.ExecuteFilterRender(m_src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,7 @@ namespace AxibugEmuOnline.Client
|
|||||||
|
|
||||||
public void ApplyFilterEffect()
|
public void ApplyFilterEffect()
|
||||||
{
|
{
|
||||||
App.filter.ExecuteFilterRender(rt_gpu, Image);
|
Image.texture = App.filter.ExecuteFilterRender(rt_gpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe void PrepareUI(uint* screenData)
|
private unsafe void PrepareUI(uint* screenData)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user