-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomGlslGuide.js
57 lines (47 loc) · 1.31 KB
/
CustomGlslGuide.js
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
create a custom function in hydra without chainging the source code
setFunction({
name: 'red', // name that will be used to access function in js as well as in glsl
type: 'src', // can be 'src', 'color', 'combine', 'combineCoords'. see below for more info
inputs: [
{
name: `amount`,
type: `float`,
default: 1.0
}
],
// The above code generates the glsl function
glsl:
`return vec4(amount,0,0,1);`
},)
//try it
red(0.7)
.out()
hush()
Types and default arguments for hydra functions.
The value in the 'type' field lets the parser know which type the function will be returned as well as default arguments.
const types = {
'src': {
returnType: 'vec4',
args: ['vec2 _st'] // the texture coordinates
},
'coord': {
returnType: 'vec2',
args: ['vec2 _st'] // the texture coordinates
},
'color': {
returnType: 'vec4',
args: ['vec4 _c0'] // the input texture
},
'combine': {
returnType: 'vec4',
args: ['vec4 _c0', 'vec4 _c1'] // two input texture
},
'combineCoord': {
returnType: 'vec2',
args: ['vec2 _st', 'vec4 _c0'] //texture coordinates and input texture
}
}
//get glsl code from hydra code
//this way you will get the code + all the utility functions, the code is at the bottom
shader = osc().modulate(noise()).glsl()
console.log(shader)