-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
173 lines (143 loc) · 5.71 KB
/
index.html
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="bunny.css">
<script src="bunny.js" type="module"></script>
<title>Search4Code</title>
</head>
<body>
<canvas class="webgl"></canvas>
<div id="instructions"> - Press to jump - </div>
<div id="credits">
<p><a href="https://www.youtube.com/@search4code?sub_confirmation=1" target="blank">Please Subscribe For More Content</a> | <a href="https://www.youtube.com/@search4code?sub_confirmation=1" target="blank">Search4Code</a></p>
</div>
<script type="x-shader/x-vertex" id="reflectorVertexShader">
uniform mat4 textureMatrix;
varying vec4 vUvReflection;
varying vec2 vUv;
#include <common>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
void main() {
#include <beginnormal_vertex>
#include <defaultnormal_vertex>
#include <begin_vertex>
vUvReflection = textureMatrix * vec4( position, 1.0 );
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
#include <logdepthbuf_vertex>
#include <worldpos_vertex>
#include <shadowmap_vertex>
}
</script>
<script type="x-shader/x-fragment" id="reflectorFragmentShader">
uniform vec3 color;
uniform sampler2D tDiffuse;
uniform sampler2D tScratches;
varying vec4 vUvReflection;
varying vec2 vUv;
#include <common>
#include <packing>
#include <lights_pars_begin>
#include <shadowmap_pars_fragment>
#include <shadowmask_pars_fragment>
#include <logdepthbuf_pars_fragment>
vec4 blur9(sampler2D image, vec4 uv, vec2 resolution, vec2 direction) {
vec4 color = vec4(0.0);
vec2 off1 = vec2(1.3846153846) * direction;
vec2 off2 = vec2(3.2307692308) * direction;
color += texture2DProj(image, uv) * 0.2270270270;
color += texture2DProj(image, uv + vec4(off1 / resolution, off1 / resolution)) * 0.3162162162;
color += texture2DProj(image, uv - vec4(off1 / resolution, off1 / resolution)) * 0.3162162162;
color += texture2DProj(image, uv + vec4(off2 / resolution, off2 / resolution)) * 0.0702702703;
color += texture2DProj(image, uv - vec4(off2 / resolution, off2 / resolution)) * 0.0702702703;
return color;
}
float blendOverlay( float base, float blend ) {
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
}
vec3 blendOverlay( vec3 base, vec3 blend ) {
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
}
void main() {
#include <logdepthbuf_fragment>
vec4 displacement = vec4( sin(vUvReflection.y * 3.) * .05, sin(vUvReflection.x * 3.) * .05, 0.0, 0.0);
vec2 resolution = vec2(30., 30.);
vec4 base = blur9( tDiffuse, vUvReflection + displacement, resolution, vec2(1., 0.) ) * .25;
base += blur9( tDiffuse, vUvReflection + displacement, resolution, vec2(-1., 0.) ) * .25;
base += blur9( tDiffuse, vUvReflection + displacement, resolution, vec2(0, 1.) ) * .25;
base += blur9( tDiffuse, vUvReflection + displacement, resolution, vec2(0, -1.) ) * .25;
vec4 scratchesCol = texture2D( tScratches, vUv);
vec3 col = mix(color, base.rgb, .5);
col.rgb += scratchesCol.r * .02;
col.gb -= scratchesCol.g * .01;
col.gb -= (1.0 - getShadowMask() ) * .015;
gl_FragColor = vec4(col, 1.0);
#include <tonemapping_fragment>
#include <colorspace_fragment>
}
</script>
<script type="x-shader/x-vertex" id="simulationVertexShader">
precision highp float;
uniform float time;
varying vec2 vUv;
void main() {
vUv = uv;
vec4 modelViewPosition = modelViewMatrix * vec4(position, 1.0);
gl_Position = projectionMatrix * modelViewPosition;
}
</script>
<script type="x-shader/x-fragment" id="simulationFragmentShader">
// fragment shader
precision highp float;
uniform sampler2D inputTexture;
uniform vec2 blade1PosOld;
uniform vec2 blade1PosNew;
uniform float strength;
uniform float time;
varying vec2 vUv;
float lineSegment(vec2 p, vec2 a, vec2 b, float thickness) {
vec2 pa = p - a;
vec2 ba = b - a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
float idk = length(pa - ba*h);
return smoothstep(thickness, .2 * thickness, idk);
}
void main(void) {
vec4 prevTexture = texture2D(inputTexture, vUv);
vec3 col = prevTexture.rgb * .999;
if (strength>0.){
float space = .001;
float crease = .001;
float thickness = .001 + strength * .001;
float leftRed = lineSegment(vUv + space, blade1PosOld, blade1PosNew, thickness);
float leftGreen = lineSegment(vUv + space + crease, blade1PosOld, blade1PosNew, thickness);
float rightRed = lineSegment(vUv - space - crease, blade1PosOld, blade1PosNew, thickness);
float rightGreen = lineSegment(vUv - space, blade1PosOld, blade1PosNew, thickness);
col.r += ( leftRed + rightRed ) * strength * 3.0;
col.g += ( leftGreen + rightGreen) * strength * 3.0;
col.r = clamp(col.r, .0, 1.0);
col.g = clamp(col.g, .0, 1.0);
}
gl_FragColor = vec4(col, 1.0);
}
</script>
<script type="x-shader/x-fragment" id="outlineFragmentShader">
uniform vec3 color;
void main(void) {
gl_FragColor = vec4( color, 1.0);
}
</script>
<script type="x-shader/x-vertex" id="outlineVertexShader">
uniform float size;
uniform float time;
void main() {
vec3 transformed = position + normal * size * (1.0 + abs( sin ( position.y * time * .02 ) * 2.0 ));
vec4 modelViewPosition = modelViewMatrix * vec4(transformed, 1.0);
gl_Position = projectionMatrix * modelViewPosition;
}
</script>
</body>
</html>