jax 0.0.0.4 → 0.0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CHANGELOG +14 -0
  2. data/Rakefile +4 -0
  3. data/builtin/shaders/depthmap/fragment.ejs +4 -2
  4. data/builtin/shaders/depthmap/material.js +5 -0
  5. data/builtin/shaders/depthmap/vertex.ejs +4 -1
  6. data/builtin/shaders/functions/noise.ejs +523 -0
  7. data/builtin/shaders/lighting/common.ejs +1 -1
  8. data/builtin/shaders/normal_map/common.ejs +1 -1
  9. data/builtin/shaders/{paraboloid-depthmap → paraboloid}/common.ejs +2 -2
  10. data/builtin/shaders/{paraboloid-depthmap → paraboloid}/fragment.ejs +3 -3
  11. data/builtin/shaders/paraboloid/manifest.yml +5 -0
  12. data/builtin/shaders/{paraboloid-depthmap → paraboloid}/material.js +4 -4
  13. data/builtin/shaders/{paraboloid-depthmap → paraboloid}/vertex.ejs +1 -0
  14. data/builtin/shaders/shadow_map/common.ejs +1 -1
  15. data/builtin/shaders/shadow_map/fragment.ejs +1 -1
  16. data/lib/jax.rb +4 -0
  17. data/lib/jax/application.rb +4 -5
  18. data/lib/jax/generators/app/templates/public/javascripts/jax.js +190 -6
  19. data/lib/jax/generators/material/USAGE +1 -1
  20. data/lib/jax/generators/shader/templates/common.ejs.tt +1 -1
  21. data/lib/jax/generators/shader/templates/spec.js.tt +4 -0
  22. data/lib/jax/packager/sprockets_template.rb +4 -0
  23. data/lib/jax/resource_compiler.rb +1 -1
  24. data/lib/jax/shader.rb +19 -7
  25. data/lib/jax/version.rb +1 -1
  26. data/spec/example_app/app/controllers/noise_controller.js +18 -0
  27. data/spec/example_app/app/helpers/noise_helper.js +3 -0
  28. data/spec/example_app/app/resources/materials/blob.yml +28 -0
  29. data/spec/example_app/app/shaders/blob/common.ejs +18 -0
  30. data/spec/example_app/app/shaders/blob/fragment.ejs +8 -0
  31. data/spec/example_app/app/shaders/blob/manifest.yml +15 -0
  32. data/spec/example_app/app/shaders/blob/material.js +48 -0
  33. data/spec/example_app/app/shaders/blob/vertex.ejs +13 -0
  34. data/spec/example_app/app/views/noise/index.js +4 -0
  35. data/spec/example_app/config/routes.rb +1 -0
  36. data/spec/example_app/spec/javascripts/controllers/noise_controller_spec.js +11 -0
  37. data/spec/example_app/spec/javascripts/helpers/noise_helper_spec.js +12 -0
  38. data/spec/example_app/spec/javascripts/shaders/blob_spec.js +30 -0
  39. data/spec/example_app/spec/javascripts/support/spec_layout.html.erb +2 -1
  40. data/spec/javascripts/shaders/core_materials_spec.js +1 -0
  41. data/spec/javascripts/shaders/{dual_paraboloid_spec.js → paraboloid_spec.js} +2 -2
  42. data/src/constants.yml +1 -0
  43. data/src/constants.yml.erb +1 -0
  44. data/src/jax.js +14 -1
  45. data/src/jax/noise.js +193 -0
  46. data/src/jax/webgl/material.js +3 -2
  47. data/src/jax/webgl/scene/light_source.js +3 -2
  48. metadata +41 -12
  49. data/spec/javascripts/Player.js +0 -58
data/lib/jax/version.rb CHANGED
@@ -3,7 +3,7 @@ module Jax
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
5
  TINY = 0
6
- PATCH = 4
6
+ PATCH = 5
7
7
 
8
8
  STRING = PATCH == 0 ? "#{MAJOR}.#{MINOR}.#{TINY}" : "#{MAJOR}.#{MINOR}.#{TINY}.#{PATCH}"
9
9
  end
