滤镜参数可调

This commit is contained in:
ALIENJACK\alien 2024-11-26 20:30:02 +08:00
parent e0a87a2737
commit adde033fa1
6 changed files with 206 additions and 114 deletions

View File

@ -150,25 +150,16 @@ MonoBehaviour:
m_GameObject: {fileID: 74796456}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3}
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MoveRepeatDelay: 0.5
m_MoveRepeatRate: 0.1
m_XRTrackingOrigin: {fileID: 0}
m_ActionsAsset: {fileID: -944628639613478452, guid: eb413fd14a8483440af9652b7e4df5e1, type: 3}
m_PointAction: {fileID: 0}
m_MoveAction: {fileID: 0}
m_SubmitAction: {fileID: 0}
m_CancelAction: {fileID: 0}
m_LeftClickAction: {fileID: 0}
m_MiddleClickAction: {fileID: 0}
m_RightClickAction: {fileID: 0}
m_ScrollWheelAction: {fileID: 0}
m_TrackedDevicePositionAction: {fileID: 0}
m_TrackedDeviceOrientationAction: {fileID: 0}
m_DeselectOnBackgroundClick: 1
m_PointerBehavior: 0
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &74796458
MonoBehaviour:
m_ObjectHideFlags: 0
@ -2508,7 +2499,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 1639091784002085428, guid: 450328d5a907c8249a60bc3980ba66f6, type: 3}
propertyPath: m_RootOrder
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1639091784002085428, guid: 450328d5a907c8249a60bc3980ba66f6, type: 3}
propertyPath: m_AnchorMax.x
@ -13451,8 +13442,8 @@ GameObject:
m_Component:
- component: {fileID: 1475480929}
- component: {fileID: 1475480931}
- component: {fileID: 1475480930}
- component: {fileID: 1475480932}
- component: {fileID: 1475480930}
m_Layer: 5
m_Name: GameCamera
m_TagString: MainCamera
@ -13847,7 +13838,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3}
propertyPath: m_RootOrder
value: 3
value: 2
objectReference: {fileID: 0}
- target: {fileID: 1963501579241001456, guid: 334eee9f85f308347844f8f5e99167c3, type: 3}
propertyPath: m_AnchorMax.x
@ -13956,7 +13947,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 3531919739338806919, guid: 1de15a80c8c1aa94486563740a15d91c, type: 3}
propertyPath: m_RootOrder
value: 4
value: 3
objectReference: {fileID: 0}
- target: {fileID: 3531919739338806919, guid: 1de15a80c8c1aa94486563740a15d91c, type: 3}
propertyPath: m_AnchorMax.x
@ -14109,7 +14100,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4478785627166277610, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_RootOrder
value: 2
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4478785627166277610, guid: d3c2508a55398a24db5d68f68d2702ea, type: 3}
propertyPath: m_AnchorMax.x

View File

