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
@@ -1,4 +1,4 @@
1
- //= require "../functions/lights"
1
+ //= require "functions/lights"
2
2
 
3
3
  shared uniform bool LIGHTING_ENABLED;
4
4
 
@@ -1,4 +1,4 @@
1
- //= require "../functions/lights"
1
+ //= require "functions/lights"
2
2
 
3
3
  uniform sampler2D NormalMap;
4
4
 
@@ -2,5 +2,5 @@ shared uniform mat4 mvMatrix;
2
2
  shared uniform float DP_SHADOW_NEAR, DP_SHADOW_FAR;
3
3
  shared uniform float DP_DIRECTION;
4
4
 
5
- shared varying float vClip;
6
- shared varying vec4 vPos;
5
+ varying float vClip;
6
+ varying vec4 vPos;
@@ -1,8 +1,8 @@
1
- //= require "../functions/depth_map"
2
-
3
1
  void main(void) {
4
2
  /* because we do our own projection, we also have to do our own clipping */
5
3
  /* if vClip is less than 0, it's behind the near plane and can be dropped. */
6
4
  if (vClip < 0.0) discard;
7
- gl_FragColor = pack_depth(vPos.z);
5
+
6
+ export(vec4, exPos, vPos);
7
+ // gl_FragColor = pack_depth(vPos.z);
8
8
  }
