diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterEffect.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterEffect.cs index 9ec1ef07..e159f07b 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterEffect.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/FilterEffect.cs @@ -22,7 +22,11 @@ namespace AxibugEmuOnline.Client { GetEditableFilterParamters(); m_material = new Material(Shader.Find(ShaderName)); + OnInit(m_material); } + + protected virtual void OnInit(Material renderMat) { } + void GetEditableFilterParamters() { var parameters = (from t in GetType().GetFields(BindingFlags.Instance | BindingFlags.Public) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/LCDPostEffect/LCDPostEffect.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/LCDPostEffect/LCDPostEffect.cs index f8ccca39..fe91ac54 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/LCDPostEffect/LCDPostEffect.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/LCDPostEffect/LCDPostEffect.cs @@ -9,7 +9,7 @@ public sealed class LCDPostEffect : FilterEffect protected override void OnRenderer(Material renderMat, Texture src, RenderTexture result) { - renderMat.SetVector("_iResolution", new Vector4(Screen.width, Screen.height, 0, 0)); + renderMat.SetVector("_iResolution", new Vector4(result.width, result.height, 0, 0)); Graphics.Blit(src, result, renderMat); } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/MattiasCRT/MattiasCRT.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/MattiasCRT/MattiasCRT.cs index 6e6c79d8..d6400f3b 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/MattiasCRT/MattiasCRT.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/MattiasCRT/MattiasCRT.cs @@ -1,5 +1,7 @@ -using AxibugEmuOnline.Client; +using Assets.Script.AppMain.Filter; +using AxibugEmuOnline.Client; using UnityEngine; +using UnityEngine.Rendering; public sealed class MattiasCRT : FilterEffect { @@ -7,9 +9,40 @@ public sealed class MattiasCRT : FilterEffect protected override string ShaderName => "Filter/MattiasCRT"; + public FilterParameter Quality = new FilterParameter(EnumQuality.High); + private LocalKeyword _kw_qualityLow; + private LocalKeyword _kw_qualityMid; + private LocalKeyword _kw_qualityHigh; + private int _pid_iResolution; + + protected override void OnInit(Material renderMat) + { + _pid_iResolution = Shader.PropertyToID("_iResolution"); + _kw_qualityLow = new LocalKeyword(renderMat.shader, "_QUALITY_LOW"); + _kw_qualityMid = new LocalKeyword(renderMat.shader, "_QUALITY_MID"); + _kw_qualityHigh = new LocalKeyword(renderMat.shader, "_QUALITY_HIGH"); + } + protected override void OnRenderer(Material renderMat, Texture src, RenderTexture result) { - renderMat.SetVector("_iResolution", new Vector4(result.width, result.height, 0, 0)); + renderMat.SetVector(_pid_iResolution, new Vector4(result.width, result.height, 0, 0)); + renderMat.DisableKeyword(_kw_qualityLow); + renderMat.DisableKeyword(_kw_qualityMid); + renderMat.DisableKeyword(_kw_qualityHigh); + switch (Quality.GetValue()) + { + case EnumQuality.Low: renderMat.EnableKeyword(_kw_qualityLow); break; + case EnumQuality.Mid: renderMat.EnableKeyword(_kw_qualityMid); break; + case EnumQuality.High: renderMat.EnableKeyword(_kw_qualityHigh); break; + } + Graphics.Blit(src, result, renderMat); } + + public enum EnumQuality + { + Low, + Mid, + High + } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/MattiasCRT/MattiasCRT.shader b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/MattiasCRT/MattiasCRT.shader index a493754b..d0ec3c2a 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/MattiasCRT/MattiasCRT.shader +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Filter/MattiasCRT/MattiasCRT.shader @@ -1,4 +1,4 @@ - + Shader "Filter/MattiasCRT" { Properties @@ -11,6 +11,7 @@ Shader "Filter/MattiasCRT" { CGPROGRAM + #pragma shader_feature_local _QUALITY_LOW _QUALITY_MID _QUALITY_HIGH #pragma vertex vert_img #pragma fragment frag #include "UnityCG.cginc" @@ -37,16 +38,26 @@ Shader "Filter/MattiasCRT" float2 q = fragCoord.xy / _iResolution.xy; float2 uv = q; uv = curve( uv ); - float3 oricol = tex2D(_MainTex,uv).xyz; - float3 col; float x = sin(0.3*_Time+uv.y*21.0)*sin(0.7*_Time+uv.y*29.0)*sin(0.3+0.33*_Time+uv.y*31.0)*0.0017; + float3 col; + #if _QUALITY_LOW + col = tex2D(_MainTex,uv); + #elif _QUALITY_MID + col = tex2D(_MainTex,float2(x+uv.x+0.001,uv.y+0.001))+0.05; + float3 tmpColor2 = tex2D(_MainTex,0.75*float2(x+0.025, -0.027)+float2(uv.x+0.001,uv.y+0.001)); + col.r+=tmpColor2.x*0.08; + col.g+=tmpColor2.y*0.05; + col.b+=tmpColor2.z*0.08; + #else col.r = tex2D(_MainTex,float2(x+uv.x+0.001,uv.y+0.001)).x+0.05; col.g = tex2D(_MainTex,float2(x+uv.x+0.000,uv.y-0.002)).y+0.05; col.b = tex2D(_MainTex,float2(x+uv.x-0.002,uv.y+0.000)).z+0.05; col.r += 0.08*tex2D(_MainTex,0.75*float2(x+0.025, -0.027)+float2(uv.x+0.001,uv.y+0.001)).x; - col.g += 0.05*tex2D(_MainTex,0.75*float2(x+-0.022, -0.02)+float2(uv.x+0.000,uv.y-0.002)).y; col.b += 0.08*tex2D(_MainTex,0.75*float2(x+-0.02, -0.018)+float2(uv.x-0.002,uv.y+0.000)).z; + col.g += 0.05*tex2D(_MainTex,0.75*float2(x+-0.022, -0.02)+float2(uv.x+0.000,uv.y-0.002)).y; + #endif + col = clamp(col*0.6+0.4*col*col*1.0,0.0,1.0);