Skip to content

Commit 32b0dbd

Browse files
committed
修订Glitch Image Block系列算法
修订Glitch Image Block系列算法
1 parent 40f683c commit 32b0dbd

File tree

9 files changed

+77
-56
lines changed

9 files changed

+77
-56
lines changed

Assets/Example/ExampleScene.unity

-4
Original file line numberDiff line numberDiff line change
@@ -2756,8 +2756,6 @@ MonoBehaviour:
27562756
Culture=neutral, PublicKeyToken=null
27572757
- assemblyQualifiedName: XPostProcessing.GlitchDigitalStripe, Assembly-CSharp, Version=0.0.0.0,
27582758
Culture=neutral, PublicKeyToken=null
2759-
- assemblyQualifiedName: XPostProcessing.GlitchDigitalStripeV2, Assembly-CSharp,
2760-
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
27612759
- assemblyQualifiedName: XPostProcessing.GlitchImageBlock, Assembly-CSharp, Version=0.0.0.0,
27622760
Culture=neutral, PublicKeyToken=null
27632761
- assemblyQualifiedName: XPostProcessing.GlitchImageBlockV2, Assembly-CSharp, Version=0.0.0.0,
@@ -2780,8 +2778,6 @@ MonoBehaviour:
27802778
Culture=neutral, PublicKeyToken=null
27812779
- assemblyQualifiedName: XPostProcessing.GlitchScanLineJitter, Assembly-CSharp,
27822780
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
2783-
- assemblyQualifiedName: XPostProcessing.GlitchScanLineJitterV2, Assembly-CSharp,
2784-
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
27852781
- assemblyQualifiedName: XPostProcessing.GlitchScreenJump, Assembly-CSharp, Version=0.0.0.0,
27862782
Culture=neutral, PublicKeyToken=null
27872783
- assemblyQualifiedName: XPostProcessing.GlitchScreenShake, Assembly-CSharp, Version=0.0.0.0,

Assets/X-PostProcessing/Effects/GlitchImageBlock/Shader/GlitchImageBlock.shader

+9-6
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ Shader "Hidden/X-PostProcessing/Glitch/ImageBlock"
4848
{
4949
float2 uv = i.texcoord.xy;
5050

51+
//求解第一层blockLayer
5152
float2 blockLayer1 = floor(uv * float2(_BlockLayer1_U, _BlockLayer1_V));
5253
float2 blockLayer2 = floor(uv * float2(_BlockLayer2_U, _BlockLayer2_V));
54+
55+
//return float4(blockLayer1, blockLayer2);
5356

54-
float lineNoise_1 = pow(randomNoise(blockLayer1), _BlockLayer1_Indensity);
55-
float lineNoise_2 = pow(randomNoise(blockLayer2), _BlockLayer2_Indensity);
57+
float lineNoise1 = pow(randomNoise(blockLayer1), _BlockLayer1_Indensity);
58+
float lineNoise2 = pow(randomNoise(blockLayer2), _BlockLayer2_Indensity);
5659
float RGBSplitNoise = pow(randomNoise(5.1379), 7.1) * _RGBSplit_Indensity;
57-
float lineNoise = lineNoise_1 * lineNoise_2 * _Offset - RGBSplitNoise;
60+
float lineNoise = lineNoise1 * lineNoise2 * _Offset - RGBSplitNoise;
5861

5962
float4 colorR = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv);
6063
float4 colorG = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + float2(lineNoise * 0.05 * randomNoise(7.0), 0));
@@ -74,10 +77,10 @@ Shader "Hidden/X-PostProcessing/Glitch/ImageBlock"
7477
float2 blockLayer1 = floor(uv * float2(_BlockLayer1_U, _BlockLayer1_V));
7578
float2 blockLayer2 = floor(uv * float2(_BlockLayer2_U, _BlockLayer2_V));
7679

77-
float lineNoise_1 = pow(randomNoise(blockLayer1), _BlockLayer1_Indensity);
78-
float lineNoise_2 = pow(randomNoise(blockLayer2), _BlockLayer2_Indensity);
80+
float lineNoise1 = pow(randomNoise(blockLayer1), _BlockLayer1_Indensity);
81+
float lineNoise2 = pow(randomNoise(blockLayer2), _BlockLayer2_Indensity);
7982
float RGBSplitNoise = pow(randomNoise(5.1379), 7.1) * _RGBSplit_Indensity;
80-
float lineNoise = lineNoise_1 * lineNoise_2 * _Offset - RGBSplitNoise;
83+
float lineNoise = lineNoise1 * lineNoise2 * _Offset - RGBSplitNoise;
8184

