picrate 0.0.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +47 -0
  3. data/.mvn/extensions.xml +9 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +1 -0
  5. data/.travis.yml +10 -0
  6. data/CHANGELOG.md +4 -0
  7. data/LICENSE.md +165 -0
  8. data/README.md +51 -0
  9. data/Rakefile +59 -0
  10. data/bin/picrate +8 -0
  11. data/docs/.gitignore +6 -0
  12. data/docs/_config.yml +30 -0
  13. data/docs/_includes/footer.html +38 -0
  14. data/docs/_includes/head.html +16 -0
  15. data/docs/_includes/header.html +27 -0
  16. data/docs/_includes/icon-github.html +1 -0
  17. data/docs/_includes/icon-github.svg +1 -0
  18. data/docs/_includes/icon-twitter.html +1 -0
  19. data/docs/_includes/icon-twitter.svg +1 -0
  20. data/docs/_includes/navigation.html +24 -0
  21. data/docs/_layouts/default.html +20 -0
  22. data/docs/_layouts/page.html +14 -0
  23. data/docs/_layouts/post.html +15 -0
  24. data/docs/_posts/2018-05-06-getting_started.md +8 -0
  25. data/docs/_posts/2018-05-06-install_jruby.md +35 -0
  26. data/docs/_sass/_base.scss +206 -0
  27. data/docs/_sass/_layout.scss +242 -0
  28. data/docs/_sass/_syntax-highlighting.scss +71 -0
  29. data/docs/about.md +10 -0
  30. data/docs/css/main.scss +38 -0
  31. data/docs/favicon.ico +0 -0
  32. data/docs/feed.xml +30 -0
  33. data/docs/index.html +38 -0
  34. data/lib/picrate.rb +10 -0
  35. data/lib/picrate/app.rb +187 -0
  36. data/lib/picrate/creators/sketch_class.rb +57 -0
  37. data/lib/picrate/creators/sketch_factory.rb +12 -0
  38. data/lib/picrate/creators/sketch_writer.rb +21 -0
  39. data/lib/picrate/helper_methods.rb +214 -0
  40. data/lib/picrate/helpers/numeric.rb +9 -0
  41. data/lib/picrate/library.rb +69 -0
  42. data/lib/picrate/library_loader.rb +53 -0
  43. data/lib/picrate/native_folder.rb +35 -0
  44. data/lib/picrate/native_loader.rb +27 -0
  45. data/lib/picrate/runner.rb +81 -0
  46. data/lib/picrate/version.rb +4 -0
  47. data/library/boids/boids.rb +209 -0
  48. data/library/chooser/chooser.rb +19 -0
  49. data/library/control_panel/control_panel.rb +182 -0
  50. data/library/library_proxy/README.md +99 -0
  51. data/library/library_proxy/library_proxy.rb +14 -0
  52. data/library/slider/slider.rb +42 -0
  53. data/library/vector_utils/vector_utils.rb +69 -0
  54. data/library/video_event/video_event.rb +3 -0
  55. data/license.txt +508 -0
  56. data/picrate.gemspec +35 -0
  57. data/pom.rb +122 -0
  58. data/pom.xml +214 -0
  59. data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
  60. data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  61. data/src/main/java/monkstone/ColorUtil.java +115 -0
  62. data/src/main/java/monkstone/MathToolModule.java +236 -0
  63. data/src/main/java/monkstone/PicrateLibrary.java +47 -0
  64. data/src/main/java/monkstone/core/LibraryProxy.java +127 -0
  65. data/src/main/java/monkstone/fastmath/Deglut.java +122 -0
  66. data/src/main/java/monkstone/fastmath/package-info.java +6 -0
  67. data/src/main/java/monkstone/filechooser/Chooser.java +48 -0
  68. data/src/main/java/monkstone/noise/SimplexNoise.java +465 -0
  69. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +168 -0
  70. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +182 -0
  71. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +149 -0
  72. data/src/main/java/monkstone/slider/SimpleSlider.java +196 -0
  73. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +163 -0
  74. data/src/main/java/monkstone/slider/Slider.java +67 -0
  75. data/src/main/java/monkstone/slider/SliderBar.java +277 -0
  76. data/src/main/java/monkstone/slider/SliderGroup.java +78 -0
  77. data/src/main/java/monkstone/slider/WheelHandler.java +35 -0
  78. data/src/main/java/monkstone/vecmath/AppRender.java +87 -0
  79. data/src/main/java/monkstone/vecmath/JRender.java +56 -0
  80. data/src/main/java/monkstone/vecmath/ShapeRender.java +87 -0
  81. data/src/main/java/monkstone/vecmath/package-info.java +20 -0
  82. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +757 -0
  83. data/src/main/java/monkstone/vecmath/vec2/package-info.java +6 -0
  84. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +727 -0
  85. data/src/main/java/monkstone/vecmath/vec3/package-info.java +6 -0
  86. data/src/main/java/monkstone/videoevent/VideoInterface.java +42 -0
  87. data/src/main/java/monkstone/videoevent/package-info.java +20 -0
  88. data/src/main/java/processing/awt/PGraphicsJava2D.java +3098 -0
  89. data/src/main/java/processing/awt/PShapeJava2D.java +401 -0
  90. data/src/main/java/processing/awt/PSurfaceAWT.java +1660 -0
  91. data/src/main/java/processing/core/PApplet.java +17647 -0
  92. data/src/main/java/processing/core/PConstants.java +1033 -0
  93. data/src/main/java/processing/core/PFont.java +1250 -0
  94. data/src/main/java/processing/core/PGraphics.java +9614 -0
  95. data/src/main/java/processing/core/PImage.java +3608 -0
  96. data/src/main/java/processing/core/PMatrix.java +347 -0
  97. data/src/main/java/processing/core/PMatrix2D.java +694 -0
  98. data/src/main/java/processing/core/PMatrix3D.java +1153 -0
  99. data/src/main/java/processing/core/PShape.java +4332 -0
  100. data/src/main/java/processing/core/PShapeOBJ.java +544 -0
  101. data/src/main/java/processing/core/PShapeSVG.java +1987 -0
  102. data/src/main/java/processing/core/PStyle.java +208 -0
  103. data/src/main/java/processing/core/PSurface.java +242 -0
  104. data/src/main/java/processing/core/PSurfaceNone.java +479 -0
  105. data/src/main/java/processing/core/PVector.java +1140 -0
  106. data/src/main/java/processing/data/FloatDict.java +829 -0
  107. data/src/main/java/processing/data/FloatList.java +912 -0
  108. data/src/main/java/processing/data/IntDict.java +796 -0
  109. data/src/main/java/processing/data/IntList.java +913 -0
  110. data/src/main/java/processing/data/JSONArray.java +1260 -0
  111. data/src/main/java/processing/data/JSONObject.java +2282 -0
  112. data/src/main/java/processing/data/JSONTokener.java +435 -0
  113. data/src/main/java/processing/data/Sort.java +46 -0
  114. data/src/main/java/processing/data/StringDict.java +601 -0
  115. data/src/main/java/processing/data/StringList.java +775 -0
  116. data/src/main/java/processing/data/Table.java +4923 -0
  117. data/src/main/java/processing/data/TableRow.java +198 -0
  118. data/src/main/java/processing/data/XML.java +1149 -0
  119. data/src/main/java/processing/event/Event.java +108 -0
  120. data/src/main/java/processing/event/KeyEvent.java +70 -0
  121. data/src/main/java/processing/event/MouseEvent.java +149 -0
  122. data/src/main/java/processing/event/TouchEvent.java +57 -0
  123. data/src/main/java/processing/javafx/PGraphicsFX2D.java +354 -0
  124. data/src/main/java/processing/opengl/FontTexture.java +379 -0
  125. data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
  126. data/src/main/java/processing/opengl/LinePath.java +623 -0
  127. data/src/main/java/processing/opengl/LineStroker.java +685 -0
  128. data/src/main/java/processing/opengl/PGL.java +3366 -0
  129. data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
  130. data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
  131. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
  132. data/src/main/java/processing/opengl/PJOGL.java +1966 -0
  133. data/src/main/java/processing/opengl/PShader.java +1478 -0
  134. data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
  135. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
  136. data/src/main/java/processing/opengl/Texture.java +1670 -0
  137. data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
  138. data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
  139. data/src/main/java/processing/opengl/cursors/cross.png +0 -0
  140. data/src/main/java/processing/opengl/cursors/hand.png +0 -0
  141. data/src/main/java/processing/opengl/cursors/license.txt +27 -0
  142. data/src/main/java/processing/opengl/cursors/move.png +0 -0
  143. data/src/main/java/processing/opengl/cursors/text.png +0 -0
  144. data/src/main/java/processing/opengl/cursors/wait.png +0 -0
  145. data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
  146. data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
  147. data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
  148. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
  149. data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
  150. data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
  151. data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
  152. data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
  153. data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
  154. data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
  155. data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
  156. data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
  157. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
  158. data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
  159. data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
  160. data/src/main/resources/icon/icon-1024.png +0 -0
  161. data/src/main/resources/icon/icon-128.png +0 -0
  162. data/src/main/resources/icon/icon-16.png +0 -0
  163. data/src/main/resources/icon/icon-256.png +0 -0
  164. data/src/main/resources/icon/icon-32.png +0 -0
  165. data/src/main/resources/icon/icon-48.png +0 -0
  166. data/src/main/resources/icon/icon-512.png +0 -0
  167. data/src/main/resources/icon/icon-64.png +0 -0
  168. data/src/main/resources/license.txt +508 -0
  169. data/test/create_test.rb +68 -0
  170. data/test/deglut_spec_test.rb +24 -0
  171. data/test/helper_methods_test.rb +58 -0
  172. data/test/math_tool_test.rb +75 -0
  173. data/test/respond_to_test.rb +215 -0
  174. data/test/sketches/key_event.rb +37 -0
  175. data/test/sketches/library/my_library/my_library.rb +32 -0
  176. data/test/test_helper.rb +3 -0
  177. data/test/vecmath_spec_test.rb +522 -0
  178. data/vendors/Rakefile +127 -0
  179. metadata +289 -0
