jax 0.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.gitmodules +3 -0
- data/.rvmrc +7 -0
- data/Gemfile +4 -0
- data/README.rdoc +32 -0
- data/Rakefile +144 -0
- data/bin/jax +11 -0
- data/builtin/shaders/basic/common.ejs +11 -0
- data/builtin/shaders/basic/fragment.ejs +5 -0
- data/builtin/shaders/basic/vertex.ejs +13 -0
- data/builtin/shaders/depthmap/common.ejs +1 -0
- data/builtin/shaders/depthmap/fragment.ejs +5 -0
- data/builtin/shaders/depthmap/vertex.ejs +7 -0
- data/builtin/shaders/fog/common.ejs +7 -0
- data/builtin/shaders/fog/fragment.ejs +23 -0
- data/builtin/shaders/fog/manifest.yml +12 -0
- data/builtin/shaders/fog/material.js +34 -0
- data/builtin/shaders/fog/vertex.ejs +10 -0
- data/builtin/shaders/functions/depth_map.ejs +24 -0
- data/builtin/shaders/functions/lights.ejs +155 -0
- data/builtin/shaders/lighting/common.ejs +5 -0
- data/builtin/shaders/lighting/fragment.ejs +34 -0
- data/builtin/shaders/lighting/manifest.yml +4 -0
- data/builtin/shaders/lighting/material.js +26 -0
- data/builtin/shaders/lighting/vertex.ejs +7 -0
- data/builtin/shaders/normal_map/common.ejs +12 -0
- data/builtin/shaders/normal_map/fragment.ejs +26 -0
- data/builtin/shaders/normal_map/manifest.yml +17 -0
- data/builtin/shaders/normal_map/material.js +16 -0
- data/builtin/shaders/normal_map/vertex.ejs +57 -0
- data/builtin/shaders/paraboloid-depthmap/common.ejs +6 -0
- data/builtin/shaders/paraboloid-depthmap/fragment.ejs +8 -0
- data/builtin/shaders/paraboloid-depthmap/material.js +15 -0
- data/builtin/shaders/paraboloid-depthmap/vertex.ejs +26 -0
- data/builtin/shaders/shadow_map/common.ejs +14 -0
- data/builtin/shaders/shadow_map/fragment.ejs +66 -0
- data/builtin/shaders/shadow_map/manifest.yml +1 -0
- data/builtin/shaders/shadow_map/material.js +26 -0
- data/builtin/shaders/shadow_map/vertex.ejs +46 -0
- data/builtin/shaders/texture/common.ejs +4 -0
- data/builtin/shaders/texture/fragment.ejs +11 -0
- data/builtin/shaders/texture/manifest.yml +17 -0
- data/builtin/shaders/texture/material.js +18 -0
- data/builtin/shaders/texture/vertex.ejs +9 -0
- data/guides/assets/images/book_icon.gif +0 -0
- data/guides/assets/images/bullet.gif +0 -0
- data/guides/assets/images/chapters_icon.gif +0 -0
- data/guides/assets/images/check_bullet.gif +0 -0
- data/guides/assets/images/credits_pic_blank.gif +0 -0
- data/guides/assets/images/edge_badge.png +0 -0
- data/guides/assets/images/feature_tile.gif +0 -0
- data/guides/assets/images/footer_tile.gif +0 -0
- data/guides/assets/images/getting_started/clean_passing_jasmine_suite.png +0 -0
- data/guides/assets/images/getting_started/rock.png +0 -0
- data/guides/assets/images/getting_started/rock_normal.png +0 -0
- data/guides/assets/images/grey_bullet.gif +0 -0
- data/guides/assets/images/header_backdrop.png +0 -0
- data/guides/assets/images/header_tile.gif +0 -0
- data/guides/assets/images/icons/README +5 -0
- data/guides/assets/images/icons/callouts/1.png +0 -0
- data/guides/assets/images/icons/callouts/10.png +0 -0
- data/guides/assets/images/icons/callouts/11.png +0 -0
- data/guides/assets/images/icons/callouts/12.png +0 -0
- data/guides/assets/images/icons/callouts/13.png +0 -0
- data/guides/assets/images/icons/callouts/14.png +0 -0
- data/guides/assets/images/icons/callouts/15.png +0 -0
- data/guides/assets/images/icons/callouts/2.png +0 -0
- data/guides/assets/images/icons/callouts/3.png +0 -0
- data/guides/assets/images/icons/callouts/4.png +0 -0
- data/guides/assets/images/icons/callouts/5.png +0 -0
- data/guides/assets/images/icons/callouts/6.png +0 -0
- data/guides/assets/images/icons/callouts/7.png +0 -0
- data/guides/assets/images/icons/callouts/8.png +0 -0
- data/guides/assets/images/icons/callouts/9.png +0 -0
- data/guides/assets/images/icons/caution.png +0 -0
- data/guides/assets/images/icons/example.png +0 -0
- data/guides/assets/images/icons/home.png +0 -0
- data/guides/assets/images/icons/important.png +0 -0
- data/guides/assets/images/icons/next.png +0 -0
- data/guides/assets/images/icons/note.png +0 -0
- data/guides/assets/images/icons/prev.png +0 -0
- data/guides/assets/images/icons/tip.png +0 -0
- data/guides/assets/images/icons/up.png +0 -0
- data/guides/assets/images/icons/warning.png +0 -0
- data/guides/assets/images/nav_arrow.gif +0 -0
- data/guides/assets/images/tab_grey.gif +0 -0
- data/guides/assets/images/tab_info.gif +0 -0
- data/guides/assets/images/tab_note.gif +0 -0
- data/guides/assets/images/tab_red.gif +0 -0
- data/guides/assets/images/tab_yellow.gif +0 -0
- data/guides/assets/images/tab_yellow.png +0 -0
- data/guides/assets/javascripts/guides.js +7 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
- data/guides/assets/javascripts/syntaxhighlighter/shCore.js +17 -0
- data/guides/assets/stylesheets/fixes.css +16 -0
- data/guides/assets/stylesheets/main.css +445 -0
- data/guides/assets/stylesheets/print.css +52 -0
- data/guides/assets/stylesheets/reset.css +43 -0
- data/guides/assets/stylesheets/style.css +13 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCore.css +226 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeJaxGuides.css +116 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
- data/guides/jax_guides.rb +41 -0
- data/guides/jax_guides/common.rb +7 -0
- data/guides/jax_guides/generator.rb +287 -0
- data/guides/jax_guides/helpers.rb +29 -0
- data/guides/jax_guides/indexer.rb +69 -0
- data/guides/jax_guides/levenshtein.rb +31 -0
- data/guides/jax_guides/textile_extensions.rb +61 -0
- data/guides/source/getting_started.textile +1171 -0
- data/guides/source/index.html.erb +50 -0
- data/guides/source/layout.html.erb +158 -0
- data/guides/source/lighting.textile +5 -0
- data/guides/source/materials.textile +5 -0
- data/guides/source/shaders.textile +5 -0
- data/guides/source/testing.textile +5 -0
- data/guides/w3c_validator.rb +91 -0
- data/jax.gems +1 -0
- data/jax.gemspec +40 -0
- data/lib/jax.rb +28 -0
- data/lib/jax/application.rb +92 -0
- data/lib/jax/application/configuration.rb +27 -0
- data/lib/jax/generators/app.rb +17 -0
- data/lib/jax/generators/app/app_generator.rb +78 -0
- data/lib/jax/generators/app/templates/Gemfile.tt +3 -0
- data/lib/jax/generators/app/templates/Rakefile +6 -0
- data/lib/jax/generators/app/templates/app/controllers/application_controller.js.tt +5 -0
- data/lib/jax/generators/app/templates/app/helpers/application_helper.js.tt +3 -0
- data/lib/jax/generators/app/templates/app/models/.empty_directory +0 -0
- data/lib/jax/generators/app/templates/app/resources/.empty_directory +0 -0
- data/lib/jax/generators/app/templates/app/views/.empty_directory +0 -0
- data/lib/jax/generators/app/templates/config/application.rb.tt +6 -0
- data/lib/jax/generators/app/templates/config/boot.rb +13 -0
- data/lib/jax/generators/app/templates/config/routes.rb.tt +5 -0
- data/lib/jax/generators/app/templates/public/javascripts/jax.js +7561 -0
- data/lib/jax/generators/app/templates/public/webgl_not_supported.html +26 -0
- data/lib/jax/generators/app/templates/script/jax +7 -0
- data/lib/jax/generators/app/templates/spec/javascripts/controllers/application_controller_spec.js +11 -0
- data/lib/jax/generators/app/templates/spec/javascripts/helpers/application_helper_spec.js +12 -0
- data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine.yml +90 -0
- data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine_config.rb +23 -0
- data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/lib/jax/generators/app/templates/spec/javascripts/support/spec_helpers/jax_spec_helper.js +216 -0
- data/lib/jax/generators/app/templates/spec/javascripts/support/spec_layout.html.erb +63 -0
- data/lib/jax/generators/commands.rb +81 -0
- data/lib/jax/generators/controller/USAGE +9 -0
- data/lib/jax/generators/controller/controller_generator.rb +59 -0
- data/lib/jax/generators/controller/templates/controller_source.js.tt +16 -0
- data/lib/jax/generators/controller/templates/controller_test.js.tt +11 -0
- data/lib/jax/generators/controller/templates/helper.js.tt +3 -0
- data/lib/jax/generators/controller/templates/helper_test.js.tt +12 -0
- data/lib/jax/generators/controller/templates/view.js.tt +4 -0
- data/lib/jax/generators/light_source/USAGE +14 -0
- data/lib/jax/generators/light_source/light_source_generator.rb +47 -0
- data/lib/jax/generators/light_source/templates/light.yml.tt +39 -0
- data/lib/jax/generators/material/USAGE +29 -0
- data/lib/jax/generators/material/material_generator.rb +81 -0
- data/lib/jax/generators/material/templates/append.yml.tt +7 -0
- data/lib/jax/generators/material/templates/material.yml.tt +33 -0
- data/lib/jax/generators/model/USAGE +5 -0
- data/lib/jax/generators/model/model_generator.rb +42 -0
- data/lib/jax/generators/model/templates/model.js.tt +11 -0
- data/lib/jax/generators/model/templates/test.js.tt +11 -0
- data/lib/jax/generators/script_jax_loader.rb +32 -0
- data/lib/jax/monkeypatch/jasmine.rb +3 -0
- data/lib/jax/monkeypatch/jasmine/config.rb +21 -0
- data/lib/jax/monkeypatch/jasmine/server.rb +50 -0
- data/lib/jax/packager.rb +58 -0
- data/lib/jax/packager/sprockets_template.rb +49 -0
- data/lib/jax/resource_compiler.rb +50 -0
- data/lib/jax/routes.rb +61 -0
- data/lib/jax/shader.rb +158 -0
- data/lib/jax/tasks/rake.rb +34 -0
- data/lib/jax/version.rb +12 -0
- data/public/images/brickwall.jpg +0 -0
- data/public/images/jacks.jpg +0 -0
- data/public/images/normal_map.jpg +0 -0
- data/public/images/rock.png +0 -0
- data/public/images/rockNormal.png +0 -0
- data/public/images/rss.png +0 -0
- data/public/webgl_not_supported.html +26 -0
- data/spec/example_app/Gemfile +1 -0
- data/spec/example_app/Rakefile +15 -0
- data/spec/example_app/app/controllers/application_controller.js +5 -0
- data/spec/example_app/app/controllers/courthouse_controller.js +24 -0
- data/spec/example_app/app/controllers/lighting_controller.js +69 -0
- data/spec/example_app/app/controllers/shadows_controller.js +130 -0
- data/spec/example_app/app/controllers/textures_controller.js +52 -0
- data/spec/example_app/app/helpers/application_helper.js +3 -0
- data/spec/example_app/app/helpers/textures_helper.js +3 -0
- data/spec/example_app/app/models/character.js +23 -0
- data/spec/example_app/app/models/door.js +10 -0
- data/spec/example_app/app/models/scene.js +19 -0
- data/spec/example_app/app/resources/characters/judge.yml +3 -0
- data/spec/example_app/app/resources/doors/courthouse_door.yml +5 -0
- data/spec/example_app/app/resources/light_sources/directional_light.yml +13 -0
- data/spec/example_app/app/resources/light_sources/point_light.yml +31 -0
- data/spec/example_app/app/resources/light_sources/spot_light.yml +15 -0
- data/spec/example_app/app/resources/light_sources/sun.yml +7 -0
- data/spec/example_app/app/resources/light_sources/textures_point.yml +34 -0
- data/spec/example_app/app/resources/materials/bricks.yml +36 -0
- data/spec/example_app/app/resources/materials/lighting_with_shadows.yml +27 -0
- data/spec/example_app/app/resources/scenes/courthouse.yml +4 -0
- data/spec/example_app/app/views/courthouse/index.js +4 -0
- data/spec/example_app/app/views/lighting/index.js +4 -0
- data/spec/example_app/app/views/shadows/index.js +6 -0
- data/spec/example_app/app/views/textures/index.js +4 -0
- data/spec/example_app/config/application.rb +6 -0
- data/spec/example_app/config/boot.rb +13 -0
- data/spec/example_app/config/routes.rb +6 -0
- data/spec/example_app/public/images/185__normalmap.png +0 -0
- data/spec/example_app/public/images/face_norm.jpg +0 -0
- data/spec/example_app/public/images/rock.png +0 -0
- data/spec/example_app/public/images/rockNormal.png +0 -0
- data/spec/example_app/public/images/rss.png +0 -0
- data/spec/example_app/public/webgl_not_supported.html +26 -0
- data/spec/example_app/script/jax +7 -0
- data/spec/example_app/spec/javascripts/controllers/textures_controller_spec.js +11 -0
- data/spec/example_app/spec/javascripts/helpers/application_helper_spec.js +12 -0
- data/spec/example_app/spec/javascripts/resources/directional_light_spec.js +16 -0
- data/spec/example_app/spec/javascripts/resources/point_light_spec.js +17 -0
- data/spec/example_app/spec/javascripts/resources/spot_light_spec.js +18 -0
- data/spec/example_app/spec/javascripts/support/jasmine.yml +89 -0
- data/spec/example_app/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/example_app/spec/javascripts/support/spec_helpers/jax_spec_helper.js +93 -0
- data/spec/example_app/spec/javascripts/support/spec_layout.html.erb +84 -0
- data/spec/generators/app_generator_spec.rb +46 -0
- data/spec/generators/controller_generator_spec.rb +68 -0
- data/spec/generators/light_generator_spec.rb +51 -0
- data/spec/generators/material_generator_spec.rb +35 -0
- data/spec/generators/model_generator_spec.rb +43 -0
- data/spec/javascripts/Player.js +58 -0
- data/spec/javascripts/helpers/SpecHelper.js +216 -0
- data/spec/javascripts/jax/builtin/materials/core_materials_spec.js +41 -0
- data/spec/javascripts/jax/builtin/materials/dual_paraboloid_spec.js +37 -0
- data/spec/javascripts/jax/builtin/materials/fog_spec.js +19 -0
- data/spec/javascripts/jax/builtin/materials/lighting_spec.js +19 -0
- data/spec/javascripts/jax/builtin/materials/normal_map_spec.js +19 -0
- data/spec/javascripts/jax/builtin/materials/shadow_map_spec.js +19 -0
- data/spec/javascripts/jax/builtin/materials/texture_spec.js +19 -0
- data/spec/javascripts/jax/builtin/meshes/cube_spec.js +10 -0
- data/spec/javascripts/jax/builtin/meshes/plane_spec.js +8 -0
- data/spec/javascripts/jax/builtin/meshes/quad_spec.js +8 -0
- data/spec/javascripts/jax/builtin/meshes/sphere_spec.js +8 -0
- data/spec/javascripts/jax/builtin/meshes/teapot_spec.js +8 -0
- data/spec/javascripts/jax/builtin/meshes/torus_spec.js +8 -0
- data/spec/javascripts/jax/compatibility_spec.js +50 -0
- data/spec/javascripts/jax/context_spec.js +82 -0
- data/spec/javascripts/jax/controller_spec.js +145 -0
- data/spec/javascripts/jax/core/delegation_spec.js +48 -0
- data/spec/javascripts/jax/core/events_spec.js +17 -0
- data/spec/javascripts/jax/core/matrix_stack_spec.js +28 -0
- data/spec/javascripts/jax/core/utils_spec.js +256 -0
- data/spec/javascripts/jax/helper_spec.js +33 -0
- data/spec/javascripts/jax/model_spec.js +87 -0
- data/spec/javascripts/jax/optimizations/material_limitations_spec.js +87 -0
- data/spec/javascripts/jax/optimizations/shaders/basic_spec.js +68 -0
- data/spec/javascripts/jax/prototype/extensions_spec.js +34 -0
- data/spec/javascripts/jax/route_set_spec.js +67 -0
- data/spec/javascripts/jax/view_manager_spec.js +17 -0
- data/spec/javascripts/jax/webgl/camera_spec.js +159 -0
- data/spec/javascripts/jax/webgl/framebuffer_spec.js +46 -0
- data/spec/javascripts/jax/webgl/lighting_spec.js +61 -0
- data/spec/javascripts/jax/webgl/material_spec.js +118 -0
- data/spec/javascripts/jax/webgl/mesh_spec.js +86 -0
- data/spec/javascripts/jax/webgl/shader/manifest_spec.js +60 -0
- data/spec/javascripts/jax/webgl/shader_chain_spec.js +192 -0
- data/spec/javascripts/jax/webgl/shader_spec.js +276 -0
- data/spec/javascripts/jax/webgl/tangent_space_spec.js +142 -0
- data/spec/javascripts/jax/webgl/texture_spec.js +162 -0
- data/spec/javascripts/jax/webgl_spec.js +5 -0
- data/spec/javascripts/jax/world_spec.js +88 -0
- data/spec/javascripts/jax_spec.js +27 -0
- data/spec/javascripts/support/jasmine.yml +85 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/lib/jax/routes_spec.rb +24 -0
- data/spec/lib/jax/shader_spec.rb +57 -0
- data/spec/lib/jax/tasks/jax_rake_spec.rb +79 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/file_exist_matcher.rb +23 -0
- data/spec/support/spec_shell.rb +97 -0
- data/src/jax.js +84 -0
- data/src/jax/anim_frame.js +47 -0
- data/src/jax/builtin/all.js +7 -0
- data/src/jax/builtin/meshes/cube.js +62 -0
- data/src/jax/builtin/meshes/plane.js +36 -0
- data/src/jax/builtin/meshes/quad.js +80 -0
- data/src/jax/builtin/meshes/sphere.js +46 -0
- data/src/jax/builtin/meshes/teapot.js +38 -0
- data/src/jax/builtin/meshes/torus.js +46 -0
- data/src/jax/compatibility.js +140 -0
- data/src/jax/context.js +253 -0
- data/src/jax/controller.js +157 -0
- data/src/jax/core.js +39 -0
- data/src/jax/core/math.js +40 -0
- data/src/jax/core/matrix_stack.js +306 -0
- data/src/jax/core/util.js +226 -0
- data/src/jax/events.js +179 -0
- data/src/jax/geometry.js +3 -0
- data/src/jax/geometry/plane.js +59 -0
- data/src/jax/helper.js +8 -0
- data/src/jax/model.js +163 -0
- data/src/jax/prototype/class.js +78 -0
- data/src/jax/prototype/core.js +112 -0
- data/src/jax/prototype/extensions.js +124 -0
- data/src/jax/route_set.js +125 -0
- data/src/jax/vendor/ejs.js +4 -0
- data/src/jax/vendor/glMatrix.js +3 -0
- data/src/jax/view.js +37 -0
- data/src/jax/view_manager.js +46 -0
- data/src/jax/webgl.js +98 -0
- data/src/jax/webgl/camera.js +526 -0
- data/src/jax/webgl/core.js +6 -0
- data/src/jax/webgl/core/buffer.js +161 -0
- data/src/jax/webgl/core/edge.js +6 -0
- data/src/jax/webgl/core/events.js +25 -0
- data/src/jax/webgl/core/face.js +8 -0
- data/src/jax/webgl/core/framebuffer.js +206 -0
- data/src/jax/webgl/material.js +375 -0
- data/src/jax/webgl/mesh.js +412 -0
- data/src/jax/webgl/scene.js +11 -0
- data/src/jax/webgl/scene/frustum.js +260 -0
- data/src/jax/webgl/scene/light_manager.js +112 -0
- data/src/jax/webgl/scene/light_source.js +248 -0
- data/src/jax/webgl/shader.js +282 -0
- data/src/jax/webgl/shader/delegator.js +13 -0
- data/src/jax/webgl/shader/delegator/attribute.js +53 -0
- data/src/jax/webgl/shader/delegator/uniform.js +71 -0
- data/src/jax/webgl/shader/manifest.js +64 -0
- data/src/jax/webgl/shader/program.js +140 -0
- data/src/jax/webgl/shader_chain.js +256 -0
- data/src/jax/webgl/texture.js +312 -0
- data/src/jax/webgl/world.js +119 -0
- data/vendor/ejs/.svn/all-wcprops +17 -0
- data/vendor/ejs/.svn/entries +114 -0
- data/vendor/ejs/.svn/text-base/Eratta.txt.svn-base +3 -0
- data/vendor/ejs/.svn/text-base/license.txt.svn-base +21 -0
- data/vendor/ejs/Eratta.txt +3 -0
- data/vendor/ejs/example/.svn/all-wcprops +29 -0
- data/vendor/ejs/example/.svn/entries +164 -0
- data/vendor/ejs/example/.svn/prop-base/ejs.gif.svn-base +5 -0
- data/vendor/ejs/example/.svn/text-base/demo.html.svn-base +54 -0
- data/vendor/ejs/example/.svn/text-base/ejs.gif.svn-base +0 -0
- data/vendor/ejs/example/.svn/text-base/example.css.svn-base +31 -0
- data/vendor/ejs/example/.svn/text-base/example.js.svn-base +88 -0
- data/vendor/ejs/example/demo.html +54 -0
- data/vendor/ejs/example/ejs.gif +0 -0
- data/vendor/ejs/example/example.css +31 -0
- data/vendor/ejs/example/example.js +88 -0
- data/vendor/ejs/lib/.svn/all-wcprops +11 -0
- data/vendor/ejs/lib/.svn/entries +62 -0
- data/vendor/ejs/lib/.svn/text-base/ejs_fulljslint.js.svn-base +3774 -0
- data/vendor/ejs/lib/ejs_fulljslint.js +3774 -0
- data/vendor/ejs/license.txt +21 -0
- data/vendor/ejs/script/.svn/all-wcprops +17 -0
- data/vendor/ejs/script/.svn/entries +96 -0
- data/vendor/ejs/script/.svn/prop-base/yuicompressor-2.2.4.jar.svn-base +5 -0
- data/vendor/ejs/script/.svn/text-base/production.bat.svn-base +4 -0
- data/vendor/ejs/script/.svn/text-base/yuicompressor-2.2.4.jar.svn-base +0 -0
- data/vendor/ejs/script/production.bat +4 -0
- data/vendor/ejs/script/yuicompressor-2.2.4.jar +0 -0
- data/vendor/ejs/src/.svn/all-wcprops +17 -0
- data/vendor/ejs/src/.svn/entries +96 -0
- data/vendor/ejs/src/.svn/text-base/ejs.js.svn-base +505 -0
- data/vendor/ejs/src/.svn/text-base/view.js.svn-base +200 -0
- data/vendor/ejs/src/ejs.js +505 -0
- data/vendor/ejs/src/view.js +200 -0
- data/vendor/ejs/test/.svn/all-wcprops +23 -0
- data/vendor/ejs/test/.svn/entries +139 -0
- data/vendor/ejs/test/.svn/text-base/index.html.svn-base +18 -0
- data/vendor/ejs/test/.svn/text-base/setup_test.html.svn-base +44 -0
- data/vendor/ejs/test/.svn/text-base/sidebar.html.svn-base +28 -0
- data/vendor/ejs/test/included/.svn/all-wcprops +23 -0
- data/vendor/ejs/test/included/.svn/entries +130 -0
- data/vendor/ejs/test/included/.svn/text-base/prototype.js.svn-base +4184 -0
- data/vendor/ejs/test/included/.svn/text-base/test.css.svn-base +44 -0
- data/vendor/ejs/test/included/.svn/text-base/unittest.js.svn-base +564 -0
- data/vendor/ejs/test/included/prototype.js +4184 -0
- data/vendor/ejs/test/included/test.css +44 -0
- data/vendor/ejs/test/included/unittest.js +564 -0
- data/vendor/ejs/test/index.html +18 -0
- data/vendor/ejs/test/setup_test.html +44 -0
- data/vendor/ejs/test/sidebar.html +28 -0
- data/vendor/ejs/test/templates/.svn/all-wcprops +11 -0
- data/vendor/ejs/test/templates/.svn/entries +62 -0
- data/vendor/ejs/test/templates/.svn/text-base/test.ejs.svn-base +3 -0
- data/vendor/ejs/test/templates/test.ejs +3 -0
- data/vendor/ejs/test/tests/.svn/all-wcprops +23 -0
- data/vendor/ejs/test/tests/.svn/entries +130 -0
- data/vendor/ejs/test/tests/.svn/text-base/rendering.js.svn-base +94 -0
- data/vendor/ejs/test/tests/.svn/text-base/templating.js.svn-base +43 -0
- data/vendor/ejs/test/tests/.svn/text-base/views.js.svn-base +100 -0
- data/vendor/ejs/test/tests/rendering.js +94 -0
- data/vendor/ejs/test/tests/templating.js +43 -0
- data/vendor/ejs/test/tests/views.js +100 -0
- data/vendor/glmatrix/benchmark/js/CanvasMatrix.js +722 -0
- data/vendor/glmatrix/benchmark/js/EWGL_math.js +742 -0
- data/vendor/glmatrix/benchmark/js/mjs.js +1230 -0
- data/vendor/glmatrix/benchmark/matrix_benchmark.html +419 -0
- data/vendor/glmatrix/glMatrix-min.js +32 -0
- data/vendor/glmatrix/glMatrix.js +1815 -0
- data/vendor/glmatrix/unit tests/glMatrix-test.js +74 -0
- data/vendor/glmatrix/unit tests/qunit.css +119 -0
- data/vendor/glmatrix/unit tests/qunit.js +1069 -0
- data/vendor/glmatrix/unit tests/test_glMatrix.html +21 -0
- data/vendor/yuicompressor-2.4.2.jar +0 -0
- metadata +748 -0
@@ -0,0 +1,112 @@
|
|
1
|
+
//= require "light_source"
|
2
|
+
|
3
|
+
Jax.Scene.LightManager = (function() {
|
4
|
+
return Jax.Class.create({
|
5
|
+
initialize: function(context) {
|
6
|
+
this.context = context;
|
7
|
+
this._lights = [];
|
8
|
+
},
|
9
|
+
|
10
|
+
add: function(light) {
|
11
|
+
if (this._lights.length == Jax.max_lights)
|
12
|
+
throw new Error("Maximum number of light sources in a scene has been exceeded! Try removing some first.");
|
13
|
+
this._lights.push(light);
|
14
|
+
},
|
15
|
+
|
16
|
+
enable: function() { this.enabled = true; },
|
17
|
+
|
18
|
+
disable: function() { this.enabled = false; },
|
19
|
+
|
20
|
+
isEnabled: function() {
|
21
|
+
if (arguments.length == 1) {
|
22
|
+
if (this._lights.length > arguments[0])
|
23
|
+
return this._lights[arguments[0]].isEnabled();
|
24
|
+
return false;
|
25
|
+
}
|
26
|
+
|
27
|
+
if (this.enabled != undefined)
|
28
|
+
return this.enabled;
|
29
|
+
return this._lights.length > 0;
|
30
|
+
},
|
31
|
+
|
32
|
+
count: function() { return this._lights.length; },
|
33
|
+
|
34
|
+
remove: function(index) {
|
35
|
+
var result = this._lights.splice(index, 1);
|
36
|
+
if (this._lights.length == 0) delete this.enabled;
|
37
|
+
return result;
|
38
|
+
},
|
39
|
+
|
40
|
+
illuminate: function(context, objects, options) {
|
41
|
+
for (var i = 0; i < this._lights.length; i++) {
|
42
|
+
this._current_light = i;
|
43
|
+
for (var j = 0; j < objects.length; j++) {
|
44
|
+
/* TODO optimization: see if objects[j] is even affected by this._lights[i] (based on attenuation) */
|
45
|
+
if (objects[j].isLit())
|
46
|
+
objects[j].render(context, options);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
delete this._current_light;
|
50
|
+
},
|
51
|
+
|
52
|
+
ambient: function(context, objects, options) {
|
53
|
+
for (var i = 0; i < this._lights.length; i++) {
|
54
|
+
this._current_light = i;
|
55
|
+
for (var j = 0; j < objects.length; j++) {
|
56
|
+
/* TODO optimization: see if objects[j] is even affected by this._lights[i] (based on attenuation) */
|
57
|
+
if (objects[j].isLit())
|
58
|
+
objects[j].render(context, options);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
delete this._current_light;
|
62
|
+
},
|
63
|
+
|
64
|
+
updateShadowMaps: function(context, objects) {
|
65
|
+
var boundingRadius = null;
|
66
|
+
var i, j;
|
67
|
+
for (i = 0; i < objects.length; i++) {
|
68
|
+
j = vec3.length(objects[i].camera.getPosition()) + objects[i].getBoundingSphereRadius();
|
69
|
+
if (boundingRadius == null || boundingRadius < j)
|
70
|
+
boundingRadius = j;
|
71
|
+
}
|
72
|
+
boundingRadius = boundingRadius || 0;
|
73
|
+
|
74
|
+
// context.glPolygonOffset(1.1, 4.0);
|
75
|
+
// context.glPolygonOffset(2,2);
|
76
|
+
// context.glEnable(GL_POLYGON_OFFSET_FILL);
|
77
|
+
for (i = 0; i < this._lights.length; i++)
|
78
|
+
this._lights[i].updateShadowMap(context, boundingRadius, objects);
|
79
|
+
// context.glDisable(GL_POLYGON_OFFSET_FILL);
|
80
|
+
// context.glPolygonOffset(0.0, 0.0);
|
81
|
+
},
|
82
|
+
|
83
|
+
getDirection: function(index) { return this.getLight(index).getDirection(); },
|
84
|
+
|
85
|
+
getPosition: function(index) { return this.getLight(index).getPosition(); },
|
86
|
+
|
87
|
+
getLight: function(index) {
|
88
|
+
if (index == undefined)
|
89
|
+
if (this._current_light != undefined) return this._lights[this._current_light];
|
90
|
+
else return (this.default_light = this.default_light || new Jax.Scene.LightSource());
|
91
|
+
return this._lights[index];
|
92
|
+
},
|
93
|
+
|
94
|
+
getType: function(index) { return this.getLight(index).getType(); },
|
95
|
+
|
96
|
+
getDiffuseColor: function(index) { return this.getLight(index).getDiffuseColor(); },
|
97
|
+
|
98
|
+
getSpecularColor: function(index) { return this.getLight(index).getSpecularColor(); },
|
99
|
+
|
100
|
+
getAmbientColor: function(index) { return this.getLight(index).getAmbientColor(); },
|
101
|
+
|
102
|
+
getConstantAttenuation: function(index) { return this.getLight(index).getConstantAttenuation(); },
|
103
|
+
|
104
|
+
getLinearAttenuation: function(index) { return this.getLight(index).getLinearAttenuation(); },
|
105
|
+
|
106
|
+
getQuadraticAttenuation: function(index) { return this.getLight(index).getQuadraticAttenuation(); },
|
107
|
+
|
108
|
+
getSpotCosCutoff: function(index) { return this.getLight(index).getSpotCosCutoff(); },
|
109
|
+
|
110
|
+
getSpotExponent: function(index) { return this.getLight(index).getSpotExponent(); }
|
111
|
+
});
|
112
|
+
})();
|
@@ -0,0 +1,248 @@
|
|
1
|
+
Jax.POINT_LIGHT = 1;
|
2
|
+
Jax.SPOT_LIGHT = 2;
|
3
|
+
Jax.DIRECTIONAL_LIGHT = 3;
|
4
|
+
|
5
|
+
Jax.Scene.LightSource = (function() {
|
6
|
+
function setupProjection(self) {
|
7
|
+
if (self.camera.projection) return;
|
8
|
+
|
9
|
+
switch(self.type) {
|
10
|
+
case Jax.DIRECTIONAL_LIGHT:
|
11
|
+
self.camera.ortho({left:-1,right:1, top:1,bottom:-1, near:-1,far:1 });
|
12
|
+
self.camera.setPosition(0,0,0);
|
13
|
+
break;
|
14
|
+
case Jax.POINT_LIGHT:
|
15
|
+
self.camera.perspective({fov:45,near:0.01,far:500,width:2048,height:2048});
|
16
|
+
break;
|
17
|
+
case Jax.SPOT_LIGHT:
|
18
|
+
self.camera.perspective({near:0.1,far:500,fov:60,width:2048,height:2048});
|
19
|
+
break;
|
20
|
+
default:
|
21
|
+
throw new Error("Unexpected light type: "+self.type);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
return Jax.Model.create({
|
26
|
+
initialize: function($super, data) {
|
27
|
+
data = Jax.Util.normalizeOptions(data, {
|
28
|
+
enabled: true,
|
29
|
+
type: Jax.POINT_LIGHT,
|
30
|
+
color: {
|
31
|
+
ambient: [0,0,0,1],
|
32
|
+
diffuse: [1,1,1,1],
|
33
|
+
specular: [1,1,1,1]
|
34
|
+
},
|
35
|
+
position: [0,0,0],
|
36
|
+
direction: [0,0,-1],
|
37
|
+
angle: Math.PI/6,
|
38
|
+
attenuation: {
|
39
|
+
constant: 0,
|
40
|
+
linear: 0.02,
|
41
|
+
quadratic: 0
|
42
|
+
},
|
43
|
+
spot_exponent: 0,
|
44
|
+
shadowcaster: true
|
45
|
+
});
|
46
|
+
|
47
|
+
if (typeof(data.type) == "string") data.type = Jax[data.type] || data.type;
|
48
|
+
data.color.ambient = Jax.Util.colorize(data.color.ambient);
|
49
|
+
data.color.diffuse = Jax.Util.colorize(data.color.diffuse);
|
50
|
+
data.color.specular= Jax.Util.colorize(data.color.specular);
|
51
|
+
$super(data);
|
52
|
+
|
53
|
+
this.spotExponent = this.spot_exponent;
|
54
|
+
delete this.spot_exponent;
|
55
|
+
|
56
|
+
this.shadowMatrix = mat4.create();
|
57
|
+
|
58
|
+
this.framebuffers = [new Jax.Framebuffer({width:2048,height:2048,depth:true,color:GL_RGBA}),
|
59
|
+
new Jax.Framebuffer({width:2048,height:2048,depth:true,color:GL_RGBA})];
|
60
|
+
|
61
|
+
setupProjection(this);
|
62
|
+
},
|
63
|
+
|
64
|
+
format: function() {
|
65
|
+
this._format = this._format || new glMatrixArrayType(Jax.Scene.LightSource.STRUCT_SIZE);
|
66
|
+
var i, j, len = 0, self = this;
|
67
|
+
function push() { for (j = 0; j < arguments.length; j++) self._format[len++] = arguments[j]; }
|
68
|
+
for (i = 0; i < arguments.length; i++) {
|
69
|
+
switch(arguments[i]) {
|
70
|
+
case Jax.Scene.LightSource.POSITION: push.apply(this, this.getPosition()); break;
|
71
|
+
case Jax.Scene.LightSource.DIRECTION: push.apply(this, this.getDirection()); break;
|
72
|
+
case Jax.Scene.LightSource.AMBIENT: push.apply(this, this.getAmbientColor()); break;
|
73
|
+
case Jax.Scene.LightSource.DIFFUSE: push.apply(this, this.getDiffuseColor()); break;
|
74
|
+
case Jax.Scene.LightSource.SPECULAR: push.apply(this, this.getSpecularColor()); break;
|
75
|
+
case Jax.Scene.LightSource.CONSTANT_ATTENUATION: push(this.getConstantAttenuation()); break;
|
76
|
+
case Jax.Scene.LightSource.LINEAR_ATTENUATION: push(this.getLinearAttenuation()); break;
|
77
|
+
case Jax.Scene.LightSource.QUADRATIC_ATTENUATION: push(this.getQuadraticAttenuation()); break;
|
78
|
+
case Jax.Scene.LightSource.SPOTLIGHT_EXPONENT: push(this.getSpotExponent()); break;
|
79
|
+
case Jax.Scene.LightSource.SPOTLIGHT_COS_CUTOFF: push(this.getSpotCosCutoff()); break;
|
80
|
+
default: throw new Error("Unexpected light source format descriptor: "+arguments[i]);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
return this._format;
|
84
|
+
},
|
85
|
+
|
86
|
+
getPosition: function() { setupProjection(this); return this.camera.getPosition(); },
|
87
|
+
getDirection: function() { setupProjection(this); return this.camera.getViewVector(); },
|
88
|
+
|
89
|
+
setEnabled: function(b) { this.enabled = b; },
|
90
|
+
enable: function() { this.setEnabled(true); },
|
91
|
+
disable: function() { this.setEnabled(false); },
|
92
|
+
|
93
|
+
isEnabled: function() { return this.enabled; },
|
94
|
+
getType: function() { return this.type; },
|
95
|
+
|
96
|
+
getDiffuseColor: function() { return this.color.diffuse; },
|
97
|
+
getAmbientColor: function() { return this.color.ambient; },
|
98
|
+
getSpecularColor: function() { return this.color.specular; },
|
99
|
+
getConstantAttenuation: function() { return this.attenuation.constant; },
|
100
|
+
getQuadraticAttenuation: function() { return this.attenuation.quadratic; },
|
101
|
+
getLinearAttenuation: function() { return this.attenuation.linear; },
|
102
|
+
getAngle: function() { return this.angle; },
|
103
|
+
getSpotExponent: function() { return this.spotExponent; },
|
104
|
+
getSpotCosCutoff: function() { return Math.cos(this.angle); },
|
105
|
+
|
106
|
+
getShadowMapTexture: function(context) {
|
107
|
+
setupProjection(this);
|
108
|
+
return this.framebuffers[0].getTextureBuffer(context, 0);
|
109
|
+
// return this.framebuffers[0].getTextureBufferHandle(context, 0);
|
110
|
+
},
|
111
|
+
|
112
|
+
getShadowMapTextures: function(context) {
|
113
|
+
setupProjection(this);
|
114
|
+
return [this.framebuffers[0].getTextureBuffer(context, 0),
|
115
|
+
this.framebuffers[1].getTextureBuffer(context, 0)];
|
116
|
+
// return [this.framebuffers[0].getTextureBufferHandle(context, 0),
|
117
|
+
// this.framebuffers[1].getTextureBufferHandle(context, 0)];
|
118
|
+
},
|
119
|
+
|
120
|
+
isShadowMapEnabled: function() {
|
121
|
+
return !!(this.framebuffers && this.isShadowcaster());
|
122
|
+
},
|
123
|
+
|
124
|
+
getShadowMatrix: function() {
|
125
|
+
return this.shadowMatrix;
|
126
|
+
},
|
127
|
+
|
128
|
+
isShadowcaster: function() { return this.shadowcaster; },
|
129
|
+
|
130
|
+
getDPShadowNear: function() { setupProjection(this); return this.camera.projection.near; },
|
131
|
+
|
132
|
+
getDPShadowFar: function() { setupProjection(this); return this.camera.projection.far; },
|
133
|
+
|
134
|
+
updateShadowMap: function(context, sceneBoundingRadius, objects) {
|
135
|
+
setupProjection(this);
|
136
|
+
|
137
|
+
var self = this;
|
138
|
+
var sm = this.shadowMatrix;
|
139
|
+
var lightToSceneDistance = vec3.length(this.camera.getPosition());
|
140
|
+
var nearPlane = lightToSceneDistance - sceneBoundingRadius;
|
141
|
+
if (nearPlane < 0.01) nearPlane = 0.01;
|
142
|
+
|
143
|
+
if (this.type == Jax.DIRECTIONAL_LIGHT) {
|
144
|
+
this.camera.ortho({left:-sceneBoundingRadius,right:sceneBoundingRadius,
|
145
|
+
top:sceneBoundingRadius,bottom:-sceneBoundingRadius,
|
146
|
+
near:-sceneBoundingRadius,far:sceneBoundingRadius
|
147
|
+
});
|
148
|
+
this.camera.setPosition(0,0,0);
|
149
|
+
} else if (this.type == Jax.SPOT_LIGHT) {
|
150
|
+
// Save the depth precision for where it's useful
|
151
|
+
var fieldOfView = Math.radToDeg(2.0 * Math.atan(sceneBoundingRadius / lightToSceneDistance));
|
152
|
+
|
153
|
+
// fieldOfView = Math.radToDeg(this.getAngle());
|
154
|
+
fieldOfView = 60;
|
155
|
+
this.camera.perspective({near:nearPlane,far:nearPlane+(2.0*sceneBoundingRadius),fov:fieldOfView,width:2048,height:2048});
|
156
|
+
} else if (this.type == Jax.POINT_LIGHT) {
|
157
|
+
|
158
|
+
context.glDisable(GL_BLEND);
|
159
|
+
context.glEnable(GL_CULL_FACE);
|
160
|
+
context.glCullFace(GL_FRONT);
|
161
|
+
context.glEnable(GL_POLYGON_OFFSET_FILL);
|
162
|
+
context.glPolygonOffset(2.0, 2.0);
|
163
|
+
|
164
|
+
context.pushMatrix(function() {
|
165
|
+
self.framebuffers[0].bind(context, function() {
|
166
|
+
// front paraboloid
|
167
|
+
self.framebuffers[0].viewport(context);
|
168
|
+
context.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
169
|
+
context.loadViewMatrix(self.camera.getModelViewMatrix());
|
170
|
+
mat4.set(context.getInverseViewMatrix(), sm);
|
171
|
+
|
172
|
+
for (var i = 0; i < objects.length; i++) {
|
173
|
+
objects[i].render(context, {material:'paraboloid-depthmap', direction:1});
|
174
|
+
}
|
175
|
+
});
|
176
|
+
|
177
|
+
self.framebuffers[1].bind(context, function() {
|
178
|
+
// back paraboloid
|
179
|
+
self.framebuffers[1].viewport(context);
|
180
|
+
context.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
181
|
+
context.loadViewMatrix(self.camera.getModelViewMatrix());
|
182
|
+
for (var i = 0; i < objects.length; i++) {
|
183
|
+
objects[i].render(context, {material:'paraboloid-depthmap',direction:-1});
|
184
|
+
}
|
185
|
+
});
|
186
|
+
|
187
|
+
context.glDisable(GL_POLYGON_OFFSET_FILL);
|
188
|
+
context.glEnable(GL_BLEND);
|
189
|
+
context.glCullFace(GL_BACK);
|
190
|
+
context.glDisable(GL_CULL_FACE);
|
191
|
+
|
192
|
+
// restore the original context viewport
|
193
|
+
context.glViewport(0, 0, context.canvas.width, context.canvas.height);
|
194
|
+
});
|
195
|
+
|
196
|
+
return;
|
197
|
+
}
|
198
|
+
|
199
|
+
this.framebuffers[0].bind(context, function() {
|
200
|
+
self.framebuffers[0].viewport(context);
|
201
|
+
context.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
202
|
+
context.pushMatrix(function() {
|
203
|
+
self.framebuffers[0].viewport(context);
|
204
|
+
context.matrix_stack.loadProjectionMatrix(self.camera.getProjectionMatrix());
|
205
|
+
context.matrix_stack.loadViewMatrix(self.camera.getModelViewMatrix());
|
206
|
+
mat4.identity(sm);
|
207
|
+
sm[0] = sm[5] = sm[10] = sm[12] = sm[13] = sm[14] = 0.5;
|
208
|
+
mat4.multiply(sm, context.getModelViewProjectionMatrix());
|
209
|
+
|
210
|
+
context.glEnable(GL_CULL_FACE);
|
211
|
+
context.glCullFace(GL_FRONT);
|
212
|
+
context.glDisable(GL_BLEND);
|
213
|
+
context.glEnable(GL_POLYGON_OFFSET_FILL);
|
214
|
+
context.glPolygonOffset(2.0, 2.0);
|
215
|
+
for (var i = 0; i < objects.length; i++) {
|
216
|
+
objects[i].render(context, {material:'depthmap'});
|
217
|
+
}
|
218
|
+
context.glDisable(GL_POLYGON_OFFSET_FILL);
|
219
|
+
context.glEnable(GL_BLEND);
|
220
|
+
context.glCullFace(GL_BACK);
|
221
|
+
context.glDisable(GL_CULL_FACE);
|
222
|
+
});
|
223
|
+
// restore the original context viewport
|
224
|
+
context.glViewport(0, 0, context.canvas.width, context.canvas.height);
|
225
|
+
});
|
226
|
+
}
|
227
|
+
});
|
228
|
+
})();
|
229
|
+
|
230
|
+
/*
|
231
|
+
Constants used internally when constructing the flat-array format for a light source.
|
232
|
+
This is so we don't need to make redundant glUniform() calls to specify the attributes of a single
|
233
|
+
light source.
|
234
|
+
*/
|
235
|
+
Jax.Scene.LightSource.POSITION = 1;
|
236
|
+
Jax.Scene.LightSource.DIRECTION = 2;
|
237
|
+
Jax.Scene.LightSource.AMBIENT = 3;
|
238
|
+
Jax.Scene.LightSource.DIFFUSE = 4;
|
239
|
+
Jax.Scene.LightSource.SPECULAR = 5;
|
240
|
+
Jax.Scene.LightSource.CONSTANT_ATTENUATION = 6;
|
241
|
+
Jax.Scene.LightSource.LINEAR_ATTENUATION = 7;
|
242
|
+
Jax.Scene.LightSource.QUADRATIC_ATTENUATION = 8;
|
243
|
+
Jax.Scene.LightSource.SPOTLIGHT_EXPONENT = 9;
|
244
|
+
Jax.Scene.LightSource.SPOTLIGHT_COS_CUTOFF = 10;
|
245
|
+
|
246
|
+
/* The size of the light source structure, in float elements */
|
247
|
+
Jax.Scene.LightSource.STRUCT_SIZE = 23;
|
248
|
+
|
@@ -0,0 +1,282 @@
|
|
1
|
+
Jax.Shader = (function() {
|
2
|
+
function buildStackTrace(context, glShader, source) {
|
3
|
+
source = source.split(/\n/);
|
4
|
+
var log = context.glGetShaderInfoLog(glShader).split(/\n/);
|
5
|
+
|
6
|
+
/* build a detailed backtrace with error information so devs can actually find the error */
|
7
|
+
var current = 1, injected = [], li;
|
8
|
+
function strToInject() { return current+" : "+source[current-1]; }
|
9
|
+
for (li = 0; li < log.length; li++) {
|
10
|
+
var line = log[li];
|
11
|
+
var match = /0:(\d+):(.*)/.exec(line);
|
12
|
+
if (!match) continue; // blank line
|
13
|
+
var line_number = parseInt(match[1]);
|
14
|
+
if (line_number > current)
|
15
|
+
for (; current < line_number; current++)
|
16
|
+
injected.push(strToInject());
|
17
|
+
if (line_number == current) {
|
18
|
+
injected.push(strToInject());
|
19
|
+
injected.push(":: ERROR : "+match[2]); /* error message */
|
20
|
+
}
|
21
|
+
current = line_number+1;
|
22
|
+
}
|
23
|
+
|
24
|
+
/* prepend a summary so user can debug simple errors at a glance */
|
25
|
+
injected.unshift("");
|
26
|
+
for (li = log.length-1; li >= 0; li--)
|
27
|
+
injected.unshift(log[li]);
|
28
|
+
|
29
|
+
/* finally, add 3 more lines so the user has an easier time finding the problem in ambiguous code */
|
30
|
+
li = current;
|
31
|
+
for (current = li; current < li+3; current++)
|
32
|
+
injected.push(strToInject());
|
33
|
+
|
34
|
+
return injected.join("\n");
|
35
|
+
}
|
36
|
+
|
37
|
+
function compile(context, shader, source) {
|
38
|
+
context.glShaderSource(shader, source);
|
39
|
+
shader.source = source;
|
40
|
+
context.glCompileShader(shader);
|
41
|
+
if (!context.glGetShaderParameter(shader, GL_COMPILE_STATUS))
|
42
|
+
throw new Error(buildStackTrace(context, shader, source));
|
43
|
+
}
|
44
|
+
|
45
|
+
function sanitizeName(name) {
|
46
|
+
return name.replace(/-/, '_');
|
47
|
+
}
|
48
|
+
|
49
|
+
function getExportedVariableName(exportPrefix, name) {
|
50
|
+
return sanitizeName("_"+exportPrefix+"_"+name);
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
preprocess shader source code to replace "import(varname, expression)" with the globalized varname if it's been
|
55
|
+
exported (as an attribute of material.exports || self.options.exports), or expression if it hasn't.
|
56
|
+
*/
|
57
|
+
function applyImports(self, options, source) {
|
58
|
+
var rx = /import\((.*?),\s*(.*?)\)/, result;
|
59
|
+
var exp;
|
60
|
+
while (result = rx.exec(source)) {
|
61
|
+
var name = result[1];
|
62
|
+
if (options && (exp = (options.exports && options.exports[name]) || (self.options.exports && self.options.exports[name]))) {
|
63
|
+
var exportedVariableName = getExportedVariableName(options.export_prefix || self.getName(), name);
|
64
|
+
source = source.replace(result[0], result[2].replace(new RegExp(name, "g"), exportedVariableName));
|
65
|
+
}
|
66
|
+
else source = source.replace(result[0], "");
|
67
|
+
}
|
68
|
+
return source;
|
69
|
+
}
|
70
|
+
|
71
|
+
function applyExports(self, options, source) {
|
72
|
+
var rx = /export\((.*?),\s*(.*?)(,\s*(.*?))?\)/, result;
|
73
|
+
// rx should match both 'export(vec4, ambient)' and 'export(vec4, ambient, ambient)'
|
74
|
+
var replacement, name, type, assignment;
|
75
|
+
while (result = rx.exec(source)) {
|
76
|
+
type = result[1];
|
77
|
+
name = result[2];
|
78
|
+
assignment = result[4] || null;
|
79
|
+
replacement = getExportedVariableName(options && options.export_prefix || self.getName(), name)+" = ";
|
80
|
+
if (assignment) replacement += assignment;
|
81
|
+
else replacement += name;
|
82
|
+
source = source.replace(result[0], replacement);
|
83
|
+
}
|
84
|
+
return source;
|
85
|
+
}
|
86
|
+
|
87
|
+
function mangleUniformsAndAttributes(self, material, source) {
|
88
|
+
var map = self.getInputMap(material);
|
89
|
+
for (var name in map)
|
90
|
+
source = source.replace(new RegExp("(^|[^a-zA-Z0-9])"+name+"([^a-zA-Z0-9]|$)", "g"), "$1"+map[name].full_name+"$2");
|
91
|
+
|
92
|
+
// remove the "shared" directive
|
93
|
+
return source.replace(/(^|[^\w])shared\s+/g, "$1");
|
94
|
+
}
|
95
|
+
|
96
|
+
function stripSharedDefinitions(self, options, source) {
|
97
|
+
var map = self.getInputMap(options);
|
98
|
+
for (var i in map) {
|
99
|
+
if (map[i].shared) {
|
100
|
+
if (options.skip_global_definitions && options.skip_global_definitions.indexOf(map[i].full_name) != -1) {
|
101
|
+
var rx = new RegExp("(shared\\s+)?"+map[i].scope+"\\s*"+map[i].type+"[^;]*?"+map[i].full_name+"[^;]*?;\n?", "g");
|
102
|
+
source = source.replace(rx, "");
|
103
|
+
}
|
104
|
+
// else source = source.replace(rx, map[i].scope+" "+map[i].type+" "+map[i].full_name+";\n");
|
105
|
+
}
|
106
|
+
}
|
107
|
+
return source.replace(/shared\s+/, '');
|
108
|
+
}
|
109
|
+
|
110
|
+
/* TODO separate preprocessing from shader and friends; perhaps a Jax.Shader.Preprocessor class? */
|
111
|
+
function preprocess(self, options, source, isVertex) {
|
112
|
+
source = stripSharedDefinitions(self, options, source);
|
113
|
+
// source = source.replace(/^\s*(shared\s+|)(uniform|attribute|varying)([^;]*)?;\n?/, '');
|
114
|
+
// if (!options || !options.skip_global_definitions)
|
115
|
+
// source = self.getGlobalDefinitions(options, isVertex) + source;
|
116
|
+
source = applyExports(self, options, source);
|
117
|
+
source = applyImports(self, options, source);
|
118
|
+
source = mangleUniformsAndAttributes(self, options, source);
|
119
|
+
return source;
|
120
|
+
}
|
121
|
+
|
122
|
+
function numArgumentsInMain(source) {
|
123
|
+
var result = /void\s*main\((.*?)\)\s*\{/.exec(source);
|
124
|
+
if (result) {
|
125
|
+
result = result[1].replace(/\s*/g, '');
|
126
|
+
if (result == "" || result == "void") return 0;
|
127
|
+
else return result[1].split(/,/).length;
|
128
|
+
}
|
129
|
+
else throw new Error("Could not find main() function in source!\n\n"+source);
|
130
|
+
}
|
131
|
+
|
132
|
+
return Jax.Class.create({
|
133
|
+
initialize: function(obj) {
|
134
|
+
this.options = obj;
|
135
|
+
|
136
|
+
if (obj.vertex) this.setRawSource(obj.vertex, 'vertex');
|
137
|
+
if (obj.fragment) this.setRawSource(obj.fragment, 'fragment');
|
138
|
+
if (obj.common) this.setRawSource(obj.common, 'common');
|
139
|
+
|
140
|
+
this.shaders = { vertex: {}, fragment: {} };
|
141
|
+
},
|
142
|
+
|
143
|
+
getName: function() { return this.options.name; },
|
144
|
+
|
145
|
+
getVertexShader: function(context) {
|
146
|
+
if (!this.options.vertex) return null;
|
147
|
+
this.shaders.vertex[context.id] = this.shaders.vertex[context.id] || context.glCreateShader(GL_VERTEX_SHADER);
|
148
|
+
return this.shaders.vertex[context.id];
|
149
|
+
},
|
150
|
+
|
151
|
+
getFragmentShader: function(context) {
|
152
|
+
if (!this.options.fragment) return null;
|
153
|
+
this.shaders.fragment[context.id] = this.shaders.fragment[context.id] || context.glCreateShader(GL_FRAGMENT_SHADER);
|
154
|
+
return this.shaders.fragment[context.id];
|
155
|
+
},
|
156
|
+
|
157
|
+
getCommonSource: function(material) {
|
158
|
+
return this.options.common ? this.options.common.render(material) : "";
|
159
|
+
},
|
160
|
+
|
161
|
+
getVertexSource: function(material) {
|
162
|
+
var source = this.getRawSource(material, 'vertex');
|
163
|
+
return source && preprocess(this, material, source, true);
|
164
|
+
},
|
165
|
+
|
166
|
+
getPreamble: function(options) {
|
167
|
+
return options && options.ignore_es_precision ? "" : "#ifdef GL_ES\nprecision highp float;\n#endif\n";
|
168
|
+
},
|
169
|
+
|
170
|
+
getFragmentSource: function(material) {
|
171
|
+
var source = this.getRawSource(material, 'fragment');
|
172
|
+
return source && preprocess(this, material, source, false);
|
173
|
+
},
|
174
|
+
|
175
|
+
getVertexArgumentCount: function(options) {
|
176
|
+
var source = this.getVertexSource(options);
|
177
|
+
return numArgumentsInMain(source);
|
178
|
+
},
|
179
|
+
|
180
|
+
getFragmentArgumentCount: function(options) {
|
181
|
+
var source = this.getFragmentSource(options);
|
182
|
+
return numArgumentsInMain(source);
|
183
|
+
},
|
184
|
+
|
185
|
+
getRawSource: function(options, which) {
|
186
|
+
var source = this.options[which];
|
187
|
+
if (source && (source = source.render(options))) {
|
188
|
+
var result = this.getPreamble(options);
|
189
|
+
if (!options || !options.skip_export_definitions)
|
190
|
+
result += this.getExportDefinitions(options && options.export_prefix || this.getName());
|
191
|
+
if (!options || !options.skip_common_source)
|
192
|
+
result += this.getCommonSource(options) + "\n";
|
193
|
+
result += source;
|
194
|
+
return result;
|
195
|
+
}
|
196
|
+
return null;
|
197
|
+
},
|
198
|
+
|
199
|
+
getGlobalDefinitions: function(options, isVertex) {
|
200
|
+
var map = this.getInputMap(options);
|
201
|
+
var source = "";
|
202
|
+
for (var i in map) {
|
203
|
+
if (map[i].scope == "attribute" && !isVertex) continue;
|
204
|
+
source += map[i].scope+" "+map[i].type+" "+map[i].full_name+";\n";
|
205
|
+
}
|
206
|
+
return source;
|
207
|
+
},
|
208
|
+
|
209
|
+
setRawSource: function(source, which) { this.options[which] = source && new EJS({text:source}); },
|
210
|
+
|
211
|
+
setVertexSource: function(source) { this.setRawSource(source, 'vertex'); },
|
212
|
+
|
213
|
+
setFragmentSource: function(source) { this.setRawSource(source, 'fragment'); },
|
214
|
+
|
215
|
+
getInputMap: function(options) {
|
216
|
+
var map = {};
|
217
|
+
var prefix = "";
|
218
|
+
|
219
|
+
if (options && options.local_prefix) prefix = options.local_prefix+"_";
|
220
|
+
else if (options && options.export_prefix) prefix = options.export_prefix+"_";
|
221
|
+
|
222
|
+
var source = (this.getRawSource(options, 'common') || "") + "\n\n" +
|
223
|
+
(this.getRawSource(options, 'vertex') || "") + "\n\n" +
|
224
|
+
(this.getRawSource(options, 'fragment') || "");
|
225
|
+
|
226
|
+
// if it's not a "shared" uniform, mangle its name.
|
227
|
+
var rx = new RegExp("(^|\\n|\\s+)((shared\\s+)?)(uniform|attribute|varying) (\\w+) ((?!"+prefix+")[^;]*);"), result;
|
228
|
+
while (result = rx.exec(source)) {
|
229
|
+
var shared = /shared/.test(result[2]);
|
230
|
+
var scope = result[4];
|
231
|
+
var type = result[5];
|
232
|
+
var names = result[6].split(/,/);
|
233
|
+
|
234
|
+
for (var i = 0; i < names.length; i++) {
|
235
|
+
names[i] = names[i].replace(/^\s+/, '').replace(/\s+$/, '');
|
236
|
+
if (shared) map[names[i]] = names[i];
|
237
|
+
else map[names[i]] = sanitizeName(prefix+names[i]);
|
238
|
+
map[names[i]] = { full_name: map[names[i]], type: type, scope: scope, shared: shared };
|
239
|
+
source = source.replace(new RegExp("(^|[^a-zA-Z0-9_])"+names[i]+"([^a-zA-Z0-9_]|$)", "g"),
|
240
|
+
"$1"+prefix+names[i]+"$2");
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
244
|
+
return map;
|
245
|
+
},
|
246
|
+
|
247
|
+
getExportDefinitions: function(exportPrefix, skip) {
|
248
|
+
var exports = "";
|
249
|
+
if (this.options.exports) {
|
250
|
+
for (var name in this.options.exports) {
|
251
|
+
if (!skip || skip.indexOf(name) == -1)
|
252
|
+
exports += this.options.exports[name]+" "+getExportedVariableName(exportPrefix, name)+";\n";
|
253
|
+
}
|
254
|
+
}
|
255
|
+
return exports + "\n";
|
256
|
+
},
|
257
|
+
|
258
|
+
build: function(context, material) {
|
259
|
+
var count = 0;
|
260
|
+
if (this.getVertexShader(context)) {
|
261
|
+
count++;
|
262
|
+
compile(context, this.getVertexShader(context), this.getVertexSource(material));
|
263
|
+
}
|
264
|
+
if (this.getFragmentShader(context)) {
|
265
|
+
count++;
|
266
|
+
compile(context, this.getFragmentShader(context), this.getFragmentSource(material));
|
267
|
+
}
|
268
|
+
if (count == 0) throw new Error("No sources specified for shader '"+this.getName()+"'!");
|
269
|
+
}
|
270
|
+
});
|
271
|
+
})();
|
272
|
+
|
273
|
+
|
274
|
+
Jax.Shader.max_varyings = gl.getParameter(GL_MAX_VARYING_VECTORS);
|
275
|
+
Jax.Shader.max_vertex_uniforms = gl.getParameter(GL_MAX_VERTEX_UNIFORM_VECTORS);
|
276
|
+
Jax.Shader.max_fragment_uniforms = gl.getParameter(GL_MAX_FRAGMENT_UNIFORM_VECTORS);
|
277
|
+
Jax.Shader.max_attributes = gl.getParameter(GL_MAX_VERTEX_ATTRIBS);
|
278
|
+
|
279
|
+
// FIXME differentiate between vertex & fragment uniforms
|
280
|
+
Jax.Shader.max_uniforms = Math.min(Jax.Shader.max_fragment_uniforms, Jax.Shader.max_vertex_uniforms);
|
281
|
+
|
282
|
+
//= require "shader/program"
|