Mooooonk commited on
Commit
8f23c64
·
verified ·
1 Parent(s): 9464943

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +253 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Shader Playground 0
3
- emoji: 🐢
4
- colorFrom: red
5
- colorTo: purple
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: shader-playground-0
3
+ emoji: 🐳
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,253 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>ShaderPlayground</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js"></script>
9
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
10
+ <style>
11
+ #editor {
12
+ position: absolute;
13
+ top: 0;
14
+ left: 0;
15
+ width: 100%;
16
+ height: 100%;
17
+ z-index: 10;
18
+ background-color: rgba(30, 41, 59, 0.9);
19
+ transition: background-color 0.3s ease;
20
+ }
21
+
22
+ #preview {
23
+ position: absolute;
24
+ top: 0;
25
+ left: 0;
26
+ width: 100%;
27
+ height: 100%;
28
+ z-index: 1;
29
+ }
30
+
31
+ .control-panel {
32
+ position: absolute;
33
+ bottom: 20px;
34
+ right: 20px;
35
+ z-index: 20;
36
+ background: rgba(15, 23, 42, 0.8);
37
+ border-radius: 8px;
38
+ padding: 10px;
39
+ backdrop-filter: blur(5px);
40
+ }
41
+
42
+ .gradient-border {
43
+ border: 2px solid transparent;
44
+ background-clip: padding-box;
45
+ position: relative;
46
+ }
47
+
48
+ .gradient-border::after {
49
+ content: '';
50
+ position: absolute;
51
+ top: -2px;
52
+ left: -2px;
53
+ right: -2px;
54
+ bottom: -2px;
55
+ background: linear-gradient(45deg, #6366f1, #8b5cf6, #ec4899);
56
+ z-index: -1;
57
+ border-radius: inherit;
58
+ }
59
+ </style>
60
+ </head>
61
+ <body class="bg-slate-900 text-slate-200 overflow-hidden h-screen">
62
+ <div id="preview"></div>
63
+
64
+ <div id="editor"></div>
65
+
66
+ <div class="control-panel gradient-border">
67
+ <div class="flex items-center space-x-4">
68
+ <div class="flex items-center">
69
+ <span class="text-sm mr-2">Editor Opacity:</span>
70
+ <input type="range" id="opacitySlider" min="0.1" max="1" step="0.1" value="0.9" class="w-24">
71
+ </div>
72
+ <button id="toggleEditor" class="px-3 py-1 bg-indigo-600 hover:bg-indigo-700 rounded-md text-sm font-medium transition-colors">
73
+ Toggle Editor
74
+ </button>
75
+ <button id="runShader" class="px-3 py-1 bg-emerald-600 hover:bg-emerald-700 rounded-md text-sm font-medium transition-colors">
76
+ Run Shader
77
+ </button>
78
+ </div>
79
+ </div>
80
+
81
+ <script>
82
+ // Initialize ACE Editor
83
+ const editor = ace.edit("editor");
84
+ editor.setTheme("ace/theme/twilight");
85
+ editor.session.setMode("ace/mode/glsl");
86
+ editor.setFontSize(14);
87
+ editor.setOptions({
88
+ enableBasicAutocompletion: true,
89
+ enableLiveAutocompletion: true
90
+ });
91
+
92
+ // Default shader code
93
+ const defaultShader = `
94
+ // Based on https://www.shadertoy.com/view/XslGRr
95
+ // Created by inigo quilez - iq/2013
96
+ // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
97
+
98
+ void mainImage( out vec4 fragColor, in vec2 fragCoord )
99
+ {
100
+ vec2 p = (2.0*fragCoord-iResolution.xy)/iResolution.y;
101
+
102
+ // background color
103
+ vec3 col = vec3(0.3 + 0.05*p.y);
104
+
105
+ // animate
106
+ float tt = mod(iTime,2.0)/2.0;
107
+ float ss = pow(tt,.2)*0.5 + 0.5;
108
+ ss = 1.0 + ss*0.5*sin(tt*6.2831*3.0 + p.y*0.5)*exp(-tt*4.0);
109
+ p *= vec2(0.5,1.5) + ss*vec2(0.5,-0.5);
110
+
111
+ // shape
112
+ float a = atan(p.x,p.y);
113
+ float r = length(p);
114
+ float h = abs(a);
115
+ float d = (13.0*h - 22.0*h*h + 10.0*h*h*h)/(6.0-5.0*h);
116
+
117
+ // color
118
+ float s = 1.0-0.5*clamp(r/d,0.0,1.0);
119
+ s = 0.75 + 0.75*p.x;
120
+ s *= 1.0-0.25*r;
121
+ s = 0.5 + 0.6*s;
122
+ s *= 0.5+0.5*pow( 1.0-clamp(r/d, 0.0, 1.0 ), 0.1 );
123
+ vec3 hcol = vec3(1.0,0.5*r,0.3)*s;
124
+
125
+ col = mix( col, hcol, smoothstep( -0.06, 0.06, d-r) );
126
+
127
+ fragColor = vec4(col,1.0);
128
+ }`;
129
+
130
+ editor.setValue(defaultShader.trim(), -1);
131
+
132
+ // Three.js setup for shader preview
133
+ let scene, camera, renderer, shaderMaterial;
134
+ const preview = document.getElementById('preview');
135
+
136
+ function initThreeJS() {
137
+ scene = new THREE.Scene();
138
+ camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
139
+
140
+ renderer = new THREE.WebGLRenderer({ antialias: true });
141
+ renderer.setPixelRatio(window.devicePixelRatio);
142
+ renderer.setSize(window.innerWidth, window.innerHeight);
143
+ preview.appendChild(renderer.domElement);
144
+
145
+ const geometry = new THREE.PlaneGeometry(2, 2);
146
+
147
+ shaderMaterial = new THREE.ShaderMaterial({
148
+ uniforms: {
149
+ iTime: { value: 0 },
150
+ iResolution: { value: new THREE.Vector3() }
151
+ },
152
+ vertexShader: `
153
+ void main() {
154
+ gl_Position = vec4(position, 1.0);
155
+ }
156
+ `,
157
+ fragmentShader: defaultShader
158
+ });
159
+
160
+ const mesh = new THREE.Mesh(geometry, shaderMaterial);
161
+ scene.add(mesh);
162
+
163
+ window.addEventListener('resize', onWindowResize);
164
+ onWindowResize();
165
+
166
+ animate();
167
+ }
168
+
169
+ function onWindowResize() {
170
+ camera.aspect = window.innerWidth / window.innerHeight;
171
+ camera.updateProjectionMatrix();
172
+ renderer.setSize(window.innerWidth, window.innerHeight);
173
+ shaderMaterial.uniforms.iResolution.value.set(
174
+ window.innerWidth * window.devicePixelRatio,
175
+ window.innerHeight * window.devicePixelRatio,
176
+ 1
177
+ );
178
+ }
179
+
180
+ function animate() {
181
+ requestAnimationFrame(animate);
182
+ shaderMaterial.uniforms.iTime.value = performance.now() / 1000;
183
+ renderer.render(scene, camera);
184
+ }
185
+
186
+ // Control panel functionality
187
+ const opacitySlider = document.getElementById('opacitySlider');
188
+ const toggleEditor = document.getElementById('toggleEditor');
189
+ const runShader = document.getElementById('runShader');
190
+ let editorVisible = true;
191
+
192
+ opacitySlider.addEventListener('input', () => {
193
+ const opacity = opacitySlider.value;
194
+ document.getElementById('editor').style.backgroundColor = `rgba(30, 41, 59, ${opacity})`;
195
+ });
196
+
197
+ toggleEditor.addEventListener('click', () => {
198
+ editorVisible = !editorVisible;
199
+ document.getElementById('editor').style.display = editorVisible ? 'block' : 'none';
200
+ toggleEditor.textContent = editorVisible ? 'Hide Editor' : 'Show Editor';
201
+ });
202
+
203
+ runShader.addEventListener('click', () => {
204
+ const shaderCode = editor.getValue();
205
+ try {
206
+ shaderMaterial.fragmentShader = `
207
+ uniform vec3 iResolution;
208
+ uniform float iTime;
209
+
210
+ void mainImage(out vec4 fragColor, in vec2 fragCoord);
211
+
212
+ void main() {
213
+ vec2 fragCoord = gl_FragCoord.xy;
214
+ vec4 fragColor;
215
+ mainImage(fragColor, fragCoord);
216
+ gl_FragColor = fragColor;
217
+ }
218
+
219
+ ${shaderCode}
220
+ `;
221
+ shaderMaterial.needsUpdate = true;
222
+
223
+ // Show success message
224
+ const notification = document.createElement('div');
225
+ notification.className = 'fixed top-4 right-4 bg-emerald-600 text-white px-4 py-2 rounded-md shadow-lg z-50 animate-fade-in-out';
226
+ notification.textContent = 'Shader compiled successfully!';
227
+ document.body.appendChild(notification);
228
+
229
+ setTimeout(() => {
230
+ notification.classList.add('opacity-0', 'transition-opacity', 'duration-300');
231
+ setTimeout(() => notification.remove(), 300);
232
+ }, 2000);
233
+ } catch (e) {
234
+ // Show error message
235
+ const notification = document.createElement('div');
236
+ notification.className = 'fixed top-4 right-4 bg-rose-600 text-white px-4 py-2 rounded-md shadow-lg z-50';
237
+ notification.textContent = 'Shader error: ' + e.message;
238
+ document.body.appendChild(notification);
239
+
240
+ setTimeout(() => {
241
+ notification.classList.add('opacity-0', 'transition-opacity', 'duration-300');
242
+ setTimeout(() => notification.remove(), 300);
243
+ }, 3000);
244
+ }
245
+ });
246
+
247
+ // Initialize everything
248
+ window.addEventListener('load', () => {
249
+ initThreeJS();
250
+ });
251
+ </script>
252
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - <a href="https://enzostvs-deepsite.hf.space?remix=Mooooonk/shader-playground-0" style="color: #fff;text-decoration: underline;" target="_blank" >🧬 Remix</a></p></body>
253
+ </html>