Lucas Stadler лет назад: 10
Родитель
Сommit
c91c07b2cb
3 измененных файлов с 137 добавлено и 1 удалено
  1. 135 0
      glsl/docs.js
  2. 1 0
      glsl/raymarching.html
  3. 1 1
      glsl/raymarching.js

+ 135 - 0
glsl/docs.js

@ -0,0 +1,135 @@
1
/*document.head.innerHTML = "";
2
document.body.innerHTML = "";
3
document.body.style = "margin: 0";*/
4
5
var styleEl = document.createElement("style");
6
styleEl.textContent = `
7
#toggle {
8
position: absolute;
9
bottom: 0.5ex;
10
right: 1ex;
11
z-index: 3;
12
font-size: 20px;
13
font-weight: bold;
14
color: white;
15
text-decoration: none;
16
}
17
18
#docs {
19
  position: absolute:
20
  top: 100vh;
21
  width: 100%;
22
  height: 100%;
23
  background-color: rgba(0, 0, 0, 0.5);
24
  z-index: 2;
25
}
26
27
#docs:target {
28
  position: absolute;
29
  top: 0;
30
}
31
32
#docs:target div {
33
  display: flex;
34
  justify-content: center;
35
}
36
37
#docs:target div pre {
38
  margin: 0;
39
  margin-top: 5vh;
40
  padding: 1em 2em;
41
  box-sizing: border-box;
42
43
  max-width: 1000px;
44
  height: 90vh;
45
46
  font-size: larger;
47
  /*font-weight: bold;*/
48
49
  background-color: rgba(255, 255, 255, 0.8);
50
51
  white-space: pre-wrap;
52
53
  overflow-y: scroll;
54
}
55
`
56
document.head.appendChild(styleEl);
57
58
var toggleEl = document.createElement("a");
59
toggleEl.id = "toggle";
60
toggleEl.href = "#docs";
61
toggleEl.textContent = "?";
62
function handleToggle(ev) {
63
  if (location.hash == "#docs") {
64
    location.hash = "";
65
  } else {
66
    location.hash = "#docs";
67
  }
68
  ev.preventDefault();
69
}
70
toggleEl.onclick = handleToggle;
71
document.body.appendChild(toggleEl);
72
73
var docsEl = document.createElement("pre");
74
docsEl.textContent = `# shaders!
75
76
Use the sliders on the left to change values used in the shader.
77
78
## Keyboard shortcuts
79
80
- \`Ctrl-Enter\` reruns the shader
81
- \`Ctrl-e\` toggles the editor
82
- \`Space\` toggles animation
83
- \`Ctrl-h\` toggles help
84
85
## Default uniforms
86
87
- \`uniform vec2 iResolution\`: resolution of the canvas
88
- \`uniform vec2 iMouse\`: mouse position (updated on mousemove)
89
- \`uniform float iGlobalTime\`: animation time in seconds
90
91
## Special comments
92
93
Special comments can be used to create sliders and to include other shaders, making it possible to create libraries of reusable functions.
94
95
### Sliders (\`//#slider[...]\`)
96
97
\`uniform {float,vec2,vec3} name; //#slider[...]\`
98
99
  Creates a slider called \`name\`.
100
101
  The value format is as follows:
102
103
    - Numbers are specified as \`(min,default,max)\`.
104
      (Omit the parens for \`float\` values, though.)
105
    - For vectors, the values must be separated by commas.
106
107
  For example, the following creates a slider whose \`.x\` component ranges from 0.0 to 2.0 and defaults to 1.0 and whose \`.y\` component ranges from -3.0 to 3.0, defaulting to 0.0:
108
109
    uniform vec2 example; //#slider[(0.0,1.0,2.0),(-3.0,0.0,3.0)]
110
111
### Includes (\`//#include "<name>"\`)
112
113
For example, \`//#include "includes/iq-primitives.frag"\` includes the primitives from iq's distance functions page at http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm.
114
115
## Resources
116
117
...
118
119
## Fin
120
121
That's it, now go and write some shaders!  The source code (*very* dirty) is at https://github.com/heyLu/lp/tree/master/glsl if you want to look at it or fix things.
122
`
123
124
var docsContainerEl = document.createElement("div");
125
docsContainerEl.id = "docs";
126
var innerContainerEl = document.createElement("div");
127
innerContainerEl.appendChild(docsEl);
128
docsContainerEl.appendChild(innerContainerEl);
129
document.body.appendChild(docsContainerEl);
130
131
window.addEventListener("keydown", function(ev) {
132
  if (ev.ctrlKey && ev.keyCode == 72) { // Ctrl-h
133
    handleToggle(ev);
134
  }
135
});

+ 1 - 0
glsl/raymarching.html

@ -13,5 +13,6 @@
13 13
    <script src="defaultFiles.js"></script>
14 14
    <script src="transformShader.js"></script>
15 15
    <script src="raymarching.js"></script>
16
    <script src="docs.js"></script>
16 17
  </body>
17 18
</html>

+ 1 - 1
glsl/raymarching.js

@ -283,7 +283,7 @@ void main() {
283 283
  }
284 284
  
285 285
  window.addEventListener('keydown', function(ev) {
286
    if (ev.ctrlKey && ev.keyCode == 72) { // Ctrl + H
286
    if (ev.ctrlKey && ev.keyCode == 69) { // Ctrl + e
287 287
      ev.preventDefault();
288 288
      editor.toggle();
289 289
    }