Skip to content

Commit c476a39

Browse files
Compressing shader code
1 parent 362ee68 commit c476a39

File tree

2 files changed

+58
-35
lines changed

2 files changed

+58
-35
lines changed

Diff for: I.shader

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
//652 chars
2-
//Apply material with shader to quad.
3-
//Compiled in Unity 2018.1.0f2
4-
//Author: Przemyslaw Zaworski
5-
6-
Shader "I"
7-
{
8-
Subshader
9-
{
10-
Pass
11-
{
12-
Cull Off
1+
//635 chars
2+
//Apply material with shader to quad.
3+
//Compiled in Unity 2018.1.0f2
4+
//Author: Przemyslaw Zaworski
5+
6+
Shader "I"
7+
{
8+
Subshader
9+
{
10+
Pass
11+
{
12+
Cull Off
1313
CGPROGRAM
14-
#pragma vertex V
15-
#pragma fragment P
16-
17-
#define l lerp
18-
19-
float f(float3 x)
20-
{
21-
float3 p = floor(x),f = smoothstep(0,1,frac(x)),n = {1,0,0};
22-
#define h(m) frac(sin(dot(m,float3(1,13,57)))*1e5)
23-
return l(l(l(h(p),h(p+n.xyy),f.x),l(h(p+n.yxy),h(p+n.xxy),f.x),f.y),l(l(h(p+n.yyx),h(p+n.xyx),f.x),l(h(p+n.yxx),h(p+1),f.x),f.y),f.z);
24-
}
25-
26-
void V(uint i:SV_VertexID,out float4 c:SV_POSITION) {c=float4(((i<<1)&2)*2.-1,-2.*(i&2)+1,.1,1);}
27-
28-
void P(float4 u:SV_POSITION, out float4 s:COLOR)
29-
{
30-
u = float4(9*u.xy/_ScreenParams,_Time.g,0);
31-
for (float i=0;i<1;i+=.02,u.y-=.1,u.w=(f(u)+f(u+9.5))*.5,s=l(s,u.w,smoothstep(0,1,(u.w-i)/fwidth(u.w)))){}
32-
}
33-
34-
ENDCG
35-
}
36-
}
14+
#pragma vertex V
15+
#pragma fragment P
16+
17+
#define l lerp
18+
19+
half f(half3 x)
20+
{
21+
half3 p = floor(x),f = smoothstep(0,1,frac(x)),n = {1,0,0};
22+
#define h(m) frac(sin(dot(m,half3(1,13,57)))*1e5)
23+
return l(l(l(h(p),h(p+n.xyy),f.x),l(h(p+n.yxy),h(p+n.xxy),f.x),f.y),l(l(h(p+n.yyx),h(p+n.xyx),f.x),l(h(p+n.yxx),h(p+1),f.x),f.y),f.z);
24+
}
25+
26+
void V(uint i:SV_VertexID,out half4 c:POSITION) {c=half4(((i<<1)&2)*2.-1,-2.*(i&2)+1,.1,1);}
27+
28+
void P(half4 u:POSITION, out half s:COLOR)
29+
{
30+
u = half4(9*u.xy/_ScreenParams,_Time.g,0);
31+
for (half i=0;i<1;i+=.02,u.y-=.1,u.w=(f(u)+f(u+9.5))*.5,s=l(s,u.w,smoothstep(0,1,(u.w-i)/fwidth(u.w)))){}
32+
}
33+
34+
ENDCG
35+
}
36+
}
3737
}

Diff for: uv.shader

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Shader "UV"
2+
{
3+
SubShader
4+
{
5+
Pass
6+
{
7+
CGPROGRAM
8+
#pragma vertex vertex_shader
9+
#pragma fragment pixel_shader
10+
11+
void vertex_shader (inout float4 vertex:POSITION,inout float2 uv:TEXCOORD0)
12+
{
13+
vertex = UnityObjectToClipPos(vertex);
14+
}
15+
16+
float4 pixel_shader (float4 vertex:POSITION,float2 uv:TEXCOORD0) : SV_TARGET
17+
{
18+
return float4(uv,0,1);
19+
}
20+
ENDCG
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)