forked from QianMo/X-PostProcessing-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrainyBlur.shader
72 lines (54 loc) · 1.64 KB
/
GrainyBlur.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//----------------------------------------------------------------------------------------------------------
// X-PostProcessing Library
// https://github.com/QianMo/X-PostProcessing-Library
// Copyright (C) 2020 QianMo. All rights reserved.
// Licensed under the MIT License
// You may not use this file except in compliance with the License.You may obtain a copy of the License at
// http://opensource.org/licenses/MIT
//----------------------------------------------------------------------------------------------------------
Shader "Hidden/X-PostProcessing/GrainyBlur"
{
HLSLINCLUDE
#include "../../../Shaders/StdLib.hlsl"
#include "../../../Shaders/XPostProcessing.hlsl"
half2 _Params;
half _MainTex_ST;
#define _BlurRadius _Params.x
#define _Iteration _Params.y
float Rand(float2 n)
{
return sin(dot(n, half2(1233.224, 1743.335)));
}
half4 GrainyBlur(VaryingsDefault i)
{
half2 randomOffset = float2(0.0, 0.0);
half4 finalColor = half4(0.0, 0.0, 0.0, 0.0);
float random = Rand(i.texcoord);
for (int k = 0; k < int(_Iteration); k ++)
{
random = frac(43758.5453 * random + 0.61432);;
randomOffset.x = (random - 0.5) * 2.0;
random = frac(43758.5453 * random + 0.61432);
randomOffset.y = (random - 0.5) * 2.0;
finalColor += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, half2(i.texcoord + randomOffset * _BlurRadius));
}
return finalColor / _Iteration;
}
half4 Frag(VaryingsDefault i): SV_Target
{
return GrainyBlur(i);
}
ENDHLSL
SubShader
{
Cull Off ZWrite Off ZTest Always
Pass
{
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment Frag
ENDHLSL
}
}
}