@@ -0,0 +1,32 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ #ifdef GL_ES
24
+ precision mediump float;
25
+ precision mediump int;
26
+ #endif
27
+
28
+ varying vec4 vertColor;
29
+
30
+ void main() {
31
+ gl_FragColor = vertColor;
32
+ }
@@ -0,0 +1,100 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ #define PROCESSING_LINE_SHADER
24
+
25
+ uniform mat4 modelviewMatrix;
26
+ uniform mat4 projectionMatrix;
27
+
28
+ uniform vec4 viewport;
29
+ uniform int perspective;
30
+ uniform vec3 scale;
31
+
32
+ attribute vec4 position;
33
+ attribute vec4 color;
34
+ attribute vec4 direction;
35
+
36
+ varying vec4 vertColor;
37
+
38
+ void main() {
39
+ vec4 posp = modelviewMatrix * position;
40
+ vec4 posq = modelviewMatrix * (position + vec4(direction.xyz, 0));
41
+
42
+ // Moving vertices slightly toward the camera
43
+ // to avoid depth-fighting with the fill triangles.
44
+ // Discussed here:
45
+ // http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848
46
+ posp.xyz = posp.xyz * scale;
47
+ posq.xyz = posq.xyz * scale;
48
+
49
+ vec4 p = projectionMatrix * posp;
50
+ vec4 q = projectionMatrix * posq;
51
+
52
+ // formula to convert from clip space (range -1..1) to screen space (range 0..[width or height])
53
+ // screen_p = (p.xy/p.w + <1,1>) * 0.5 * viewport.zw
54
+
55
+ // prevent division by W by transforming the tangent formula (div by 0 causes
56
+ // the line to disappear, see https://github.com/processing/processing/issues/5183)
57
+ // t = screen_q - screen_p
58
+ //
59
+ // tangent is normalized and we don't care which direction it points to (+-)
60
+ // t = +- normalize( screen_q - screen_p )
61
+ // t = +- normalize( (q.xy/q.w+<1,1>)*0.5*viewport.zw - (p.xy/p.w+<1,1>)*0.5*viewport.zw )
62
+ //
63
+ // extract common factor, <1,1> - <1,1> cancels out
64
+ // t = +- normalize( (q.xy/q.w - p.xy/p.w) * 0.5 * viewport.zw )
65
+ //
66
+ // convert to common divisor
67
+ // t = +- normalize( ((q.xy*p.w - p.xy*q.w) / (p.w*q.w)) * 0.5 * viewport.zw )
68
+ //
69
+ // remove the common scalar divisor/factor, not needed due to normalize and +-
70
+ // (keep viewport - can't remove because it has different components for x and y
71
+ // and corrects for aspect ratio, see https://github.com/processing/processing/issues/5181)
72
+ // t = +- normalize( (q.xy*p.w - p.xy*q.w) * viewport.zw )
73
+
74
+ vec2 tangent = (q.xy*p.w - p.xy*q.w) * viewport.zw;
75
+
76
+ // don't normalize zero vector (line join triangles and lines perpendicular to the eye plane)
77
+ tangent = length(tangent) == 0.0 ? vec2(0.0, 0.0) : normalize(tangent);
78
+
79
+ // flip tangent to normal (it's already normalized)
80
+ vec2 normal = vec2(-tangent.y, tangent.x);
81
+
82
+ float thickness = direction.w;
83
+ vec2 offset = normal * thickness;
84
+
85
+ // Perspective ---
86
+ // convert from world to clip by multiplying with projection scaling factor
87
+ // to get the right thickness (see https://github.com/processing/processing/issues/5182)
88
+ // invert Y, projections in Processing invert Y
89
+ vec2 perspScale = (projectionMatrix * vec4(1, -1, 0, 0)).xy;
90
+
91
+ // No Perspective ---
92
+ // multiply by W (to cancel out division by W later in the pipeline) and
93
+ // convert from screen to clip (derived from clip to screen above)
94
+ vec2 noPerspScale = p.w / (0.5 * viewport.zw);
95
+
96
+ gl_Position.xy = p.xy + offset.xy * mix(noPerspScale, perspScale, float(perspective > 0));
97
+ gl_Position.zw = p.zw;
98
+
99
+ vertColor = color;
100
+ }
@@ -0,0 +1,40 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ #ifdef GL_ES
24
+ precision mediump float;
25
+ precision mediump int;
26
+ #endif
27
+
28
+ #define PROCESSING_TEXTURE_SHADER
29
+
30
+ uniform sampler2D texture;
31
+ uniform sampler2D mask;
32
+
33
+ varying vec4 vertTexCoord;
34
+
35
+ void main() {
36
+ vec3 texColor = texture2D(texture, vertTexCoord.st).rgb;
37
+ vec3 maskColor = texture2D(mask, vertTexCoord.st).rgb;
38
+ float luminance = dot(maskColor, vec3(0.2126, 0.7152, 0.0722));
39
+ gl_FragColor = vec4(texColor, luminance);
40
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ #ifdef GL_ES
24
+ precision mediump float;
25
+ precision mediump int;
26
+ #endif
27
+
28
+ varying vec4 vertColor;
29
+
30
+ void main() {
31
+ gl_FragColor = vertColor;
32
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ uniform mat4 projectionMatrix;
24
+ uniform mat4 modelviewMatrix;
25
+
26
+ uniform vec4 viewport;
27
+ uniform int perspective;
28
+
29
+ attribute vec4 position;
30
+ attribute vec4 color;
31
+ attribute vec2 offset;
32
+
33
+ varying vec4 vertColor;
34
+
35
+ void main() {
36
+ vec4 pos = modelviewMatrix * position;
37
+ vec4 clip = projectionMatrix * pos;
38
+
39
+ // Perspective ---
40
+ // convert from world to clip by multiplying with projection scaling factor
41
+ // invert Y, projections in Processing invert Y
42
+ vec2 perspScale = (projectionMatrix * vec4(1, -1, 0, 0)).xy;
43
+
44
+ // formula to convert from clip space (range -1..1) to screen space (range 0..[width or height])
45
+ // screen_p = (p.xy/p.w + <1,1>) * 0.5 * viewport.zw
46
+
47
+ // No Perspective ---
48
+ // multiply by W (to cancel out division by W later in the pipeline) and
49
+ // convert from screen to clip (derived from clip to screen above)
50
+ vec2 noPerspScale = clip.w / (0.5 * viewport.zw);
51
+
52
+ gl_Position.xy = clip.xy + offset.xy * mix(noPerspScale, perspScale, float(perspective > 0));
53
+ gl_Position.zw = clip.zw;
54
+
55
+ vertColor = color;
56
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ #ifdef GL_ES
24
+ precision mediump float;
25
+ precision mediump int;
26
+ #endif
27
+
28
+ uniform sampler2D texture;
29
+
30
+ uniform vec2 texOffset;
31
+
32
+ varying vec4 vertColor;
33
+ varying vec4 vertTexCoord;
34
+
35
+ void main() {
36
+ gl_FragColor = texture2D(texture, vertTexCoord.st) * vertColor;
37
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+ #ifdef GL_ES
23
+ precision mediump float;
24
+ precision mediump int;
25
+ #endif
26
+
27
+ uniform sampler2D texture;
28
+
29
+ uniform vec2 texOffset;
30
+
31
+ varying vec4 vertColor;
32
+ varying vec4 backVertColor;
33
+ varying vec4 vertTexCoord;
34
+
35
+ void main() {
36
+ gl_FragColor = texture2D(texture, vertTexCoord.st) * (gl_FrontFacing ? vertColor : backVertColor);
37
+ }
@@ -0,0 +1,160 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ uniform mat4 modelviewMatrix;
24
+ uniform mat4 transformMatrix;
25
+ uniform mat3 normalMatrix;
26
+ uniform mat4 texMatrix;
27
+
28
+ uniform int lightCount;
29
+ uniform vec4 lightPosition[8];
30
+ uniform vec3 lightNormal[8];
31
+ uniform vec3 lightAmbient[8];
32
+ uniform vec3 lightDiffuse[8];
33
+ uniform vec3 lightSpecular[8];
34
+ uniform vec3 lightFalloff[8];
35
+ uniform vec2 lightSpot[8];
36
+
37
+ attribute vec4 position;
38
+ attribute vec4 color;
39
+ attribute vec3 normal;
40
+ attribute vec2 texCoord;
41
+
42
+ attribute vec4 ambient;
43
+ attribute vec4 specular;
44
+ attribute vec4 emissive;
45
+ attribute float shininess;
46
+
47
+ varying vec4 vertColor;
48
+ varying vec4 backVertColor;
49
+ varying vec4 vertTexCoord;
50
+
51
+ const float zero_float = 0.0;
52
+ const float one_float = 1.0;
53
+ const vec3 zero_vec3 = vec3(0.0);
54
+ const vec3 minus_one_vec3 = vec3(0.0-1.0);
55
+
56
+ float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) {
57
+ vec3 lpv = lightPos - vertPos;
58
+ vec3 dist = vec3(one_float);
59
+ dist.z = dot(lpv, lpv);
60
+ dist.y = sqrt(dist.z);
61
+ return one_float / dot(dist, coeff);
62
+ }
63
+
64
+ float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) {
65
+ vec3 lpv = normalize(lightPos - vertPos);
66
+ vec3 nln = minus_one_vec3 * lightNorm;
67
+ float spotCos = dot(nln, lpv);
68
+ return spotCos <= minCos ? zero_float : pow(spotCos, spotExp);
69
+ }
70
+
71
+ float lambertFactor(vec3 lightDir, vec3 vecNormal) {
72
+ return max(zero_float, dot(lightDir, vecNormal));
73
+ }
74
+
75
+ float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine) {
76
+ vec3 np = normalize(vertPos);
77
+ vec3 ldp = normalize(lightDir - np);
78
+ return pow(max(zero_float, dot(ldp, vecNormal)), shine);
79
+ }
80
+
81
+ void main() {
82
+ // Vertex in clip coordinates
83
+ gl_Position = transformMatrix * position;
84
+
85
+ // Vertex in eye coordinates
86
+ vec3 ecVertex = vec3(modelviewMatrix * position);
87
+
88
+ // Normal vector in eye coordinates
89
+ vec3 ecNormal = normalize(normalMatrix * normal);
90
+ vec3 ecNormalInv = ecNormal * minus_one_vec3;
91
+
92
+ // Light calculations
93
+ vec3 totalAmbient = vec3(0, 0, 0);
94
+
95
+ vec3 totalFrontDiffuse = vec3(0, 0, 0);
96
+ vec3 totalFrontSpecular = vec3(0, 0, 0);
97
+
98
+ vec3 totalBackDiffuse = vec3(0, 0, 0);
99
+ vec3 totalBackSpecular = vec3(0, 0, 0);
100
+
101
+ // prevent register allocation failure by limiting ourselves to
102
+ // two lights for now
103
+ for (int i = 0; i < 2; i++) {
104
+ if (lightCount == i) break;
105
+
106
+ vec3 lightPos = lightPosition[i].xyz;
107
+ bool isDir = lightPosition[i].w < one_float;
108
+ float spotCos = lightSpot[i].x;
109
+ float spotExp = lightSpot[i].y;
110
+
111
+ vec3 lightDir;
112
+ float falloff;
113
+ float spotf;
114
+
115
+ if (isDir) {
116
+ falloff = one_float;
117
+ lightDir = minus_one_vec3 * lightNormal[i];
118
+ } else {
119
+ falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]);
120
+ lightDir = normalize(lightPos - ecVertex);
121
+ }
122
+
123
+ spotf = spotExp > zero_float ? spotFactor(lightPos, ecVertex, lightNormal[i],
124
+ spotCos, spotExp)
125
+ : one_float;
126
+
127
+ if (any(greaterThan(lightAmbient[i], zero_vec3))) {
128
+ totalAmbient += lightAmbient[i] * falloff;
129
+ }
130
+
131
+ if (any(greaterThan(lightDiffuse[i], zero_vec3))) {
132
+ totalFrontDiffuse += lightDiffuse[i] * falloff * spotf *
133
+ lambertFactor(lightDir, ecNormal);
134
+ totalBackDiffuse += lightDiffuse[i] * falloff * spotf *
135
+ lambertFactor(lightDir, ecNormalInv);
136
+ }
137
+
138
+ if (any(greaterThan(lightSpecular[i], zero_vec3))) {
139
+ totalFrontSpecular += lightSpecular[i] * falloff * spotf *
140
+ blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess);
141
+ totalBackSpecular += lightSpecular[i] * falloff * spotf *
142
+ blinnPhongFactor(lightDir, ecVertex, ecNormalInv, shininess);
143
+ }
144
+ }
145
+
146
+ // Calculating final color as result of all lights (plus emissive term).
147
+ // Transparency is determined exclusively by the diffuse component.
148
+ vertColor = vec4(totalAmbient, 0) * ambient +
149
+ vec4(totalFrontDiffuse, 1) * color +
150
+ vec4(totalFrontSpecular, 0) * specular +
151
+ vec4(emissive.rgb, 0);
152
+
153
+ backVertColor = vec4(totalAmbient, 0) * ambient +
154
+ vec4(totalBackDiffuse, 1) * color +
155
+ vec4(totalBackSpecular, 0) * specular +
156
+ vec4(emissive.rgb, 0);
157
+
158
+ // Calculating texture coordinates, with r and q set both to one
159
+ vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
160
+ }