@ -1,3 +1,5 @@
using AxibugEmuOnline.Client;
using AxibugEmuOnline.Client.ClientCore;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
@ -5,7 +7,51 @@ using UnityEngine.Rendering.PostProcessing;
[PostProcess(typeof(FixingPixelArtGrilleRenderer), PostProcessEvent.BeforeStack, "Filter/FixingPixelArtGrille")]
public sealed class FixingPixelArtGrille : PostProcessEffectSettings
{
// 在这里可以添加效果的参数
public ParameterOverride<EnumMaskStyle> MaskStyle = new ParameterOverride<EnumMaskStyle> { value = EnumMaskStyle.ApertureGrille };
[Tooltip("Emulated input resolution\nOptimize for resize")]
public Vector2Parameter DrawResolution = new Vector2Parameter
{
value = new Vector2(272, 240)
};
[Tooltip("Hardness of scanline")]
[Range(-32, 0)]
public FloatParameter HardScan = new FloatParameter { value = -10 };
[Tooltip("Hardness of pixels in scanline")]
[Range(-6, 0)]
public FloatParameter HardPix = new FloatParameter { value = -2 };
[Tooltip("Hardness of short vertical bloom")]
[Range(-8, 0)]
public FloatParameter HardBloomScan = new FloatParameter { value = -4.0f };
[Tooltip("Hardness of short horizontal bloom")]
[Range(-4, 0)]
public FloatParameter HardBloomPix = new FloatParameter { value = -1.5f };
[Tooltip("Amount of small bloom effect")]
[Range(0, 1)]
public FloatParameter BloomAmount = new FloatParameter { value = 1 / 16f };
[Tooltip("Display warp")]
public Vector2Parameter Warp = new Vector2Parameter { value = new Vector2(1f / 64f, 1f / 24f) };
[Tooltip("Amount of shadow mask Light")]
[Range(1, 3)]
public FloatParameter MaskLight = new FloatParameter { value = 1.5f };
[Range(0.1f, 1)]
[Tooltip("Amount of shadow mask Dark")]
public FloatParameter MaskDrak = new FloatParameter { value = 0.5f };
public enum EnumMaskStyle
{
TVStyle,
ApertureGrille,
StretchedVGA,
VGAStyle
}
}
public sealed class FixingPixelArtGrilleRenderer : PostProcessEffectRenderer<FixingPixelArtGrille>
@ -21,6 +67,39 @@ public sealed class FixingPixelArtGrilleRenderer : PostProcessEffectRenderer<Fix
public override void Render(PostProcessRenderContext context)
{
material.SetVector("_iResolution", new Vector4(Screen.width, Screen.height, 0, 0));
var res = settings.DrawResolution;
material.SetVector("_res", new Vector4(res.value.x, res.value.y, 0, 0));
material.SetFloat("_hardScan", settings.HardScan.value);
material.SetFloat("_hardPix", settings.HardPix.value);
material.SetFloat("_hardBloomScan", settings.HardBloomScan.value);
material.SetFloat("_hardBloomPix", settings.HardBloomPix.value);
material.SetFloat("_bloomAmount", settings.BloomAmount.value);
material.SetVector("_warp", settings.Warp.value);
material.SetFloat("_maskDark", settings.MaskDrak.value);
material.SetFloat("_maskLight", settings.MaskLight.value);
material.DisableKeyword("_MASKSTYLE_VGASTYLE");
material.DisableKeyword("_MASKSTYLE_TVSTYLE");
material.DisableKeyword("_MASKSTYLE_APERTUREGRILLE");
material.DisableKeyword("_MASKSTYLE_STRETCHEDVGA");
switch (settings.MaskStyle.value)
{
case FixingPixelArtGrille.EnumMaskStyle.VGAStyle:
material.EnableKeyword("_MASKSTYLE_VGASTYLE");
break;
case FixingPixelArtGrille.EnumMaskStyle.TVStyle:
material.EnableKeyword("_MASKSTYLE_TVSTYLE");
break;
case FixingPixelArtGrille.EnumMaskStyle.ApertureGrille:
material.EnableKeyword("_MASKSTYLE_APERTUREGRILLE");
break;
case FixingPixelArtGrille.EnumMaskStyle.StretchedVGA:
material.EnableKeyword("_MASKSTYLE_STRETCHEDVGA");
break;
}
context.command.Blit(context.source, context.destination, material);
}
}

View File