8285
return float4(lineNoise, lineNoise, lineNoise, 1);
8386
}

Assets/X-PostProcessing/Effects/GlitchImageBlockV3/Editor/GlitchImageBlockV3Editor.cs

+3-8
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ public sealed class GlitchImageBlockV3Editor : PostProcessEffectEditor<GlitchIma
2323
{
2424

2525
SerializedParameterOverride Speed;
26-
SerializedParameterOverride Density;
27-
SerializedParameterOverride MaxDisplacement;
26+
SerializedParameterOverride BlockSize;
2827

2928

3029
public override void OnEnable()
3130
{
3231
Speed = FindParameterOverride(x => x.Speed);
33-
Density = FindParameterOverride(x => x.Density);
34-
MaxDisplacement = FindParameterOverride(x => x.MaxDisplacement);
35-
32+
BlockSize = FindParameterOverride(x => x.BlockSize);
3633
}
3734

3835
public override string GetDisplayTitle()
@@ -44,9 +41,7 @@ public override void OnInspectorGUI()
4441
{
4542
EditorUtilities.DrawHeaderLabel("Core Property");
4643
PropertyField(Speed);
47-
PropertyField(Density);
48-
PropertyField(MaxDisplacement);
49-
44+
PropertyField(BlockSize);
5045
}
5146

5247
}

Assets/X-PostProcessing/Effects/GlitchImageBlockV3/GlitchImageBlockV3.cs

+4-7
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@ namespace XPostProcessing
2222
public class GlitchImageBlockV3 : PostProcessEffectSettings
2323
{
2424

25-
[Range(0.0f, 100.0f)]
25+
[Range(0.0f, 50.0f)]
2626
public FloatParameter Speed = new FloatParameter { value = 10f };
2727

28-
[Range(0.0f, 15.0f)]
29-
public FloatParameter Density = new FloatParameter { value = 8f };
30-
31-
[Range(0.0f, 10.0f)]
32-
public FloatParameter MaxDisplacement = new FloatParameter { value = 2f };
28+
[Range(0.0f, 50.0f)]
29+
public FloatParameter BlockSize = new FloatParameter { value = 8f };
3330

3431
}
3532

@@ -61,7 +58,7 @@ public override void Render(PostProcessRenderContext context)
6158
PropertySheet sheet = context.propertySheets.Get(shader);
6259
cmd.BeginSample(PROFILER_TAG);
6360

64-
sheet.properties.SetVector(ShaderIDs.Params, new Vector3(settings.Speed, settings.Density, settings.MaxDisplacement));
61+
sheet.properties.SetVector(ShaderIDs.Params, new Vector2(settings.Speed, settings.BlockSize));
6562

6663
cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
6764
cmd.EndSample(PROFILER_TAG);

Assets/X-PostProcessing/Effects/GlitchImageBlockV3/Shader/GlitchImageBlockV3.shader

+7-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// X-PostProcessing Library
44
// https://github.com/QianMo/X-PostProcessing-Library
55
// Copyright (C) 2020 QianMo. All rights reserved.
6-
// Licensed under the MIT License
6+
// Licensed under the MIT License
77
// You may not use this file except in compliance with the License.You may obtain a copy of the License at
88
// http://opensource.org/licenses/MIT
99
//----------------------------------------------------------------------------------------------------------
@@ -18,12 +18,11 @@ Shader "Hidden/X-PostProcessing/Glitch/ImageBlockV3"
1818
half3 _Params;
1919

2020
#define _Speed _Params.x
21-
#define _Density _Params.y
22-
#define _MaxDisplace _Params.z
21+
#define _BlockSize _Params.y
2322

2423
inline float randomNoise(float2 seed)
2524
{
26-
return frac(sin(dot(seed * floor(_Time.y * _Speed), float2(127.1, 311.7))) * 43758.5453123);
25+
return frac(sin(dot(seed * floor(_Time.y * _Speed), float2(17.13, 3.71))) * 43758.5453123);
2726
}
2827