@@ -0,0 +1,18 @@
1
+ //= require "application_controller"
2
+
3
+ var NoiseController = (function() {
4
+ return Jax.Controller.create("noise", ApplicationController, {
5
+ index: function() {
6
+ var model = new Jax.Model({mesh:new Jax.Mesh.Sphere({material:Material.find("blob")})});
7
+ this.world.addObject(model);
8
+ this.player.camera.move(-5);
9
+ },
10
+
11
+
12
+ // Some special actions are fired whenever the corresponding input is
13
+ // received from the user.
14
+ mouse_clicked: function(event) {
15
+
16
+ }
17
+ });
18
+ })();
@@ -0,0 +1,3 @@
1
+ var NoiseHelper = Jax.Helper.create({
2
+
3
+ });
@@ -0,0 +1,28 @@
1
+ # ambient component multiplied with the light source's ambient component
2
+ ambient:
3
+ red: 1.0
4
+ green: 1.0
5
+ blue: 1.0
6
+ alpha: 1.0
7
+
8
+ # diffuse component multiplied with the light source's diffuse component
9
+ diffuse:
10
+ red: 1.0
11
+ green: 1.0
12
+ blue: 1.0
13
+ alpha: 1.0
14
+
15
+ # specular component multiplied with the light source's specular component
16
+ specular:
17
+ red: 1.0
18
+ green: 1.0
19
+ blue: 1.0
20
+ alpha: 1.0
21
+
22
+ shininess: 30
23
+
24
+ layers:
25
+ # remove Lighting to conserve video memory if you don't need/want support for light sources
26
+ - type: Lighting
27
+
28
+ - type: Blob
@@ -0,0 +1,18 @@
1
+ //= require "functions/noise"
2
+
3
+ // Shared variables save on graphics memory and allow you to "piggy-back" off of
4
+ // variables defined in other shaders:
5
+
6
+ shared uniform mat3 nMatrix;
7
+ shared uniform mat4 mvMatrix, pMatrix;
8
+
9
+ shared varying vec2 vTexCoords;
10
+ shared varying vec3 vNormals;
11
+ shared varying vec4 vColor;
12
+
13
+ // If a variable isn't shared, it will be defined specifically for this shader.
14
+ // If this shader is used twice in one materials, unshared variables will be
15
+ // defined twice -- once for each use of the shader.
16
+
17
+ // uniform sampler2D Texture;
18
+ // uniform float TextureScaleX, TextureScaleY;
@@ -0,0 +1,8 @@
1
+ /*
2
+ If you don't need the color attributes, use
3
+ void main(void)
4
+ to make your shader more efficient.
5
+ */
6
+ void main(inout vec4 ambient, inout vec4 diffuse, inout vec4 specular) {
7
+ diffuse = vColor;
8
+ }
@@ -0,0 +1,15 @@
1
+ description: |
2
+ Causes the object to have "blob-like" edges, like a thick liquid
3
+
4
+
5
+ # Add an 'options' attribute if your shader's Material can accept
6
+ # multiple configurations. Usually, you'll have an option for each
7
+ # corresponding uniform or attribute variable.
8
+
9
+ # Example:
10
+
11
+ #options:
12
+ # path: "/path/to/texture.png"
13
+ # flip_y: false
14
+ # scale_x: 1.0
15
+ # scale_y: 1.0
@@ -0,0 +1,48 @@
1
+ Jax.Material.Blob = (function() {
2
+ function getNoise(self, context) {
3
+ var noise = self.noise[context.id];
4
+ if (!noise) noise = self.noise[context.id] = new Jax.Noise(context);
5
+ return noise;
6
+ }
7
+
8
+ return Jax.Class.create(Jax.Material, {
9
+ initialize: function($super, options) {
10
+ options = Jax.Util.normalizeOptions(options, {
11
+ shader: "blob",
12
+
13
+ // You can specify default options (see +manifest.yml+) here.
14
+ });
15
+
16
+ $super(options);
17
+ this.noise = {};
18
+ },
19
+
20
+ setUniforms: function($super, context, mesh, options, uniforms) {
21
+ $super(context, mesh, options, uniforms);
22
+
23
+ uniforms.set('mvMatrix', context.getModelViewMatrix());
24
+ uniforms.set('nMatrix', context.getNormalMatrix());
25
+ uniforms.set('pMatrix', context.getProjectionMatrix());
26
+
27
+ // uniforms.texture('Texture', this.texture, context);
28
+
29
+ this.l = this.l || new Date().getTime();
30
+ var tc = (new Date().getTime() - this.l) / 1000;
31
+
32
+ var noise = getNoise(this, context);
33
+
34
+ uniforms.texture('permTexture', noise.perm, context);
35
+ uniforms.texture('simplexTexture', noise.simplex, context);
36
+ uniforms.texture('gradTexture', noise.grad, context);
37
+
38
+ uniforms.set('time', tc);
39
+ },
40
+
41
+ setAttributes: function($super, context, mesh, options, attributes) {
42
+ attributes.set('VERTEX_POSITION', mesh.getVertexBuffer());
43
+ attributes.set('VERTEX_COLOR', mesh.getColorBuffer());
44
+ attributes.set('VERTEX_NORMAL', mesh.getNormalBuffer());
45
+ attributes.set('VERTEX_TEXCOORDS', mesh.getTextureCoordsBuffer());
46
+ }
47
+ });
48
+ })();
@@ -0,0 +1,13 @@
1
+ shared attribute vec4 VERTEX_POSITION, VERTEX_COLOR;
2
+ shared attribute vec3 VERTEX_NORMAL;
3
+ shared attribute vec2 VERTEX_TEXCOORDS;
4
+
5
+ void main(void) {
6
+ vec4 pos = VERTEX_POSITION;
7
+ float n = snoise(vec4(pos.xyz, time));
8
+ pos.xyz += normalize(pos.xyz)*n;
9
+
10
+ gl_Position = pMatrix * mvMatrix * pos;
11
+
12
+ vColor = vec4(n);
13
+ }
@@ -0,0 +1,4 @@
1
+ Jax.views.push('noise/index', function() {
2
+ this.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3
+ this.world.render();
4
+ });
@@ -1,4 +1,5 @@
1
1
  ExampleApp.routes.map do
