-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathWebGL.js
More file actions
50 lines (39 loc) · 1.58 KB
/
Copy pathWebGL.js
File metadata and controls
50 lines (39 loc) · 1.58 KB
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
var knownFunctions = require("./libs/knownFunctions");
var _ = require('underscore');
var builtins = {};
function Builtin(name, fn, argTypes, rtnType) {
this.name = name;
this.rtnType = rtnType || "float";
this.argTypes = argTypes || [ "float" ];
this.fn = fn;
}
function Shared(name, argTypes, rtnType) {
Builtin.call(this, name, Math[name], argTypes, rtnType);
}
function mod(a, b) { return a % b; }
function texture2D(tex, coord) {
return tex.texture2D(coord);
}
function clamp(value, low, high) {
return Math.max(low, Math.min(value, high));
}
function identity(v) { return v; }
var builtins = [
new Shared("sin"), new Shared("cos"), new Shared("tan"), new Shared("asin"),
new Shared("acos"), new Shared("exp"), new Shared("log"), new Shared("sqrt"),
new Shared("abs"), new Shared("sign"), new Shared("floor"), new Shared("ceil"),
new Shared("atan"),
new Shared("pow", [ "float", "float" ]),
new Shared("min", [ "float", "float" ]),
new Shared("max", [ "float", "float" ]),
new Builtin("float", identity, ["int"], "float"),
new Builtin("int", identity, ["float"], "int"),
new Builtin("atan", Math.atan2, [ "float", "float" ]),
new Builtin("texture2D", texture2D, [ 'sampler2D', 'vec2' ], 'vec4'),
new Builtin("mod", mod, [ 'float', 'float' ], 'float'),
new Builtin("clamp", clamp, [ 'float', 'float', 'float' ], 'float')
];
module.exports = {
Builtins: _.object(_.pluck(builtins, 'name'), _.pluck(builtins, 'fn')),
MetaBuiltins: builtins
};