@ -11,6 +11,7 @@ Shader "PostEffect/FixingPixcelArtGrille"
{
CGPROGRAM
#pragma shader_feature_local _MASKSTYLE_TVSTYLE _MASKSTYLE_APERTUREGRILLE _MASKSTYLE_STRETCHEDVGA _MASKSTYLE_VGASTYLE
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
@ -33,48 +34,48 @@ Shader "PostEffect/FixingPixcelArtGrille"
// Please take and use, change, or whatever.
//
#define iResolution float2(1920,1080)
float2 _iResolution = float2(1920,1080);
// Emulated input resolution.
// Optimize for resize.
#define res (float2(272.0,240.0)*1.5)
float2 _res = float2(272.0,240.0);
// Hardness of scanline.
// -8.0 = soft
// -16.0 = medium
#define hardScan -10.0
float _hardScan = -10.0;
// Hardness of pixels in scanline.
// -2.0 = soft
// -4.0 = hard
#define hardPix -2.0
float _hardPix =-2.0;
// Hardness of short vertical bloom.
// -1.0 = wide to the point of clipping (bad)
// -1.5 = wide
// -4.0 = not very wide at all
#define hardBloomScan -4.0
float _hardBloomScan = -4.0;
// Hardness of short horizontal bloom.
// -0.5 = wide to the point of clipping (bad)
// -1.0 = wide
// -2.0 = not very wide at all
#define hardBloomPix -1.5
float _hardBloomPix = -1.5;
// Amount of small bloom effect.
// 1.0/1.0 = only bloom
// 1.0/16.0 = what I think is a good amount of small bloom
// 0.0 = no bloom
#define bloomAmount 1.0/1.0
float _bloomAmount = 1.0/16.0;
// Display warp.
// 0.0 = none
// 1.0/8.0 = extreme
#define warp float2(1.0/64.0,1.0/24.0)
float2 _warp = float2(1.0/64.0,1.0/24.0);
// Amount of shadow mask.
#define maskDark 0.5
#define maskLight 1.5
float _maskDark = 0.5;
float _maskLight = 1.5;
//------------------------------------------------------------------------
@ -92,23 +93,18 @@ float3 ToLinear(float3 c){return float3(ToLinear1(c.r),ToLinear1(c.g),ToLinear1(
float ToSrgb1(float c){return(c<0.0031308?c*12.92:1.055*pow(c,0.41666)-0.055);}
float3 ToSrgb(float3 c){return float3(ToSrgb1(c.r),ToSrgb1(c.g),ToSrgb1(c.b));}
// Testing only, something to help generate a dark signal for bloom test.
// Set to zero, or remove Test() if using this shader.
#if 1
float3 Test(float3 c){return c*(1.0/64.0)+c*c*c;}
#else
float3 Test(float3 c){return c;}
#endif
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
float3 Fetch( float2 pos,float2 off){
pos=floor(pos*res+off)/res;
pos=floor(pos*_res+off)/_res;
if(max(abs(pos.x-0.5),abs(pos.y-0.5))>0.5)return float3(0.0,0.0,0.0);
return Test(ToLinear(tex2D(_MainTex,pos.xy).rgb));}
// Distance in emulated pixels to nearest texel.
float2 Dist(float2 pos){pos=pos*res;return -((pos-floor(pos))-float2(0.5,0.5));}
float2 Dist(float2 pos){pos=pos*_res;return -((pos-floor(pos))-float2(0.5,0.5));}
// 1D Gaussian.
float Gaus(float pos,float scale){return exp2(scale*pos*pos);}
@ -120,7 +116,7 @@ float3 Horz3(float2 pos,float off){
float3 d=Fetch(pos,float2( 1.0,off));
float dst=Dist(pos).x;
// Convert distance to weight.
float scale=hardPix;
float scale=_hardPix;
float wb=Gaus(dst-1.0,scale);
float wc=Gaus(dst+0.0,scale);
float wd=Gaus(dst+1.0,scale);
@ -136,7 +132,7 @@ float3 Horz5(float2 pos,float off){
float3 e=Fetch(pos,float2( 2.0,off));
float dst=Dist(pos).x;
// Convert distance to weight.
float scale=hardPix;
float scale=_hardPix;
float wa=Gaus(dst-2.0,scale);
float wb=Gaus(dst-1.0,scale);
float wc=Gaus(dst+0.0,scale);
@ -156,7 +152,7 @@ float3 Horz7(float2 pos,float off){
float3 g=Fetch(pos,float2( 3.0,off));
float dst=Dist(pos).x;
// Convert distance to weight.
float scale=hardBloomPix;
float scale=_hardBloomPix;
float wa=Gaus(dst-3.0,scale);
float wb=Gaus(dst-2.0,scale);
float wc=Gaus(dst-1.0,scale);
@ -170,12 +166,12 @@ float3 Horz7(float2 pos,float off){
// Return scanline weight.
float Scan(float2 pos,float off){
float dst=Dist(pos).y;
return Gaus(dst+off,hardScan);}
return Gaus(dst+off,_hardScan);}
// Return scanline weight for bloom.
float BloomScan(float2 pos,float off){
float dst=Dist(pos).y;
return Gaus(dst+off,hardBloomScan);}
return Gaus(dst+off,_hardBloomScan);}
// Allow nearest three lines to effect pixel.
float3 Tri(float2 pos){
@ -205,62 +201,58 @@ float3 Bloom(float2 pos){
float2 Warp(float2 pos){
pos=pos*2.0-1.0;
pos*=float2(1.0+(pos.y*pos.y)*warp.x,1.0+(pos.x*pos.x)*warp.y);
pos*=float2(1.0+(pos.y*pos.y)*_warp.x,1.0+(pos.x*pos.x)*_warp.y);
return pos*0.5+0.5;}
#if 0
// Very compressed TV style shadow mask.
float3 Mask(float2 pos){
float line=maskLight;
#if defined(_MASKSTYLE_TVSTYLE)
// Very compressed TV style shadow mask.
float3 Mask(float2 pos){
float lineee=_maskLight;
float odd=0.0;
if(fract(pos.x/6.0)<0.5)odd=1.0;
if(fract((pos.y+odd)/2.0)<0.5)line=maskDark;
if(fract((pos.y+odd)/2.0)<0.5) lineee=_maskDark;
pos.x=fract(pos.x/3.0);
float3 mask=float3(maskDark,maskDark,maskDark);
if(pos.x<0.333)mask.r=maskLight;
else if(pos.x<0.666)mask.g=maskLight;
else mask.b=maskLight;
mask*=line;
return mask;}
#endif
#if 1
// Aperture-grille.
float3 Mask(float2 pos){
float3 mask=float3(_maskDark,_maskDark,_maskDark);
if(pos.x<0.333)mask.r=_maskLight;
else if(pos.x<0.666)mask.g=_maskLight;
else mask.b=_maskLight;
mask*=lineee;
return mask;
}
#elif defined(_MASKSTYLE_APERTUREGRILLE)
// Aperture-grille.
float3 Mask(float2 pos){
pos.x=fract(pos.x/3.0);
float3 mask=float3(maskDark,maskDark,maskDark);
if(pos.x<0.333)mask.r=maskLight;
else if(pos.x<0.666)mask.g=maskLight;
else mask.b=maskLight;
float3 mask=float3(_maskDark,_maskDark,_maskDark);
if(pos.x<0.333)mask.r=_maskLight;
else if(pos.x<0.666)mask.g=_maskLight;
else mask.b=_maskLight;
return mask;}
#endif
#if 0
// Stretched VGA style shadow mask (same as prior shaders).
float3 Mask(float2 pos){
#elif defined(_MASKSTYLE_STRETCHEDVGA)
// Stretched VGA style shadow mask (same as prior shaders).
float3 Mask(float2 pos){
pos.x+=pos.y*3.0;
float3 mask=float3(maskDark,maskDark,maskDark);
float3 mask=float3(_maskDark,_maskDark,_maskDark);
pos.x=fract(pos.x/6.0);
if(pos.x<0.333)mask.r=maskLight;
else if(pos.x<0.666)mask.g=maskLight;
else mask.b=maskLight;
if(pos.x<0.333)mask.r=_maskLight;
else if(pos.x<0.666)mask.g=_maskLight;
else mask.b=_maskLight;
return mask;}
#endif
#if 0
#elif defined(_MASKSTYLE_VGASTYLE)
// VGA style shadow mask.
float3 Mask(float2 pos){
pos.xy=floor(pos.xy*float2(1.0,0.5));
pos.x+=pos.y*3.0;
float3 mask=float3(maskDark,maskDark,maskDark);
float3 mask=float3(_maskDark,_maskDark,_maskDark);
pos.x=fract(pos.x/6.0);
if(pos.x<0.333)mask.r=maskLight;
else if(pos.x<0.666)mask.g=maskLight;
else mask.b=maskLight;
if(pos.x<0.333)mask.r=_maskLight;
else if(pos.x<0.666)mask.g=_maskLight;
else mask.b=_maskLight;
return mask;}
#endif
// Draw dividing bars.
float Bar(float pos,float bar){pos-=bar;return pos*pos<4.0?0.0:1.0;}
@ -268,11 +260,11 @@ float Bar(float pos,float bar){pos-=bar;return pos*pos<4.0?0.0:1.0;}
float4 mainImage(float2 fragCoord){
float4 fragColor = float4(1,1,1,1);
float2 pos=Warp(fragCoord.xy/iResolution.xy);
float2 pos=Warp(fragCoord.xy/_iResolution.xy);
fragColor.rgb=Tri(pos)*Mask(fragCoord.xy);
fragColor.rgb+=Bloom(pos)*bloomAmount;
fragColor.rgb+=Bloom(pos)*_bloomAmount;
fragColor.a=1.0;
fragColor.rgb=ToSrgb(fragColor.rgb);
@ -288,7 +280,7 @@ float2 pos=Warp(fragCoord.xy/iResolution.xy);
fixed4 frag (v2f i) : SV_Target
{
float2 pos = iResolution.xy*i.uv;
float2 pos = _iResolution.xy*i.uv;
fixed4 col = mainImage(pos);
return col;
}

View File

@ -1,6 +1,20 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-3536514882628332180
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8e6292b2c06870d4495f009f912b9600, type: 3}
m_Name: GameCamera Profile
m_EditorClassIdentifier:
settings:
- {fileID: 8004032914748422304}
--- !u!114 &8004032914748422304
MonoBehaviour:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
@ -16,17 +30,33 @@ MonoBehaviour:
enabled:
overrideState: 1
value: 1
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8e6292b2c06870d4495f009f912b9600, type: 3}
m_Name: GameCamera Profile
m_EditorClassIdentifier:
settings:
- {fileID: -3536514882628332180}
MaskStyle:
overrideState: 0
value: 3
DrawResolution:
overrideState: 0
value: {x: 272, y: 240}
HardScan:
overrideState: 0
value: -10
HardPix:
overrideState: 0
value: -2
HardBloomScan:
overrideState: 0
value: -4.06
HardBloomPix:
overrideState: 0
value: -1.15
BloomAmount:
overrideState: 0
value: 0.483
Warp:
overrideState: 0
value: {x: 0.12, y: 0.04}
MaskLight:
overrideState: 0
value: 3
MaskDrak:
overrideState: 0
value: 0.1

View File

@ -98,7 +98,6 @@ namespace AxibugEmuOnline.Client
public static IKeyListener GetKey(int controllerInput, EnumButtonType nesConBtnType)
{
string configKey = $"NES_{controllerInput}_{nesConBtnType}";
if (PlayerPrefs.HasKey(configKey))
{
return new KeyListener(PlayerPrefs.GetString(configKey));

View File

@ -199,6 +199,7 @@ namespace AxibugEmuOnline.Client
UnityEditor.EditorUtility.SetDirty(db);
UnityEditor.AssetDatabase.SaveAssets();
}
#endif
}
}