Skip to content

Commit f671a48

Browse files
committed
add base math tutorial scene
1 parent 55d866c commit f671a48

File tree

6 files changed

+144
-0
lines changed

6 files changed

+144
-0
lines changed
Binary file not shown.

Assets/FishManShaderTutorial/Materials/FishManShaderTutorial_BaseMath.mat.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
15.5 KB
Binary file not shown.

Assets/FishManShaderTutorial/Scene/BaseMath.unity.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// create by JiepengTan
2+
// date: 2018-03-27
3+
4+
Shader "FishManShaderTutorial/BaseMath"{
5+
Properties{
6+
_MainTex ("MainTex", 2D) = "white" {}
7+
}
8+
9+
SubShader
10+
{
11+
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
12+
13+
Pass
14+
{
15+
ZWrite Off
16+
Blend SrcAlpha OneMinusSrcAlpha
17+
Cull Off
18+
19+
CGPROGRAM
20+
#pragma vertex vert
21+
#pragma fragment frag
22+
#define USING_PERLIN_NOISE 1
23+
#include "ShaderLibs/Framework2D.cginc"
24+
25+
#define DrawInGrid(uv,DRAW_FUNC)\
26+
{\
27+
float2 pFloor = floor(uv);\
28+
if(length(pFloor-float2(j,i))<0.1){\
29+
col = DRAW_FUNC(frac(uv)-0.5);\
30+
}\
31+
num = num + 1.000;\
32+
i=floor(num / gridSize); j=fmod(num,gridSize);\
33+
}\
34+
35+
36+
float3 DrawSmoothstep(float2 uv){
37+
uv+=0.5;
38+
float val = smoothstep(0.0,1.0,uv.x);
39+
val = step(abs(val-uv.y),0.01);
40+
return float3(val,val,val);
41+
}
42+
float3 DrawCircle(float2 uv){
43+
float val = clamp((1.0-length(uv)*2),0.,1.);
44+
return float3(val,val,val);
45+
}
46+
float3 DrawFlower(float2 uv){
47+
float deg = atan2(uv.y,uv.x) + _Time.y * -0.1;
48+
float len = length(uv)*3.0;
49+
float offs = abs(sin(deg*3.))*0.35;
50+
return smoothstep(1.+offs,1.+offs-0.05,len);
51+
}
52+
float3 DrawWeakCircle(float2 uv){
53+
float val = clamp((1.0-length(uv)*2),0.,1.);
54+
val = pow(val,2.0);
55+
return float3(val,val,val);
56+
}
57+
float3 DrawStrongCircle(float2 uv){
58+
float val = clamp((1.0-length(uv)*2),0.,1.);
59+
val = pow(val,0.5);
60+
return float3(val,val,val);
61+
}
62+
float3 DrawBounceBall(float2 uv){
63+
uv*=4.;
64+
uv.y+=sin(ftime*PI);
65+
float val = clamp((1.0-length(uv)),0.,1.);
66+
val = smoothstep(0.,0.05,val);
67+
return float3(val,val,val);
68+
}
69+
float3 DrawRandomColor(float2 uv){
70+
uv+=0.5;
71+
uv*=4.;
72+
return Hash32(floor(uv));
73+
}
74+
float3 DrawNoise(float2 uv){
75+
uv*=4.;
76+
float val =(PNoise(uv)+1.0)*0.5;
77+
return float3(val,val,val);
78+
}
79+
float3 DrawFBM(float2 uv){
80+
uv*=4.;
81+
float val = (FBM(uv)+1.0)*0.5;
82+
return float3(val,val,val);
83+
}
84+
//»æÖƸñ×ÓÏß
85+
float3 DrawGridLine(float2 uv){
86+
float2 _uv = uv-floor(uv);
87+
float val = 0.;
88+
const float eps = 0.01;
89+
if(_uv.x<eps||_uv.y<eps){
90+
val = 1.;
91+
}
92+
return float3(val,val,val);
93+
}
94+
95+
float3 ProcessFrag(float2 uv) {
96+
float3 col = float3(0.0,0.0,0.0);
97+
float num = 0.;
98+
float gridSize = 3.;
99+
float i =0.,j=0.;
100+
uv*=gridSize;
101+
DrawInGrid(uv,DrawSmoothstep);
102+
DrawInGrid(uv,DrawCircle);
103+
DrawInGrid(uv,DrawFlower);
104+
DrawInGrid(uv,DrawWeakCircle);
105+
DrawInGrid(uv,DrawStrongCircle);
106+
DrawInGrid(uv,DrawBounceBall);
107+
DrawInGrid(uv,DrawRandomColor);
108+
DrawInGrid(uv,DrawNoise);
109+
DrawInGrid(uv,DrawFBM);
110+
111+
col +=DrawGridLine(uv);
112+
return col;
113+
}
114+
ENDCG
115+
}//end pass
116+
}//end SubShader
117+
}//end Shader
118+

Assets/FishManShaderTutorial/Shaders/BaseMath.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)