1
+ //source: https://www.shadertoy.com/view/XtVGD1
2
+ //Notebook drawings post processing fullscreen effect.
3
+ //Include notebook_drawings.cs to Main Camera and material with shader.
4
+ //Removed noise for better performance.
5
+
6
+ Shader "Notebook Drawings"
7
+ {
8
+ Properties
9
+ {
10
+ _MainTex ( "Texture" , 2D ) = "white" {}
11
+ SampNum ( "Sample count" , Int ) = 8
12
+ }
13
+ Subshader
14
+ {
15
+ Pass
16
+ {
17
+ CGPROGRAM
18
+ #pragma vertex vertex_shader
19
+ #pragma fragment pixel_shader
20
+ #pragma target 4.0
21
+
22
+ sampler2D _MainTex;
23
+ int SampNum;
24
+
25
+ float4 getCol (float2 pos)
26
+ {
27
+ float2 uv=((pos-_ScreenParams .xy*.5 )/_ScreenParams .y*_ScreenParams .y)/_ScreenParams .xy+.5 ;
28
+ uv.y=1.0 -uv.y;
29
+ float4 c1=tex2Dlod (_MainTex,float4 (uv,0 ,0 ));
30
+ float4 e=smoothstep (float4 (-0.05 ,-0.05 ,-0.05 ,-0.05 ),float4 (0 ,0 ,0 ,0 ),float4 (uv,float2 (1 ,1 )-uv));
31
+ c1=lerp (float4 (1 ,1 ,1 ,0 ),c1,e.x*e.y*e.z*e.w);
32
+ float d=clamp (dot (c1.xyz,float3 (-.5 ,1 .,-.5 )),0.0 ,1.0 );
33
+ float4 c2=float4 (0.7 ,0.7 ,0.7 ,0.7 );
34
+ return min (lerp (c1,c2,1.8 *d),.7 );
35
+ }
36
+
37
+ float4 getColHT (float2 pos)
38
+ {
39
+ return getCol (pos);
40
+ }
41
+
42
+ float getVal (float2 pos)
43
+ {
44
+ float4 c=getCol (pos);
45
+ return pow (dot (c.xyz,float3 (0.333 ,0.333 ,0.333 )),1 .)*1 .;
46
+ }
47
+
48
+ float2 getGrad (float2 pos, float eps)
49
+ {
50
+ float2 d=float2 (eps,0 );
51
+ return float2 (
52
+ getVal (pos+d.xy)-getVal (pos-d.xy),
53
+ getVal (pos+d.yx)-getVal (pos-d.yx)
54
+ )/eps/2 .;
55
+ }
56
+
57
+ float4 vertex_shader (float4 vertex : POSITION ) : SV_POSITION
58
+ {
59
+ return UnityObjectToClipPos (vertex);
60
+ }
61
+
62
+ float4 pixel_shader (float4 vertex:SV_POSITION ) : SV_TARGET
63
+ {
64
+ float2 pos = vertex.xy+4.0 *sin (float2 (1 ,1.7 ))*_ScreenParams .y/400.0 ;
65
+ float3 col = float3 (0 ,0 ,0 );
66
+ float3 col2 = float3 (0 ,0 ,0 );
67
+ float sum=0.0 ;
68
+ for (int i=0 ;i<3 ;i++)
69
+ {
70
+ float ang= 6.28318530717959 /3.0 *(float (i)+.8 );
71
+ float2 v=float2 (cos (ang),sin (ang));
72
+ for (int j=0 ;j<SampNum;j++)
73
+ {
74
+ float2 dpos = v.yx*float2 (1 ,-1 )*float (j)*_ScreenParams .y/400 .;
75
+ float2 dpos2 = v.xy*float (j*j)/float (SampNum)*.5 *_ScreenParams .y/400 .;
76
+ float2 g;
77
+ float fact,fact2;
78
+ for (float s=-1 .;s<=1 .;s+=2 .)
79
+ {
80
+ float2 pos2=pos+s*dpos+dpos2;
81
+ float2 pos3=pos+(s*dpos+dpos2).yx*float2 (1 ,-1 )*2 .;
82
+ g=getGrad (pos2,.4 );
83
+ fact=dot (g,v)-.5 *abs (dot (g,v.yx*float2 (1 ,-1 )))/**(1.-getVal(pos2))*/ ;
84
+ fact2=dot (normalize (g+float2 (.0001 ,.0001 )),v.yx*float2 (1 ,-1 ));
85
+ fact=clamp (fact,0.0 ,0.05 );
86
+ fact2=abs (fact2);
87
+ fact*=1 .-float (j)/float (SampNum);
88
+ col += fact;
89
+ col2 += fact2*getColHT (pos3).xyz;
90
+ sum+=fact2;
91
+ }
92
+ }
93
+ }
94
+ col/=float (SampNum*3 )*.75 /sqrt (_ScreenParams .y);
95
+ col2/=sum;
96
+ col.x=1 .-col.x;
97
+ col.x*=col.x*col.x;
98
+ float2 s=sin (pos.xy*.1 /sqrt (_ScreenParams .y/400 .));
99
+ float3 karo=float3 (1 ,1 ,1 );
100
+ karo-=.5 *float3 (.25 ,.1 ,.1 )*dot (exp (-s*s*80 .),float2 (1 ,1 ));
101
+ float r=length (pos-_ScreenParams .xy*.5 )/_ScreenParams .x;
102
+ float vign=1 .-r*r*r;
103
+ return float4 (float3 (col.x*col2*karo*vign),1 );
104
+ }
105
+ ENDCG
106
+ }
107
+ }
108
+ }
0 commit comments