2
+ map 'noise/index'
2
3
  map 'textures/index'
3
4
  root 'lighting'
4
5
  map 'shadows'
@@ -0,0 +1,11 @@
1
+ describe("NoiseController", function() {
2
+ var controller;
3
+
4
+ beforeEach(function() {
5
+ controller = new NoiseController();
6
+ });
7
+
8
+ it("does something", function() {
9
+ expect(1).toEqual(1);
10
+ });
11
+ });
@@ -0,0 +1,12 @@
1
+ describe("NoiseHelper", function() {
2
+ var helper;
3
+
4
+ beforeEach(function() {
5
+ var klass = Jax.Class.create({helpers: function() { return [NoiseHelper]; } });
6
+ helper = new klass();
7
+ });
8
+
9
+ it("does something", function() {
10
+ expect(1).toEqual(1);
11
+ });
12
+ });
@@ -0,0 +1,30 @@
1
+ describe("Shader 'blob'", function() {
2
+ var context, material, mesh;
3
+
4
+ beforeEach(function() {
5
+ context = new Jax.Context('webgl-canvas');
6
+ mesh = new Jax.Mesh.Quad();
7
+ });
8
+
9
+ afterEach(function() { context.dispose(); });
10
+
11
+ describe("stand-alone", function() {
12
+ beforeEach(function() { mesh.material = new Jax.Material.Blob(); });
13
+
14
+ xit("should render without error", function() {
15
+ expect(function() { mesh.render(context); }).not.toThrow();
16
+ });
17
+ });
18
+
19
+ describe("as a layer", function() {
20
+ beforeEach(function() {
21
+ mesh.material = new Jax.Material({layers:[{
22
+ type:"Blob"
23
+ }]});
24
+ });
25
+
26
+ xit("should render without error", function() {
27
+ expect(function() { mesh.render(context); }).not.toThrow();
28
+ });
29
+ });
30
+ });
@@ -77,7 +77,8 @@
77
77
  <div id="jax_nav">
78
78
  <a href="#" onclick="context.redirectTo('/');return false;">Lighting w/Multiple Sources</a> |
79
79
  <a href="#" onclick="context.redirectTo('shadows');return false;">Shadows</a> |
80
- <a href="#" onclick="context.redirectTo('textures');return false;">Textures</a>
80
+ <a href="#" onclick="context.redirectTo('textures');return false;">Textures</a> |
81
+ <a href="#" onclick="context.redirectTo('noise');return false;">Noise Functions</a>
81
82
  </div>