@@ -0,0 +1,5 @@
1
+ description: |
2
+ Renders the scene distorted into a paraboloid. Useful for fast
3
+ omnidirectional environment mapping.
4
+
5
+ # no options
@@ -1,11 +1,11 @@
1
- Jax.Material.DualParaboloid = Jax.Class.create(Jax.Material, {
2
- initialize: function($super) {
3
- $super({shader:"paraboloid-depthmap"});
1
+ Jax.Material.Paraboloid = Jax.Class.create(Jax.Material, {
2
+ initialize: function($super, options) {
3
+ $super(Jax.Util.normalizeOptions(options, {shader:"paraboloid"}));
4
4
  },
5
5
 
6
6
  setUniforms: function($super, context, mesh, options, uniforms) {
7
7
  $super(context, mesh, options, uniforms);
8
-
8
+
9
9
  uniforms.set({
10
10
  DP_SHADOW_NEAR: 0.1, //c.world.lighting.getLight().getDPShadowNear() || 0.1;}},
11
11
  DP_SHADOW_FAR: 500,//c.world.lighting.getLight().getDPShadowFar() || 500;}},
@@ -22,5 +22,6 @@ void main(void) {
22
22
  pos.w = 1.0;
23
23
 
24
24
  vPos = pos;
25
+ export(vec4, Position, pos);
25
26
  gl_Position = pos;
26
27
  }
@@ -11,4 +11,4 @@ varying vec4 vShadowCoord;
11
11
  varying vec4 vDP0, vDP1;
12
12
  //varying float vDPz, vDPDepth;
13
13
 
14
- //= require "../functions/lights"
14
+ //= require "functions/lights"
@@ -1,4 +1,4 @@
1
- //= require "../functions/depth_map"
1
+ //= require "functions/depth_map"
2
2
 
3
3
  float dp_lookup() {
4
4
  float map_depth, depth;
data/lib/jax.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "active_support/core_ext"
2
+
1
3
  module Jax
2
4
  autoload :Generators, File.join(File.dirname(__FILE__), "jax/generators/commands")
3
5
  autoload :VERSION, File.join(File.dirname(__FILE__), "jax/version")
@@ -20,6 +22,8 @@ module Jax
20
22
  def root
21
23
  application && application.root
22
24
  end
25
+
26
+ delegate :shader_load_paths, :to => :application
23
27
  end
24
28
  end
25
29
 
@@ -1,9 +1,7 @@
1
- require "active_support/core_ext"
2
-
3
1
  module Jax
4
2
  class Application
5
3
  autoload :Configuration, "jax/application/configuration"
6
-
4
+
7
5
  class << self
8
6
  def inherited(base)
9
7
  raise "You cannot have more than one Jax::Application" if Jax.application
@@ -43,6 +41,7 @@ module Jax
43
41
  delegate :config, :to => "self.class"
44
42
  delegate :root, :to => :config
45
43
  delegate :routes, :to => :config
44
+ delegate :shader_load_paths, :to => :config
46
45
 
47
46
  def shaders
48
47
  # @shaders ||= begin
@@ -62,7 +61,7 @@ module Jax
62
61
 
63
62
  def shader_paths
64
63
  shader_paths = {}
65
- config.shader_load_paths.each do |path|
64
+ shader_load_paths.each do |path|
66
65
  full_path = File.directory?(path) ? path : File.expand_path(path, config.root)
67
66
  glob = File.join(full_path, "*/{fragment,vertex}.ejs")
68
67
  Dir[glob].each do |dir|
@@ -73,7 +72,7 @@ module Jax
73
72
  end
74
73
  shader_paths
75
74
  end
76
-
75
+
77
76
  def find_root_with_flag(flag, default=nil)
78
77
  root_path = self.class.called_from
79
78
 
@@ -1,4 +1,15 @@
1
- var Jax = { PRODUCTION: 1 };
1
+ var Jax = { PRODUCTION: 1, VERSION: "0.0.0.5" };
2
+
3
+ /* Called by Jax applications as of version 0.0.0.5 to alert the user to incomplete upgrades */
4
+ Jax.doVersionCheck = function(targetVersion) {
5
+ if (Jax.environment && Jax.environment == Jax.PRODUCTION) return;
6
+
7
+ if (Jax.VERSION != targetVersion) {
8
+ alert("Jax version mismatch!\n\n" +
9
+ "Your Jax gem is version "+targetVersion+", but the Jax JS library is version "+Jax.VERSION+"!\n\n" +
10
+ "Please run `rake jax:update` at the command line to fix this issue.");
11
+ }
12
+ };
2
13
 
3
14
  Jax.default_shader = "basic";
4
15
 
@@ -4906,9 +4917,14 @@ Jax.Material.ShadowMap = Jax.Class.create(Jax.Material, {
4906
4917
  if (back) uniforms.texture('SHADOWMAP1', back, context);
4907
4918
  }
4908
4919
  });
4909
- Jax.Material.DualParaboloid = Jax.Class.create(Jax.Material, {
4920
+ Jax.Material.Depthmap = Jax.Class.create(Jax.Material, {
4910
4921
  initialize: function($super) {
4911
- $super({shader:"paraboloid-depthmap"});
4922
+ $super({shader:"depthmap"});
4923
+ }
4924
+ });
4925
+ Jax.Material.Paraboloid = Jax.Class.create(Jax.Material, {
4926
+ initialize: function($super, options) {
4927
+ $super(Jax.Util.normalizeOptions(options, {shader:"paraboloid"}));
4912
4928
  },
4913
4929
 
4914
4930
  setUniforms: function($super, context, mesh, options, uniforms) {
@@ -4959,7 +4975,7 @@ Jax.Material.Fog = Jax.Class.create(Jax.Material, {
4959
4975
  Jax.Material.create("basic");
4960
4976
  Jax.Material.create("default", {default_shader:'basic'});
4961
4977
  Jax.Material.create("depthmap", {default_shader:"depthmap"});
4962
- Jax.Material.create("paraboloid-depthmap", {type:"DualParaboloid",default_shader:"paraboloid-depthmap"});
4978
+ Jax.Material.create("paraboloid-depthmap", {type:"Paraboloid",default_shader:"paraboloid",layers:[{type:"Depthmap"}]});
4963
4979
  Jax.Core = {};
4964
4980
 
4965
4981
  Jax.Core.Face = Jax.Class.create({
@@ -5984,6 +6000,7 @@ Jax.Scene.LightSource = (function() {
5984
6000
  fieldOfView = 60;
5985
6001
  this.camera.perspective({near:nearPlane,far:nearPlane+(2.0*sceneBoundingRadius),fov:fieldOfView,width:2048,height:2048});
5986
6002
  } else if (this.type == Jax.POINT_LIGHT) {
6003
+ var paraboloid_depthmap = Jax.Material.find("paraboloid-depthmap");
5987
6004
 
5988
6005
  context.glDisable(GL_BLEND);
5989
6006
  context.glEnable(GL_CULL_FACE);
@@ -5999,7 +6016,7 @@ Jax.Scene.LightSource = (function() {
5999
6016
  mat4.set(context.getInverseViewMatrix(), sm);
6000
6017
 
6001
6018
  for (var i = 0; i < objects.length; i++) {
6002
- objects[i].render(context, {material:'paraboloid-depthmap', direction:1});
6019
+ objects[i].render(context, {material:paraboloid_depthmap, direction:1});
6003
6020
  }
6004
6021
  });
6005
6022
 
@@ -6008,7 +6025,7 @@ Jax.Scene.LightSource = (function() {
6008
6025
  context.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
6009
6026
  context.loadViewMatrix(self.camera.getModelViewMatrix());
6010
6027
  for (var i = 0; i < objects.length; i++) {
6011
- objects[i].render(context, {material:'paraboloid-depthmap',direction:-1});
6028
+ objects[i].render(context, {material:paraboloid_depthmap,direction:-1});
6012
6029
  }
6013
6030
  });
6014
6031
 
@@ -7250,6 +7267,173 @@ Jax.Context = (function() {
7250
7267
  Jax.Context.identifier = 0;
7251
7268
  Jax.Context.addMethods(GL_METHODS);
7252
7269
  Jax.Context.addMethods(Jax.EVENT_METHODS);
7270
+ Jax.Noise = (function() {
7271
+ var perm/*[256]*/ = [151,160,137,91,90,15,
7272
+ 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
7273
+ 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
7274
+ 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
7275
+ 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
7276
+ 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
7277
+ 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
7278
+ 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
7279
+ 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
7280
+ 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
7281
+ 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
7282
+ 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
7283
+ 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];
7284
+
7285
+ /* These are Ken Perlin's proposed gradients for 3D noise. I kept them for
7286
+ better consistency with the reference implementation, but there is really
7287
+ no need to pad this to 16 gradients for this particular implementation.
7288
+ If only the "proper" first 12 gradients are used, they can be extracted
7289
+ from the grad4[][] array: grad3[i][j] == grad4[i*2][j], 0<=i<=11, j=0,1,2
7290
+ */
7291
+ var grad3/*[16][3]*/ = [0,1,1, 0,1,-1, 0,-1,1, 0,-1,-1,
7292
+ 1,0,1, 1,0,-1, -1,0,1, -1,0,-1,
7293
+ 1,1,0, 1,-1,0, -1,1,0, -1,-1,0, // 12 cube edges
7294
+ 1,0,-1, -1,0,-1, 0,-1,1, 0,1,1]; // 4 more to make 16
7295
+
7296
+ /* These are my own proposed gradients for 4D noise. They are the coordinates
7297
+ of the midpoints of each of the 32 edges of a tesseract, just like the 3D
7298
+ noise gradients are the midpoints of the 12 edges of a cube.
7299
+ */
7300
+ var grad4/*[32][4]*/ = [0,1,1,1, 0,1,1,-1, 0,1,-1,1, 0,1,-1,-1, // 32 tesseract edges
7301
+ 0,-1,1,1, 0,-1,1,-1, 0,-1,-1,1, 0,-1,-1,-1,
7302
+ 1,0,1,1, 1,0,1,-1, 1,0,-1,1, 1,0,-1,-1,
7303
+ -1,0,1,1, -1,0,1,-1, -1,0,-1,1, -1,0,-1,-1,
7304
+ 1,1,0,1, 1,1,0,-1, 1,-1,0,1, 1,-1,0,-1,
7305
+ -1,1,0,1, -1,1,0,-1, -1,-1,0,1, -1,-1,0,-1,
7306
+ 1,1,1,0, 1,1,-1,0, 1,-1,1,0, 1,-1,-1,0,
7307
+ -1,1,1,0, -1,1,-1,0, -1,-1,1,0, -1,-1,-1,0];
7308
+
7309
+ /* This is a look-up table to speed up the decision on which simplex we
7310
+ are in inside a cube or hypercube "cell" for 3D and 4D simplex noise.
7311
+ It is used to avoid complicated nested conditionals in the GLSL code.
7312
+ The table is indexed in GLSL with the results of six pair-wise
7313
+ comparisons beween the components of the P=(x,y,z,w) coordinates
7314
+ within a hypercube cell.
7315
+ c1 = x>=y ? 32 : 0;
7316
+ c2 = x>=z ? 16 : 0;
7317
+ c3 = y>=z ? 8 : 0;
7318
+ c4 = x>=w ? 4 : 0;
7319
+ c5 = y>=w ? 2 : 0;
7320
+ c6 = z>=w ? 1 : 0;
7321
+ offsets = simplex[c1+c2+c3+c4+c5+c6];
7322
+ o1 = step(160,offsets);
7323
+ o2 = step(96,offsets);
7324
+ o3 = step(32,offsets);
7325
+ (For the 3D case, c4, c5, c6 and o3 are not needed.)
7326
+ */
7327
+ var simplex4/*[][4]*/ = [0,64,128,192, 0,64,192,128, 0,0,0,0, 0,128,192,64,
7328
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 64,128,192,0,
7329
+ 0,128,64,192, 0,0,0,0, 0,192,64,128, 0,192,128,64,
7330
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 64,192,128,0,
7331
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
7332
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
7333
+ 64,128,0,192, 0,0,0,0, 64,192,0,128, 0,0,0,0,
7334
+ 0,0,0,0, 0,0,0,0, 128,192,0,64, 128,192,64,0,
7335
+ 64,0,128,192, 64,0,192,128, 0,0,0,0, 0,0,0,0,
7336
+ 0,0,0,0, 128,0,192,64, 0,0,0,0, 128,64,192,0,
7337
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
7338
+ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
7339
+ 128,0,64,192, 0,0,0,0, 0,0,0,0, 0,0,0,0,
7340
+ 192,0,64,128, 192,0,128,64, 0,0,0,0, 192,64,128,0,
7341
+ 128,64,0,192, 0,0,0,0, 0,0,0,0, 0,0,0,0,
7342
+ 192,64,0,128, 0,0,0,0, 192,128,0,64, 192,128,64,0];
7343
+
7344
+ var simplex_buf = null, perm_buf = null, grad_buf = null;
7345
+
7346
+ /*
7347
+ * initPermTexture() - create and load a 2D texture for
7348
+ * a combined index permutation and gradient lookup table.
7349
+ * This texture is used for 2D and 3D noise, both classic and simplex.
7350
+ */
7351
+ function initPermTexture(context)
7352
+ {
7353
+ var tex = new Jax.Texture({min_filter: GL_NEAREST, mag_filter: GL_NEAREST, width:256, height:256});
7354
+
7355
+ if (!perm_buf) {
7356
+ var pixels = new Array(256*256*4);
7357
+ var i,j;
7358
+ for(i = 0; i<256; i++)
7359
+ for(j = 0; j<256; j++) {
7360
+ var offset = (i*256+j)*4;
7361
+ var value = perm[(j+perm[i]) & 0xFF];
7362
+ var g = (value & 0x0F) * 3;
7363
+ pixels[offset] = grad3[g+0] * 64 + 64; // Gradient x
7364
+ pixels[offset+1] = grad3[g+1] * 64 + 64; // Gradient y
7365
+ pixels[offset+2] = grad3[g+2] * 64 + 64; // Gradient z
7366
+ pixels[offset+3] = value; // Permuted index
7367
+ }
7368
+ perm_buf = new Uint8Array(pixels);
7369
+ }
7370
+
7371
+ tex.bind(context, function() {
7372
+ context.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, perm_buf);
7373
+ });
7374
+
7375
+ return tex;
7376
+ }
7377
+
7378
+ /*
7379
+ * initSimplexTexture() - create and load a 1D texture for a
7380
+ * simplex traversal order lookup table. This is used for simplex noise only,
7381
+ * and only for 3D and 4D noise where there are more than 2 simplices.
7382
+ * (3D simplex noise has 6 cases to sort out, 4D simplex noise has 24 cases.)
7383
+ */
7384
+ function initSimplexTexture(context)
7385
+ {
7386
+
7387
+ if (!simplex_buf) simplex_buf = new Uint8Array(simplex4);
7388
+ var tex = new Jax.Texture({min_filter:GL_NEAREST,mag_filter:GL_NEAREST, width:64, height:1});
7389
+ tex.bind(context, function() {
7390
+ context.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, simplex_buf);
7391
+ });
7392
+ return tex;
7393
+ }
7394
+
7395
+ /*
7396
+ * initGradTexture(context) - create and load a 2D texture
7397
+ * for a 4D gradient lookup table. This is used for 4D noise only.
7398
+ */
7399
+ function initGradTexture(context)
7400
+ {
7401
+ var tex = new Jax.Texture({min_filter: GL_NEAREST, mag_filter: GL_NEAREST, width:256, height:256});
7402
+
7403
+ if (!grad_buf) {
7404
+ var pixels = new Array(256*256*4);
7405
+ var i,j;
7406
+
7407
+ for(i = 0; i<256; i++)
7408
+ for(j = 0; j<256; j++) {
7409
+ var offset = (i*256+j)*4;
7410
+ var value = perm[(j+perm[i]) & 0xFF];
7411
+ var g = (value & 0x1F) * 4;
7412
+ pixels[offset] = grad4[g+0] * 64 + 64; // Gradient x
7413
+ pixels[offset+1] = grad4[g+1] * 64 + 64; // Gradient y
7414
+ pixels[offset+2] = grad4[g+2] * 64 + 64; // Gradient z
7415
+ pixels[offset+3] = grad4[g+3] * 64 + 64; // Gradient z
7416
+ }
7417
+
7418
+ grad_buf = new Uint8Array(pixels);
7419
+ }
7420
+
7421
+ tex.bind(context, function() {
7422
+ context.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, grad_buf);
7423
+ });
7424
+ return tex;
7425
+ }
7426
+
7427
+ return Jax.Class.create({
7428
+ initialize: function(context) {
7429
+ this.perm = initPermTexture(context);
7430
+
7431
+ this.simplex = initSimplexTexture(context);
7432
+
7433
+ this.grad = initGradTexture(context);
7434
+ }
7435
+ });
7436
+ })();
7253
7437
 
7254
7438
  Jax.shaders = {};
7255
7439
 
@@ -14,7 +14,7 @@ exceeds the capabilities of the graphics processor.
14
14
  Processors supported by your application:
15
15
 
16
16
  <%supported_shaders.each do |shader| -%>
17
- - <%=shader.name.ljust(20)%> : <%=shader.description.gsub(/\n/, "\n"+" "*25)%>
17
+ - <%=shader.name.ljust(20)%> : <%=shader.description.strip.gsub(/\n/, "\n"+" "*25)%>
18
18
  <%end -%>
19
19
 
20
20
  You can specify a shader more than once. For instance, you can create a
@@ -6,7 +6,7 @@ shared uniform mat4 mvMatrix, pMatrix;
6
6
 
7
7
  shared varying vec2 vTexCoords;
8
8
  shared varying vec3 vNormals;
9
- shared varying vec4 vColors;
9
+ shared varying vec4 vColor;
10
10
 
11
11
  // If a variable isn't shared, it will be defined specifically for this shader.
12
12
  // If this shader is used twice in one materials, unshared variables will be
@@ -5,6 +5,10 @@ describe("Shader '<%=file_name%>'", function() {
5
5
  context = new Jax.Context('webgl-canvas');
6
6
  mesh = new Jax.Mesh.Quad();
7
7
  });
8
+
9
+ /* dispose the context so it doesn't continue using
10
+ resources after the tests have completed */
11
+ afterEach(function() { context.dispose(); });
8
12
 
9
13
  describe("stand-alone", function() {
10
14
  beforeEach(function() { mesh.material = new Jax.Material.<%=class_name%>(); });
@@ -18,6 +18,10 @@ class Jax::Packager::SprocketsTemplate < Sprockets::SourceFile
18
18
  template << "//= require \"#{relative_path}\""
19
19
  end
20
20
  end
21
+ template.concat [
22
+ "if (Jax.doVersionCheck) Jax.doVersionCheck('#{Jax::Version::STRING}');",
23
+ "else alert('Your Jax gem version is newer than your Jax JavaScript library!\n\nRun `rake jax:update` to fix this.');"
24
+ ]
21
25
  template
22
26
  end
23
27
  end
@@ -5,7 +5,7 @@ class Jax::ResourceCompiler
5
5
  if destination_file.kind_of?(IO)
6
6
  save_resources destination_file, resources
7
7
  else
8
- mkdir_p File.dirname(destination_file)
8
+ mkdir_p File.dirname(destination_file) unless File.exist?(File.dirname(destination_file))
9
9
  File.open destination_file, "w" do |f|
10
10
  save_resources f, resources
11
11
  end
data/lib/jax/shader.rb CHANGED
@@ -118,14 +118,26 @@ class Jax::Shader
118
118
  # look for Sprockets-style require directives
119
119
  str.gsub! /\/\/=\s*require\s*['"]([^'"]*)['"]/m do |sub|
120
120
  filename = $~[1]
121
- macro_name = "dependency_#{filename}".underscore.gsub(/[^a-zA-Z0-9_]/, '_')
122
- <<-end_code
123
- #ifndef #{macro_name}
124
- #define #{macro_name}
121
+ found = false
122
+ paths = Jax.shader_load_paths
123
+ result = nil
124
+ for path in paths
125
+ if File.file?(real = File.join(path, "#{filename}.ejs"))
126
+ found = true
127
+ macro_name = "dependency_#{filename}".underscore.gsub(/[^a-zA-Z0-9_]/, '_')
128
+ result = <<-end_code
129
+ #ifndef #{macro_name}
130
+ #define #{macro_name}
125
131
 
126
- #{File.read(File.join(path, "#{filename}.ejs"))}
127
- #endif
128
- end_code
132
+ #{File.read(real)}
133
+ #endif
134
+ end_code
135
+ break
136
+ end
137
+ end
138
+
139
+ raise "Required file '#{filename}.ejs' not found in load paths #{paths.inspect} for shader '#{name}'!" if !found
140
+ result
129
141
  end
130
142
  end
131
143