-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend_to_blackle_shader.h
132 lines (129 loc) · 4.55 KB
/
send_to_blackle_shader.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Generated with Shader Minifier 1.3.5 (https://github.com/laurentlb/Shader_Minifier/)
#ifndef SHADERS_H_
# define SHADERS_H_
const char *vshader_vert =
"#version 400\n"
"void main()\n"
"{\n"
"gl_Position=vec4(gl_VertexID%2*2-1,gl_VertexID/2*2-1,1,1);\n"
"}";
const char *shader_frag =
"#version 400\n"
"uint state=uint(gl_FragCoord.x*gl_FragCoord.y)*uint(668265261);\n"
"out vec4 Frag;\n"
"vec3 attentuation,albedo;\n"
"float specularity,sharpness,emission,metal;\n"
"vec3 rotate(vec3 p,vec3 t)\n"
"{\n"
"vec3 c=cos(t),s=sin(t);\n"
"return mat3(c.z,-s.z,0,s.z,c.z,0,0,0,1)*mat3(c.y,0,s.y,0,1,0,-s.y,0,c.y)*mat3(1,0,0,0,c.x,-s.x,0,s.x,c.x)*p;\n"
"}\n"
"float softmin(float f1,float f2,float val)\n"
"{\n"
"return min(f1,f2)-pow(max(val-abs(f1-f2),0.),2)*.25/val;\n"
"}\n"
"float fCappedCone(vec3 p,float h,float r1,float r2,float r3)\n"
"{\n"
"vec2 q=vec2(length(p.xz),p.y),k1=vec2(r2,h),k2=vec2(r2-r1,2.*h),ca=vec2(q.x-min(q.x,q.y<0.?\n"
"r1:\n"
"r2),abs(q.y)-h),cb=q-k1+k2*clamp(dot(k1-q,k2)/dot(k2,k2),0.,1.);\n"
"return cb.x<0.&&ca.y<0.?\n"
"-1.:\n"
"sqrt(min(dot(ca,ca),dot(cb,cb)))-r3;\n"
"}\n"
"float wang_hash(inout uint seed)\n"
"{\n"
"seed^=61^(seed>>16)*9^(seed>>4)*668265261^seed>>15;\n"
"return float(seed)/4294967296.;\n"
"}\n"
"vec3 rndVector(inout uint state)\n"
"{\n"
"float z=wang_hash(state)*2-1,a=acos(-1)*2*wang_hash(state),r=sqrt(1-z*z);\n"
"return vec3(r*cos(a),r*sin(a),z);\n"
"}\n"
"float fPlane(vec3 p,vec3 n,float distanceFromOrigin)\n"
"{\n"
"return dot(p,n)+distanceFromOrigin;\n"
"}\n"
"float fBox(vec3 p,vec3 d)\n"
"{\n"
"vec3 q=abs(p)-d;\n"
"return length(max(q,0.))+min(0.,max(q.x,max(q.y,q.z)));\n"
"}\n"
"float scene(vec3 p)\n"
"{\n"
"p=rotate(rotate(p,vec3(-.7,0,-.04)),vec3(0,1.1,0))+vec3(.5,-1.05,0);\n"
"albedo=vec3(.03);\n"
"specularity=.3;\n"
"sharpness=64;\n"
"emission=0;\n"
"metal=.2;\n"
"vec2 seed=fract(p.xz*vec2(233.34,851.74));\n"
"seed+=dot(seed,seed+23.45);\n"
"float grid=fBox(mod(p,1e-4)-5e-5,vec3(0))-fract(seed.x*seed.y)*.02,ground=fPlane(p,vec3(0,1,0),2.2),red=min(min(softmin(fBox(p+vec3(0,-1,0),vec3(0))-.5,fCappedCone(p+vec3(0,.25,0),1,.15,.25,0),.025),fCappedCone(vec3(p.xy,abs(p.z))+vec3(1.75,1.27,-.75),.05,.4,.4,.015)-.01),fCappedCone(vec3(p.xy,abs(p.z))+vec3(1.75,1.34,-.75),.05,.55,.45,.02)-.005),black=min(softmin(softmin(softmin(fCappedCone(p+vec3(0,.6,0),.05,.3,.3,.05),fCappedCone(p+vec3(0,1,0),.3,.6,.6,.05),.05),fBox(p+vec3(0,1.4,0),vec3(.9,.15,.9))-.1,.1),mix(fBox(p+vec3(.5,1.85,0),vec3(1.55,0,1.05))-.45,grid,.01),.05),fBox(p+vec3(15.5,sin(p.x*1.8)*.1+2.05,sin(p.x*0.+sin(p.x*.7))+.75),vec3(15,0,0))-.1);\n"
"grid=min(min(red,black),ground);\n"
"albedo=grid==ground?\n"
"vec3(.1):\n"
"grid==red?\n"
"vec3(.7,.01,.01):\n"
"albedo;\n"
"metal=grid==ground?\n"
".25:\n"
"grid==red?\n"
".3:\n"
"grid==black?\n"
".9:\n"
"metal;\n"
"specularity=grid==ground?\n"
".1:\n"
"grid==black?\n"
".2:\n"
"specularity;\n"
"return grid;\n"
"}\n"
"vec3 normal(vec3 p)\n"
"{\n"
"mat3 k=mat3(p,p,p)-mat3(.001);\n"
"return normalize(scene(p)-vec3(scene(k[0]),scene(k[1]),scene(k[2])));\n"
"}\n"
"bool march(inout vec3 p,vec3 dir)\n"
"{\n"
"float dst=.1,travel=0;\n"
"for(;travel<50&&dst>.01;travel+=dst)\n"
"{\n"
"p+=dir*dst;\n"
"dst=scene(p);\n"
"}\n"
"return dst<.01;\n"
"}\n"
"vec3 calcLight(vec3 d,vec3 n,vec3 color,float power)\n"
"{\n"
"float light=max(dot(n,normalize(d)),0);\n"
"return(albedo*attentuation*light*color+pow(light,sharpness)*specularity)*power;\n"
"}\n"
"void main()\n"
"{\n"
"vec2 uv=(gl_FragCoord.xy/vec2(2560,1440)*2-1)/vec2(1,2560./1440.);\n"
"Frag.xyz=vec3(0);\n"
"vec3 n,ro,d;\n"
"for(int j=0;j<300;j++)\n"
"{\n"
"d=normalize(vec3(uv,1.f/tan(85*.5f*acos(-1)/180.f)));\n"
"ro=vec3(uv,-5);\n"
"attentuation=vec3(.5,.5,1);\n"
"for(int i=0;i<9&&march(ro,d);i++)\n"
"{\n"
"n=normal(ro);\n"
"attentuation+=albedo*emission;\n"
"Frag.xyz+=calcLight(vec3(0,10,-20),n,vec3(.5,.5,.9),.5)+calcLight(vec3(-50,20,-50),n,vec3(1,.1,.1),.5)+calcLight(vec3(50,20,-50),n,vec3(.5,1,.125),.8);\n"
"d=normalize(mix(normalize(n+rndVector(state)),reflect(d,n),metal));\n"
"attentuation*=albedo*max(dot(d,n),0)*.98;\n"
"Frag.w++;\n"
"}\n"
"Frag.xyz+=Frag.w==0?\n"
"vec3(0):\n"
"attentuation;\n"
"}\n"
"Frag.xyz=sqrt(Frag.xyz/Frag.w);\n"
"}";
#endif // SHADERS_H_