82
83
  <div id="jasmine_content"></div>
83
84
  </body>
@@ -27,6 +27,7 @@ describe("Core Materials", function() {
27
27
 
28
28
  it("should coexist with all other builtins", function() {
29
29
  var m = new Jax.Material();
30
+
30
31
  if (name != "basic" && name != "default")
31
32
  m.addLayer(Jax.Material.find(name));
32
33
 
@@ -1,10 +1,10 @@
1
- describe("Material segment 'dual_paraboloid'", function() {
1
+ describe("Material segment 'paraboloid'", function() {
2
2
  var context;
3
3
  var matr;
4
4
 
5
5
  beforeEach(function() {
6
6
  context = new Jax.Context(document.getElementById('canvas-element'));
7
- matr = new Jax.Material.DualParaboloid();
7
+ matr = new Jax.Material.Paraboloid();
8
8
  spyOn(matr, 'prepareShader').andCallThrough();
9
9
  });
10
10
 
data/src/constants.yml ADDED
@@ -0,0 +1 @@
1
+ JAX_VERSION: 0.0.0.5
@@ -0,0 +1 @@
1
+ JAX_VERSION: <%=Jax::Version::STRING%>
data/src/jax.js CHANGED
@@ -2,7 +2,19 @@
2
2
  * Jax
3
3
  * Root namespace containing all Jax data
4
4
  **/
5
- var Jax = { PRODUCTION: 1 };
5
+ var Jax = { PRODUCTION: 1, VERSION: "<%=JAX_VERSION%>" };
6
+
7
+ /* Called by Jax applications as of version 0.0.0.5 to alert the user to incomplete upgrades */
8
+ Jax.doVersionCheck = function(targetVersion) {
9
+ // don't do this in production cause that would be a Bad Idea
10
+ if (Jax.environment && Jax.environment == Jax.PRODUCTION) return;
11
+
12
+ if (Jax.VERSION != targetVersion) {
13
+ alert("Jax version mismatch!\n\n" +
14
+ "Your Jax gem is version "+targetVersion+", but the Jax JS library is version "+Jax.VERSION+"!\n\n" +
15
+ "Please run `rake jax:update` at the command line to fix this issue.");
16
+ }
17
+ };
6
18
 
7
19
  // note: the default_shader is used immediately after Jax.Material has been defined. So, most
8
20
  // likely the end user won't be able to customize it with the expected result. Materials created
@@ -24,6 +36,7 @@ Jax.default_shader = "basic";
24
36
  //= require "jax/route_set"
25
37
  //= require "jax/view"
26
38
  //= require "jax/context"
39
+ //= require "jax/noise"
27
40
 
28
41
  Jax.shaders = {};
29
42
 
data/src/jax/noise.js ADDED
@@ -0,0 +1,193 @@
1
+ Jax.Noise = (function() {
2
+ var perm/*[256]*/ = [151,160,137,91,90,15,
3
+ 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
4
+ 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
5
+ 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
6
+ 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
7
+ 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
8
+ 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
9
+ 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
10
+ 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
11
+ 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
12
+ 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
13
+ 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
14
+ 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];
15
+
16
+ /* These are Ken Perlin's proposed gradients for 3D noise. I kept them for
17
+ better consistency with the reference implementation, but there is really
18
+ no need to pad this to 16 gradients for this particular implementation.
19
+ If only the "proper" first 12 gradients are used, they can be extracted
20
+ from the grad4[][] array: grad3[i][j] == grad4[i*2][j], 0<=i<=11, j=0,1,2
21
+ */
22
+ var grad3/*[16][3]*/ = [0,1,1, 0,1,-1, 0,-1,1, 0,-1,-1,
23
+ 1,0,1, 1,0,-1, -1,0,1, -1,0,-1,
24
+ 1,1,0, 1,-1,0, -1,1,0, -1,-1,0, // 12 cube edges
25
+ 1,0,-1, -1,0,-1, 0,-1,1, 0,1,1]; // 4 more to make 16
26
+
27
+ /* These are my own proposed gradients for 4D noise. They are the coordinates
28
+ of the midpoints of each of the 32 edges of a tesseract, just like the 3D
29
+ noise gradients are the midpoints of the 12 edges of a cube.
30
+ */
31
+ var grad4/*[32][4]*/ = [0,1,1,1, 0,1,1,-1, 0,1,-1,1, 0,1,-1,-1, // 32 tesseract edges
32
+ 0,-1,1,1, 0,-1,1,-1, 0,-1,-1,1, 0,-1,-1,-1,
33
+ 1,0,1,1, 1,0,1,-1, 1,0,-1,1, 1,0,-1,-1,
34
+ -1,0,1,1, -1,0,1,-1, -1,0,-1,1, -1,0,-1,-1,
35
+ 1,1,0,1, 1,1,0,-1, 1,-1,0,1, 1,-1,0,-1,
36
+ -1,1,0,1, -1,1,0,-1, -1,-1,0,1, -1,-1,0,-1,
37
+ 1,1,1,0, 1,1,-1,0, 1,-1,1,0, 1,-1,-1,0,
38
+ -1,1,1,0, -1,1,-1,0, -1,-1,1,0, -1,-1,-1,0];
39
+
40
+ /* This is a look-up table to speed up the decision on which simplex we
41
+ are in inside a cube or hypercube "cell" for 3D and 4D simplex noise.
42
+ It is used to avoid complicated nested conditionals in the GLSL code.
43
+ The table is indexed in GLSL with the results of six pair-wise
44
+ comparisons beween the components of the P=(x,y,z,w) coordinates
45
+ within a hypercube cell.
46
+ c1 = x>=y ? 32 : 0;
47
+ c2 = x>=z ? 16 : 0;
48
+ c3 = y>=z ? 8 : 0;
49
+ c4 = x>=w ? 4 : 0;
50
+ c5 = y>=w ? 2 : 0;
51
+ c6 = z>=w ? 1 : 0;
52
+ offsets = simplex[c1+c2+c3+c4+c5+c6];
53
+ o1 = step(160,offsets);
54
+ o2 = step(96,offsets);
55
+ o3 = step(32,offsets);
56
+ (For the 3D case, c4, c5, c6 and o3 are not needed.)
57
+ */
58
+ var simplex4/*[][4]*/ = [0,64,128,192, 0,64,192,128, 0,0,0,0, 0,128,192,64,
59
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 64,128,192,0,
60
+ 0,128,64,192, 0,0,0,0, 0,192,64,128, 0,192,128,64,
61
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 64,192,128,0,
62
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
63
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
64
+ 64,128,0,192, 0,0,0,0, 64,192,0,128, 0,0,0,0,
65
+ 0,0,0,0, 0,0,0,0, 128,192,0,64, 128,192,64,0,
66
+ 64,0,128,192, 64,0,192,128, 0,0,0,0, 0,0,0,0,
67
+ 0,0,0,0, 128,0,192,64, 0,0,0,0, 128,64,192,0,
68
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
69
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
70
+ 128,0,64,192, 0,0,0,0, 0,0,0,0, 0,0,0,0,
71
+ 192,0,64,128, 192,0,128,64, 0,0,0,0, 192,64,128,0,
72
+ 128,64,0,192, 0,0,0,0, 0,0,0,0, 0,0,0,0,
73
+ 192,64,0,128, 0,0,0,0, 192,128,0,64, 192,128,64,0];
74
+
75
+ var simplex_buf = null, perm_buf = null, grad_buf = null;
76
+
77
+ /*
78
+ * initPermTexture() - create and load a 2D texture for
79
+ * a combined index permutation and gradient lookup table.
80
+ * This texture is used for 2D and 3D noise, both classic and simplex.
81
+ */
82
+ function initPermTexture(context)
83
+ {
84
+ var tex = new Jax.Texture({min_filter: GL_NEAREST, mag_filter: GL_NEAREST, width:256, height:256});
85
+
86
+ if (!perm_buf) {
87
+ var pixels = new Array(256*256*4);
88
+ var i,j;
89
+ for(i = 0; i<256; i++)
90
+ for(j = 0; j<256; j++) {
91
+ var offset = (i*256+j)*4;
92
+ var value = perm[(j+perm[i]) & 0xFF];
93
+ var g = (value & 0x0F) * 3;
94
+ pixels[offset] = grad3[g+0] * 64 + 64; // Gradient x
95
+ pixels[offset+1] = grad3[g+1] * 64 + 64; // Gradient y
96
+ pixels[offset+2] = grad3[g+2] * 64 + 64; // Gradient z
97
+ pixels[offset+3] = value; // Permuted index
98
+ }
99
+ perm_buf = new Uint8Array(pixels);
100
+ }
101
+
102
+ tex.bind(context, function() {
103
+ context.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, perm_buf);
104
+ });
105
+
106
+ return tex;
107
+ }
108
+
109
+ /*
110
+ * initSimplexTexture() - create and load a 1D texture for a
111
+ * simplex traversal order lookup table. This is used for simplex noise only,
112
+ * and only for 3D and 4D noise where there are more than 2 simplices.
113
+ * (3D simplex noise has 6 cases to sort out, 4D simplex noise has 24 cases.)
114
+ */
115
+ function initSimplexTexture(context)
116
+ {
117
+ // webgl doesn't support 1D so we'll simulate it with a 64x1 texture
118
+
119
+ if (!simplex_buf) simplex_buf = new Uint8Array(simplex4);
120
+ var tex = new Jax.Texture({min_filter:GL_NEAREST,mag_filter:GL_NEAREST, width:64, height:1});
121
+ tex.bind(context, function() {
122
+ context.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, simplex_buf);
123
+ });
124
+ return tex;
125
+ }
126
+
127
+ /*
128
+ * initGradTexture(context) - create and load a 2D texture
129
+ * for a 4D gradient lookup table. This is used for 4D noise only.
130
+ */
131
+ function initGradTexture(context)
132
+ {
133
+ var tex = new Jax.Texture({min_filter: GL_NEAREST, mag_filter: GL_NEAREST, width:256, height:256});
134
+
135
+ if (!grad_buf) {
136
+ var pixels = new Array(256*256*4);
137
+ var i,j;
138
+
139
+ for(i = 0; i<256; i++)
140
+ for(j = 0; j<256; j++) {
141
+ var offset = (i*256+j)*4;
142
+ var value = perm[(j+perm[i]) & 0xFF];
143
+ var g = (value & 0x1F) * 4;
144
+ pixels[offset] = grad4[g+0] * 64 + 64; // Gradient x
145
+ pixels[offset+1] = grad4[g+1] * 64 + 64; // Gradient y
146
+ pixels[offset+2] = grad4[g+2] * 64 + 64; // Gradient z
147
+ pixels[offset+3] = grad4[g+3] * 64 + 64; // Gradient z
148
+ }
149
+
150
+ grad_buf = new Uint8Array(pixels);
151
+ }
152
+
153
+ tex.bind(context, function() {
154
+ context.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, grad_buf);
155
+ });
156
+ return tex;
157
+ }
158
+
159
+ /**
160
+ * class Jax.Noise
161
+ *
162
+ * Used by +Jax.Material.Noise+.
163
+ **/
164
+ return Jax.Class.create({
165
+ initialize: function(context) {
166
+ /**
167
+ * Jax.Noise#perm -> Jax.Texture
168
+ * A 2D texture for a combined index permutation and gradient lookup table.
169
+ * This texture is used for both 2D and 3D noise, both classic and simplex.
170
+ **/
171
+ this.perm = initPermTexture(context);
172
+
173
+ /**
174
+ * Jax.Noise#simplex -> Jax.Texture
175
+ * A 1D texture for a simplex transversal order lookup table. This is used
176
+ * for simplex noise only, and only for 3D and 4D noise where there are more
177
+ * than 2 simplices. (3D simplex noise has 6 cases to sort out, 4D simplex
178
+ * noise has 24 cases.)
179
+ *
180
+ * Note that WebGL does not support 1D textures, so this is technically a
181
+ * 2D texture with a height of 1 pixel.
182
+ **/
183
+ this.simplex = initSimplexTexture(context);
184
+
185
+ /**
186
+ * Jax.Noise#grad -> Jax.Texture
187
+ * A 2D texture for a 4D gradient lookup table. This is used for 4D noise
188
+ * only.
189
+ **/
190
+ this.grad = initGradTexture(context);
191
+ }
192
+ });
193
+ })();