2928
inline float randomNoise(float seed)
@@ -34,13 +33,12 @@ Shader "Hidden/X-PostProcessing/Glitch/ImageBlockV3"
3433
half4 Frag(VaryingsDefault i) : SV_Target
3534
{
3635

37-
float2 block = randomNoise(floor(i.texcoord * _Density));
38-
39-
half displaceNoise = pow(block.x, 8.0) * pow(block.x, 3.0) - pow(randomNoise(7.2341), 17.0) * _MaxDisplace;
36+
float2 block = randomNoise(floor(i.texcoord * _BlockSize));
37+
float displaceNoise = pow(block.x, 8.0) * pow(block.x, 3.0);
4038

4139
half ColorR = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord).r;
42-
half ColorG = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + float2(displaceNoise * 0.05 * rand(7.0), 0.0)).g;
43-
half ColorB = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord - float2(displaceNoise * 0.05 * rand(13.0), 0.0)).b;
40+
half ColorG = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + float2(displaceNoise * 0.05 * randomNoise(7.0), 0.0)).g;
41+
half ColorB = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord - float2(displaceNoise * 0.05 * randomNoise(13.0), 0.0)).b;
4442

4543
return half4(ColorR, ColorG, ColorB, 1.0);
4644

Assets/X-PostProcessing/Effects/GlitchImageBlockV4/Editor/GlitchImageBlockV4Editor.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ public sealed class GlitchImageBlockV4Editor : PostProcessEffectEditor<GlitchIma
2424

2525
SerializedParameterOverride Speed;
2626
SerializedParameterOverride BlockSize;
27-
SerializedParameterOverride MaxOffsetX;
28-
SerializedParameterOverride MaxOffsetY;
27+
SerializedParameterOverride MaxRGBSplitX;
28+
SerializedParameterOverride MaxRGBSplitY;
2929

3030

3131

3232
public override void OnEnable()
3333
{
3434
Speed = FindParameterOverride(x => x.Speed);
3535
BlockSize = FindParameterOverride(x => x.BlockSize);
36-
MaxOffsetX = FindParameterOverride(x => x.MaxOffsetX);
37-
MaxOffsetY = FindParameterOverride(x => x.MaxOffsetY);
36+
MaxRGBSplitX = FindParameterOverride(x => x.MaxRGBSplitX);
37+
MaxRGBSplitY = FindParameterOverride(x => x.MaxRGBSplitY);
3838
}
3939

4040
public override string GetDisplayTitle()
@@ -47,8 +47,10 @@ public override void OnInspectorGUI()
4747
EditorUtilities.DrawHeaderLabel("Core Property");
4848
PropertyField(Speed);
4949
PropertyField(BlockSize);
50-
PropertyField(MaxOffsetX);
51-
PropertyField(MaxOffsetY);
50+
51+
EditorUtilities.DrawHeaderLabel("RGB Split");
52+
PropertyField(MaxRGBSplitX);
53+
PropertyField(MaxRGBSplitY);
5254
}
5355

5456
}

Assets/X-PostProcessing/Effects/GlitchImageBlockV4/GlitchImageBlockV4.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ public class GlitchImageBlockV4 : PostProcessEffectSettings
2323
{
2424
[Range(0f, 50f)]
2525
public FloatParameter Speed = new FloatParameter { value = 10f };
26+
2627
[Range(0f, 50f)]
2728
public FloatParameter BlockSize = new FloatParameter { value = 8f };
2829

2930
[Range(0f, 25f)]
30-
public FloatParameter MaxOffsetX = new FloatParameter { value = 1f };
31+
public FloatParameter MaxRGBSplitX = new FloatParameter { value = 1f };
3132

3233
[Range(0f, 25f)]
33-
public FloatParameter MaxOffsetY = new FloatParameter { value = 1f };
34+
public FloatParameter MaxRGBSplitY = new FloatParameter { value = 1f };
3435
}
3536

3637
public sealed class GlitchImageBlockV4Renderer : PostProcessEffectRenderer<GlitchImageBlockV4>
@@ -64,7 +65,7 @@ public override void Render(PostProcessRenderContext context)
6465
PropertySheet sheet = context.propertySheets.Get(shader);
6566
cmd.BeginSample(PROFILER_TAG);
6667

67-
sheet.properties.SetVector(ShaderIDs.Params, new Vector4(settings.Speed, settings.BlockSize, settings.MaxOffsetX, settings.MaxOffsetY));
68+
sheet.properties.SetVector(ShaderIDs.Params, new Vector4(settings.Speed, settings.BlockSize, settings.MaxRGBSplitX, settings.MaxRGBSplitY));
6869

6970
cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, 0);
7071
cmd.EndSample(PROFILER_TAG);

Assets/X-PostProcessing/Effects/GlitchImageBlockV4/Shader/GlitchImageBlockV4.shader

