picrate 0.0.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/.mvn/extensions.xml +9 -0
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE.md +165 -0
- data/README.md +51 -0
- data/Rakefile +59 -0
- data/bin/picrate +8 -0
- data/docs/.gitignore +6 -0
- data/docs/_config.yml +30 -0
- data/docs/_includes/footer.html +38 -0
- data/docs/_includes/head.html +16 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/icon-github.html +1 -0
- data/docs/_includes/icon-github.svg +1 -0
- data/docs/_includes/icon-twitter.html +1 -0
- data/docs/_includes/icon-twitter.svg +1 -0
- data/docs/_includes/navigation.html +24 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_posts/2018-05-06-getting_started.md +8 -0
- data/docs/_posts/2018-05-06-install_jruby.md +35 -0
- data/docs/_sass/_base.scss +206 -0
- data/docs/_sass/_layout.scss +242 -0
- data/docs/_sass/_syntax-highlighting.scss +71 -0
- data/docs/about.md +10 -0
- data/docs/css/main.scss +38 -0
- data/docs/favicon.ico +0 -0
- data/docs/feed.xml +30 -0
- data/docs/index.html +38 -0
- data/lib/picrate.rb +10 -0
- data/lib/picrate/app.rb +187 -0
- data/lib/picrate/creators/sketch_class.rb +57 -0
- data/lib/picrate/creators/sketch_factory.rb +12 -0
- data/lib/picrate/creators/sketch_writer.rb +21 -0
- data/lib/picrate/helper_methods.rb +214 -0
- data/lib/picrate/helpers/numeric.rb +9 -0
- data/lib/picrate/library.rb +69 -0
- data/lib/picrate/library_loader.rb +53 -0
- data/lib/picrate/native_folder.rb +35 -0
- data/lib/picrate/native_loader.rb +27 -0
- data/lib/picrate/runner.rb +81 -0
- data/lib/picrate/version.rb +4 -0
- data/library/boids/boids.rb +209 -0
- data/library/chooser/chooser.rb +19 -0
- data/library/control_panel/control_panel.rb +182 -0
- data/library/library_proxy/README.md +99 -0
- data/library/library_proxy/library_proxy.rb +14 -0
- data/library/slider/slider.rb +42 -0
- data/library/vector_utils/vector_utils.rb +69 -0
- data/library/video_event/video_event.rb +3 -0
- data/license.txt +508 -0
- data/picrate.gemspec +35 -0
- data/pom.rb +122 -0
- data/pom.xml +214 -0
- data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/main/java/monkstone/ColorUtil.java +115 -0
- data/src/main/java/monkstone/MathToolModule.java +236 -0
- data/src/main/java/monkstone/PicrateLibrary.java +47 -0
- data/src/main/java/monkstone/core/LibraryProxy.java +127 -0
- data/src/main/java/monkstone/fastmath/Deglut.java +122 -0
- data/src/main/java/monkstone/fastmath/package-info.java +6 -0
- data/src/main/java/monkstone/filechooser/Chooser.java +48 -0
- data/src/main/java/monkstone/noise/SimplexNoise.java +465 -0
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +168 -0
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +182 -0
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +149 -0
- data/src/main/java/monkstone/slider/SimpleSlider.java +196 -0
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +163 -0
- data/src/main/java/monkstone/slider/Slider.java +67 -0
- data/src/main/java/monkstone/slider/SliderBar.java +277 -0
- data/src/main/java/monkstone/slider/SliderGroup.java +78 -0
- data/src/main/java/monkstone/slider/WheelHandler.java +35 -0
- data/src/main/java/monkstone/vecmath/AppRender.java +87 -0
- data/src/main/java/monkstone/vecmath/JRender.java +56 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +87 -0
- data/src/main/java/monkstone/vecmath/package-info.java +20 -0
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +757 -0
- data/src/main/java/monkstone/vecmath/vec2/package-info.java +6 -0
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +727 -0
- data/src/main/java/monkstone/vecmath/vec3/package-info.java +6 -0
- data/src/main/java/monkstone/videoevent/VideoInterface.java +42 -0
- data/src/main/java/monkstone/videoevent/package-info.java +20 -0
- data/src/main/java/processing/awt/PGraphicsJava2D.java +3098 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +401 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +1660 -0
- data/src/main/java/processing/core/PApplet.java +17647 -0
- data/src/main/java/processing/core/PConstants.java +1033 -0
- data/src/main/java/processing/core/PFont.java +1250 -0
- data/src/main/java/processing/core/PGraphics.java +9614 -0
- data/src/main/java/processing/core/PImage.java +3608 -0
- data/src/main/java/processing/core/PMatrix.java +347 -0
- data/src/main/java/processing/core/PMatrix2D.java +694 -0
- data/src/main/java/processing/core/PMatrix3D.java +1153 -0
- data/src/main/java/processing/core/PShape.java +4332 -0
- data/src/main/java/processing/core/PShapeOBJ.java +544 -0
- data/src/main/java/processing/core/PShapeSVG.java +1987 -0
- data/src/main/java/processing/core/PStyle.java +208 -0
- data/src/main/java/processing/core/PSurface.java +242 -0
- data/src/main/java/processing/core/PSurfaceNone.java +479 -0
- data/src/main/java/processing/core/PVector.java +1140 -0
- data/src/main/java/processing/data/FloatDict.java +829 -0
- data/src/main/java/processing/data/FloatList.java +912 -0
- data/src/main/java/processing/data/IntDict.java +796 -0
- data/src/main/java/processing/data/IntList.java +913 -0
- data/src/main/java/processing/data/JSONArray.java +1260 -0
- data/src/main/java/processing/data/JSONObject.java +2282 -0
- data/src/main/java/processing/data/JSONTokener.java +435 -0
- data/src/main/java/processing/data/Sort.java +46 -0
- data/src/main/java/processing/data/StringDict.java +601 -0
- data/src/main/java/processing/data/StringList.java +775 -0
- data/src/main/java/processing/data/Table.java +4923 -0
- data/src/main/java/processing/data/TableRow.java +198 -0
- data/src/main/java/processing/data/XML.java +1149 -0
- data/src/main/java/processing/event/Event.java +108 -0
- data/src/main/java/processing/event/KeyEvent.java +70 -0
- data/src/main/java/processing/event/MouseEvent.java +149 -0
- data/src/main/java/processing/event/TouchEvent.java +57 -0
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +354 -0
- data/src/main/java/processing/opengl/FontTexture.java +379 -0
- data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
- data/src/main/java/processing/opengl/LinePath.java +623 -0
- data/src/main/java/processing/opengl/LineStroker.java +685 -0
- data/src/main/java/processing/opengl/PGL.java +3366 -0
- data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
- data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
- data/src/main/java/processing/opengl/PJOGL.java +1966 -0
- data/src/main/java/processing/opengl/PShader.java +1478 -0
- data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
- data/src/main/java/processing/opengl/Texture.java +1670 -0
- data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
- data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
- data/src/main/java/processing/opengl/cursors/cross.png +0 -0
- data/src/main/java/processing/opengl/cursors/hand.png +0 -0
- data/src/main/java/processing/opengl/cursors/license.txt +27 -0
- data/src/main/java/processing/opengl/cursors/move.png +0 -0
- data/src/main/java/processing/opengl/cursors/text.png +0 -0
- data/src/main/java/processing/opengl/cursors/wait.png +0 -0
- data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
- data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
- data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
- data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
- data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
- data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
- data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
- data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/src/main/resources/license.txt +508 -0
- data/test/create_test.rb +68 -0
- data/test/deglut_spec_test.rb +24 -0
- data/test/helper_methods_test.rb +58 -0
- data/test/math_tool_test.rb +75 -0
- data/test/respond_to_test.rb +215 -0
- data/test/sketches/key_event.rb +37 -0
- data/test/sketches/library/my_library/my_library.rb +32 -0
- data/test/test_helper.rb +3 -0
- data/test/vecmath_spec_test.rb +522 -0
- data/vendors/Rakefile +127 -0
- metadata +289 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
|
+
|
3
|
+
/*
|
4
|
+
Part of the Processing project - http://processing.org
|
5
|
+
|
6
|
+
Copyright (c) 2012-15 The Processing Foundation
|
7
|
+
Copyright (c) 2004-12 Ben Fry and Casey Reas
|
8
|
+
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
9
|
+
|
10
|
+
This library is free software; you can redistribute it and/or
|
11
|
+
modify it under the terms of the GNU Lesser General Public
|
12
|
+
License as published by the Free Software Foundation, version 2.1.
|
13
|
+
|
14
|
+
This library is distributed in the hope that it will be useful,
|
15
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
17
|
+
Lesser General Public License for more details.
|
18
|
+
|
19
|
+
You should have received a copy of the GNU Lesser General
|
20
|
+
Public License along with this library; if not, write to the
|
21
|
+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
22
|
+
Boston, MA 02111-1307 USA
|
23
|
+
*/
|
24
|
+
|
25
|
+
package processing.opengl;
|
26
|
+
|
27
|
+
import processing.opengl.PGraphicsOpenGL.GLResourceVertexBuffer;
|
28
|
+
|
29
|
+
// TODO: need to combine with PGraphicsOpenGL.VertexAttribute
|
30
|
+
public class VertexBuffer {
|
31
|
+
static protected final int INIT_VERTEX_BUFFER_SIZE = 256;
|
32
|
+
static protected final int INIT_INDEX_BUFFER_SIZE = 512;
|
33
|
+
|
34
|
+
public int glId;
|
35
|
+
int target;
|
36
|
+
int elementSize;
|
37
|
+
int ncoords;
|
38
|
+
boolean index;
|
39
|
+
|
40
|
+
protected PGL pgl; // The interface between Processing and OpenGL.
|
41
|
+
protected int context; // The context that created this texture.
|
42
|
+
private GLResourceVertexBuffer glres;
|
43
|
+
|
44
|
+
VertexBuffer(PGraphicsOpenGL pg, int target, int ncoords, int esize) {
|
45
|
+
this(pg, target, ncoords, esize, false);
|
46
|
+
}
|
47
|
+
|
48
|
+
VertexBuffer(PGraphicsOpenGL pg, int target, int ncoords, int esize, boolean index) {
|
49
|
+
pgl = pg.pgl;
|
50
|
+
context = pgl.createEmptyContext();
|
51
|
+
|
52
|
+
this.target = target;
|
53
|
+
this.ncoords = ncoords;
|
54
|
+
this.elementSize = esize;
|
55
|
+
this.index = index;
|
56
|
+
create();
|
57
|
+
init();
|
58
|
+
}
|
59
|
+
|
60
|
+
protected void create() {
|
61
|
+
context = pgl.getCurrentContext();
|
62
|
+
glres = new GLResourceVertexBuffer(this);
|
63
|
+
}
|
64
|
+
|
65
|
+
protected void init() {
|
66
|
+
int size = index ? ncoords * INIT_INDEX_BUFFER_SIZE * elementSize :
|
67
|
+
ncoords * INIT_VERTEX_BUFFER_SIZE * elementSize;
|
68
|
+
pgl.bindBuffer(target, glId);
|
69
|
+
pgl.bufferData(target, size, null, PGL.STATIC_DRAW);
|
70
|
+
}
|
71
|
+
|
72
|
+
protected void dispose() {
|
73
|
+
if (glres != null) {
|
74
|
+
glres.dispose();
|
75
|
+
glId = 0;
|
76
|
+
glres = null;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
protected boolean contextIsOutdated() {
|
81
|
+
boolean outdated = !pgl.contextIsCurrent(context);
|
82
|
+
if (outdated) {
|
83
|
+
dispose();
|
84
|
+
}
|
85
|
+
return outdated;
|
86
|
+
}
|
87
|
+
|
88
|
+
}
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,27 @@
|
|
1
|
+
These files are based on the DMZ Cursors package,
|
2
|
+
used with permission from Jakub Steiner <jimmac@gmail.com>
|
3
|
+
11 September 2015
|
4
|
+
|
5
|
+
|
6
|
+
The MIT License (MIT)
|
7
|
+
|
8
|
+
Copyright (c) 2006 Jakub Steiner <jimmac@novell.com>
|
9
|
+
Copyright (c) 2006 Novell, Inc.
|
10
|
+
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
13
|
+
in the Software without restriction, including without limitation the rights
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
16
|
+
furnished to do so, subject to the following conditions:
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be included in
|
19
|
+
all copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
27
|
+
THE SOFTWARE.
|
Binary file
|
Binary file
|
Binary file
|
@@ -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,34 @@
|
|
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 transformMatrix;
|
24
|
+
|
25
|
+
attribute vec4 position;
|
26
|
+
attribute vec4 color;
|
27
|
+
|
28
|
+
varying vec4 vertColor;
|
29
|
+
|
30
|
+
void main() {
|
31
|
+
gl_Position = transformMatrix * position;
|
32
|
+
|
33
|
+
vertColor = color;
|
34
|
+
}
|
@@ -0,0 +1,33 @@
|
|
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
|
+
varying vec4 backVertColor;
|
30
|
+
|
31
|
+
void main() {
|
32
|
+
gl_FragColor = gl_FrontFacing ? vertColor : backVertColor;
|
33
|
+
}
|
@@ -0,0 +1,154 @@
|
|
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
|
+
|
27
|
+
uniform int lightCount;
|
28
|
+
uniform vec4 lightPosition[8];
|
29
|
+
uniform vec3 lightNormal[8];
|
30
|
+
uniform vec3 lightAmbient[8];
|
31
|
+
uniform vec3 lightDiffuse[8];
|
32
|
+
uniform vec3 lightSpecular[8];
|
33
|
+
uniform vec3 lightFalloff[8];
|
34
|
+
uniform vec2 lightSpot[8];
|
35
|
+
|
36
|
+
attribute vec4 position;
|
37
|
+
attribute vec4 color;
|
38
|
+
attribute vec3 normal;
|
39
|
+
|
40
|
+
attribute vec4 ambient;
|
41
|
+
attribute vec4 specular;
|
42
|
+
attribute vec4 emissive;
|
43
|
+
attribute float shininess;
|
44
|
+
|
45
|
+
varying vec4 vertColor;
|
46
|
+
varying vec4 backVertColor;
|
47
|
+
|
48
|
+
const float zero_float = 0.0;
|
49
|
+
const float one_float = 1.0;
|
50
|
+
const vec3 zero_vec3 = vec3(0.0);
|
51
|
+
const vec3 minus_one_vec3 = vec3(0.0-1.0);
|
52
|
+
|
53
|
+
float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) {
|
54
|
+
vec3 lpv = lightPos - vertPos;
|
55
|
+
vec3 dist = vec3(one_float);
|
56
|
+
dist.z = dot(lpv, lpv);
|
57
|
+
dist.y = sqrt(dist.z);
|
58
|
+
return one_float / dot(dist, coeff);
|
59
|
+
}
|
60
|
+
|
61
|
+
float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) {
|
62
|
+
vec3 lpv = normalize(lightPos - vertPos);
|
63
|
+
vec3 nln = minus_one_vec3 * lightNorm;
|
64
|
+
float spotCos = dot(nln, lpv);
|
65
|
+
return spotCos <= minCos ? zero_float : pow(spotCos, spotExp);
|
66
|
+
}
|
67
|
+
|
68
|
+
float lambertFactor(vec3 lightDir, vec3 vecNormal) {
|
69
|
+
return max(zero_float, dot(lightDir, vecNormal));
|
70
|
+
}
|
71
|
+
|
72
|
+
float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine) {
|
73
|
+
vec3 np = normalize(vertPos);
|
74
|
+
vec3 ldp = normalize(lightDir - np);
|
75
|
+
return pow(max(zero_float, dot(ldp, vecNormal)), shine);
|
76
|
+
}
|
77
|
+
|
78
|
+
void main() {
|
79
|
+
// Vertex in clip coordinates
|
80
|
+
gl_Position = transformMatrix * position;
|
81
|
+
|
82
|
+
// Vertex in eye coordinates
|
83
|
+
vec3 ecVertex = vec3(modelviewMatrix * position);
|
84
|
+
|
85
|
+
// Normal vector in eye coordinates
|
86
|
+
vec3 ecNormal = normalize(normalMatrix * normal);
|
87
|
+
vec3 ecNormalInv = ecNormal * minus_one_vec3;
|
88
|
+
|
89
|
+
// Light calculations
|
90
|
+
vec3 totalAmbient = vec3(0, 0, 0);
|
91
|
+
|
92
|
+
vec3 totalFrontDiffuse = vec3(0, 0, 0);
|
93
|
+
vec3 totalFrontSpecular = vec3(0, 0, 0);
|
94
|
+
|
95
|
+
vec3 totalBackDiffuse = vec3(0, 0, 0);
|
96
|
+
vec3 totalBackSpecular = vec3(0, 0, 0);
|
97
|
+
|
98
|
+
// prevent register allocation failure by limiting ourselves to
|
99
|
+
// two lights for now
|
100
|
+
for (int i = 0; i < 2; i++) {
|
101
|
+
if (lightCount == i) break;
|
102
|
+
|
103
|
+
vec3 lightPos = lightPosition[i].xyz;
|
104
|
+
bool isDir = lightPosition[i].w < one_float;
|
105
|
+
float spotCos = lightSpot[i].x;
|
106
|
+
float spotExp = lightSpot[i].y;
|
107
|
+
|
108
|
+
vec3 lightDir;
|
109
|
+
float falloff;
|
110
|
+
float spotf;
|
111
|
+
|
112
|
+
if (isDir) {
|
113
|
+
falloff = one_float;
|
114
|
+
lightDir = minus_one_vec3 * lightNormal[i];
|
115
|
+
} else {
|
116
|
+
falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]);
|
117
|
+
lightDir = normalize(lightPos - ecVertex);
|
118
|
+
}
|
119
|
+
|
120
|
+
spotf = spotExp > zero_float ? spotFactor(lightPos, ecVertex, lightNormal[i],
|
121
|
+
spotCos, spotExp)
|
122
|
+
: one_float;
|
123
|
+
|
124
|
+
if (any(greaterThan(lightAmbient[i], zero_vec3))) {
|
125
|
+
totalAmbient += lightAmbient[i] * falloff;
|
126
|
+
}
|
127
|
+
|
128
|
+
if (any(greaterThan(lightDiffuse[i], zero_vec3))) {
|
129
|
+
totalFrontDiffuse += lightDiffuse[i] * falloff * spotf *
|
130
|
+
lambertFactor(lightDir, ecNormal);
|
131
|
+
totalBackDiffuse += lightDiffuse[i] * falloff * spotf *
|
132
|
+
lambertFactor(lightDir, ecNormalInv);
|
133
|
+
}
|
134
|
+
|
135
|
+
if (any(greaterThan(lightSpecular[i], zero_vec3))) {
|
136
|
+
totalFrontSpecular += lightSpecular[i] * falloff * spotf *
|
137
|
+
blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess);
|
138
|
+
totalBackSpecular += lightSpecular[i] * falloff * spotf *
|
139
|
+
blinnPhongFactor(lightDir, ecVertex, ecNormalInv, shininess);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
// Calculating final color as result of all lights (plus emissive term).
|
144
|
+
// Transparency is determined exclusively by the diffuse component.
|
145
|
+
vertColor = vec4(totalAmbient, 0) * ambient +
|
146
|
+
vec4(totalFrontDiffuse, 1) * color +
|
147
|
+
vec4(totalFrontSpecular, 0) * specular +
|
148
|
+
vec4(emissive.rgb, 0);
|
149
|
+
|
150
|
+
backVertColor = vec4(totalAmbient, 0) * ambient +
|
151
|
+
vec4(totalBackDiffuse, 1) * color +
|
152
|
+
vec4(totalBackSpecular, 0) * specular +
|
153
|
+
vec4(emissive.rgb, 0);
|
154
|
+
}
|
@@ -0,0 +1,151 @@
|
|
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
|
+
|
27
|
+
uniform int lightCount;
|
28
|
+
uniform vec4 lightPosition[8];
|
29
|
+
uniform vec3 lightNormal[8];
|
30
|
+
uniform vec3 lightAmbient[8];
|
31
|
+
uniform vec3 lightDiffuse[8];
|
32
|
+
uniform vec3 lightSpecular[8];
|
33
|
+
uniform vec3 lightFalloff[8];
|
34
|
+
uniform vec2 lightSpot[8];
|
35
|
+
|
36
|
+
attribute vec4 position;
|
37
|
+
attribute vec4 color;
|
38
|
+
attribute vec3 normal;
|
39
|
+
|
40
|
+
attribute vec4 ambient;
|
41
|
+
attribute vec4 specular;
|
42
|
+
attribute vec4 emissive;
|
43
|
+
attribute float shininess;
|
44
|
+
|
45
|
+
varying vec4 vertColor;
|
46
|
+
varying vec4 backVertColor;
|
47
|
+
|
48
|
+
const float zero_float = 0.0;
|
49
|
+
const float one_float = 1.0;
|
50
|
+
const vec3 zero_vec3 = vec3(0);
|
51
|
+
|
52
|
+
float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) {
|
53
|
+
vec3 lpv = lightPos - vertPos;
|
54
|
+
vec3 dist = vec3(one_float);
|
55
|
+
dist.z = dot(lpv, lpv);
|
56
|
+
dist.y = sqrt(dist.z);
|
57
|
+
return one_float / dot(dist, coeff);
|
58
|
+
}
|
59
|
+
|
60
|
+
float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) {
|
61
|
+
vec3 lpv = normalize(lightPos - vertPos);
|
62
|
+
vec3 nln = -one_float * lightNorm;
|
63
|
+
float spotCos = dot(nln, lpv);
|
64
|
+
return spotCos <= minCos ? zero_float : pow(spotCos, spotExp);
|
65
|
+
}
|
66
|
+
|
67
|
+
float lambertFactor(vec3 lightDir, vec3 vecNormal) {
|
68
|
+
return max(zero_float, dot(lightDir, vecNormal));
|
69
|
+
}
|
70
|
+
|
71
|
+
float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine) {
|
72
|
+
vec3 np = normalize(vertPos);
|
73
|
+
vec3 ldp = normalize(lightDir - np);
|
74
|
+
return pow(max(zero_float, dot(ldp, vecNormal)), shine);
|
75
|
+
}
|
76
|
+
|
77
|
+
void main() {
|
78
|
+
// Vertex in clip coordinates
|
79
|
+
gl_Position = transformMatrix * position;
|
80
|
+
|
81
|
+
// Vertex in eye coordinates
|
82
|
+
vec3 ecVertex = vec3(modelviewMatrix * position);
|
83
|
+
|
84
|
+
// Normal vector in eye coordinates
|
85
|
+
vec3 ecNormal = normalize(normalMatrix * normal);
|
86
|
+
vec3 ecNormalInv = ecNormal * -one_float;
|
87
|
+
|
88
|
+
// Light calculations
|
89
|
+
vec3 totalAmbient = vec3(0, 0, 0);
|
90
|
+
|
91
|
+
vec3 totalFrontDiffuse = vec3(0, 0, 0);
|
92
|
+
vec3 totalFrontSpecular = vec3(0, 0, 0);
|
93
|
+
|
94
|
+
vec3 totalBackDiffuse = vec3(0, 0, 0);
|
95
|
+
vec3 totalBackSpecular = vec3(0, 0, 0);
|
96
|
+
|
97
|
+
for (int i = 0; i < 8; i++) {
|
98
|
+
if (lightCount == i) break;
|
99
|
+
|
100
|
+
vec3 lightPos = lightPosition[i].xyz;
|
101
|
+
bool isDir = lightPosition[i].w < one_float;
|
102
|
+
float spotCos = lightSpot[i].x;
|
103
|
+
float spotExp = lightSpot[i].y;
|
104
|
+
|
105
|
+
vec3 lightDir;
|
106
|
+
float falloff;
|
107
|
+
float spotf;
|
108
|
+
|
109
|
+
if (isDir) {
|
110
|
+
falloff = one_float;
|
111
|
+
lightDir = -one_float * lightNormal[i];
|
112
|
+
} else {
|
113
|
+
falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]);
|
114
|
+
lightDir = normalize(lightPos - ecVertex);
|
115
|
+
}
|
116
|
+
|
117
|
+
spotf = spotExp > zero_float ? spotFactor(lightPos, ecVertex, lightNormal[i],
|
118
|
+
spotCos, spotExp)
|
119
|
+
: one_float;
|
120
|
+
|
121
|
+
if (any(greaterThan(lightAmbient[i], zero_vec3))) {
|
122
|
+
totalAmbient += lightAmbient[i] * falloff;
|
123
|
+
}
|
124
|
+
|
125
|
+
if (any(greaterThan(lightDiffuse[i], zero_vec3))) {
|
126
|
+
totalFrontDiffuse += lightDiffuse[i] * falloff * spotf *
|
127
|
+
lambertFactor(lightDir, ecNormal);
|
128
|
+
totalBackDiffuse += lightDiffuse[i] * falloff * spotf *
|
129
|
+
lambertFactor(lightDir, ecNormalInv);
|
130
|
+
}
|
131
|
+
|
132
|
+
if (any(greaterThan(lightSpecular[i], zero_vec3))) {
|
133
|
+
totalFrontSpecular += lightSpecular[i] * falloff * spotf *
|
134
|
+
blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess);
|
135
|
+
totalBackSpecular += lightSpecular[i] * falloff * spotf *
|
136
|
+
blinnPhongFactor(lightDir, ecVertex, ecNormalInv, shininess);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
// Calculating final color as result of all lights (plus emissive term).
|
141
|
+
// Transparency is determined exclusively by the diffuse component.
|
142
|
+
vertColor = vec4(totalAmbient, 0) * ambient +
|
143
|
+
vec4(totalFrontDiffuse, 1) * color +
|
144
|
+
vec4(totalFrontSpecular, 0) * specular +
|
145
|
+
vec4(emissive.rgb, 0);
|
146
|
+
|
147
|
+
backVertColor = vec4(totalAmbient, 0) * ambient +
|
148
|
+
vec4(totalBackDiffuse, 1) * color +
|
149
|
+
vec4(totalBackSpecular, 0) * specular +
|
150
|
+
vec4(emissive.rgb, 0);
|
151
|
+
}
|