+20-13
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,38 @@ Shader "Hidden/X-PostProcessing/Glitch/ImageBlockV4"
1818
uniform half4 _Params;
1919
#define _Speed _Params.x
2020
#define _BlockSize _Params.y
21-
#define _MaxOffsetX _Params.z
22-
#define _MaxOffsetY _Params.w
21+
#define _MaxRGBSplitX _Params.z
22+
#define _MaxRGBSplitY _Params.w
2323

2424

2525
inline float randomNoise(float2 seed)
2626
{
27-
return frac(sin(dot(seed * floor(_Time.y * _Speed), float2(127.1, 311.7))) * 43758.5453123);
27+
return frac(sin(dot(seed * floor(_Time.y * _Speed), float2(17.13, 3.71))) * 43758.5453123);
2828
}
2929

30-
3130
inline float randomNoise(float seed)
3231
{
3332
return randomNoise(float2(seed, 1.0));
3433
}
3534

36-
float4 Frag(VaryingsDefault i) : SV_Target
35+
half4 Frag(VaryingsDefault i) : SV_Target
3736
{
38-
float2 block = randomNoise(floor(i.texcoord * _BlockSize));
39-
float OffsetX = pow(block.x, 8.0) * pow(block.x, 3.0) - pow(randomNoise(7.2341), 17.0) * _MaxOffsetX;
40-
float OffsetY = pow(block.x, 8.0) * pow(block.x, 3.0) - pow(randomNoise(7.2341), 17.0) * _MaxOffsetY;
41-
float4 r = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
42-
float4 g = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + half2(OffsetX * 0.05 * randomNoise(7.0), OffsetY*0.05*randomNoise(12.0)));
43-
float4 b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord - half2(OffsetX * 0.05 * randomNoise(13.0), OffsetY*0.05*randomNoise(12.0)));
44-
45-
return half4(r.x, g.g, b.z, (r.a + g.a + b.a));
37+
half2 block = randomNoise(floor(i.texcoord * _BlockSize));
38+
39+
float displaceNoise = pow(block.x, 8.0) * pow(block.x, 3.0);
40+
float splitRGBNoise = pow(randomNoise(7.2341), 17.0);
41+
float offsetX = displaceNoise - splitRGBNoise * _MaxRGBSplitX;
42+
float offsetY = displaceNoise - splitRGBNoise * _MaxRGBSplitY;
43+
44+
float noiseX = 0.05 * randomNoise(13.0);
45+
float noiseY = 0.05 * randomNoise(7.0);
46+
float2 offset = float2(offsetX * noiseX, offsetY* noiseY);
47+
48+
half4 colorR = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
49+
half4 colorG = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + offset);
50+
half4 colorB = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord - offset);
51+
52+
return half4(colorR.r , colorG.g, colorB.z, (colorR.a + colorG.a + colorB.a));
4653
}
4754

4855
ENDHLSL

Assets/X-PostProcessing/Profiles/X-PostProcessing ExampleProfiles.asset

+22
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ MonoBehaviour:
2222
- {fileID: 114964623377917018}
2323
- {fileID: 114789630020481822}
2424
- {fileID: 114320506431503834}
25+
- {fileID: 114760233488171950}
2526
--- !u!114 &114186190907686168
2627
MonoBehaviour:
2728
m_ObjectHideFlags: 3
@@ -169,6 +170,27 @@ MonoBehaviour:
169170
RTDownScaling:
170171
overrideState: 1
171172
value: 2.66
173+
--- !u!114 &114760233488171950
174+
MonoBehaviour:
175+
m_ObjectHideFlags: 3
176+
m_PrefabParentObject: {fileID: 0}
177+
m_PrefabInternal: {fileID: 0}
178+
m_GameObject: {fileID: 0}
179+
m_Enabled: 1
180+
m_EditorHideFlags: 0
181+
m_Script: {fileID: 11500000, guid: c9acc76ac9d8d4e4a8d7294a5bd00c85, type: 3}
182+
m_Name: GlitchImageBlockV3
183+
m_EditorClassIdentifier:
184+
active: 1
185+
enabled:
186+
overrideState: 1
187+
value: 1
188+
Speed:
189+
overrideState: 0
190+
value: 10
191+
BlockSize:
192+
overrideState: 0
193+
value: 8
172194
--- !u!114 &114789630020481822
173195
MonoBehaviour:
174196
m_ObjectHideFlags: 3

0 commit comments

Comments
 (0)