picrate 2.0.0.pre-java → 2.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/CHANGELOG.md +10 -0
  6. data/README.md +11 -9
  7. data/Rakefile +9 -8
  8. data/docs/_config.yml +1 -1
  9. data/docs/_editors/geany.md +1 -0
  10. data/docs/_gems/gems/gems.md +1 -1
  11. data/docs/_methods/alternative_methods.md +2 -1
  12. data/docs/_posts/2018-05-06-getting_started.md +4 -4
  13. data/docs/_posts/2018-05-06-install_jruby.md +5 -11
  14. data/docs/_posts/2018-05-11-arch-linux-arm.md +1 -11
  15. data/docs/_posts/2018-11-18-building-gem.md +4 -2
  16. data/docs/_posts/2018-11-27-getting_started_geany.md +1 -1
  17. data/docs/_posts/2019-11-11-getting_started_buster.md +4 -7
  18. data/docs/_posts/{2018-06-26-auto_install_picrate.md → 2020-03-09-auto_install_picrate.md} +9 -6
  19. data/docs/_posts/2020-05-11-getting_started_manjaro.md +106 -0
  20. data/docs/about.md +1 -1
  21. data/lib/picrate.rb +2 -1
  22. data/lib/picrate/app.rb +1 -0
  23. data/lib/picrate/helper_methods.rb +1 -1
  24. data/lib/picrate/native_folder.rb +6 -7
  25. data/lib/picrate/runner.rb +4 -4
  26. data/lib/picrate/version.rb +1 -1
  27. data/library/jcomplex/jcomplex.rb +1 -0
  28. data/mvnw +2 -2
  29. data/mvnw.cmd +2 -2
  30. data/picrate.gemspec +3 -5
  31. data/pom.rb +18 -15
  32. data/pom.xml +20 -8
  33. data/src/main/java/monkstone/complex/JComplex.java +252 -0
  34. data/src/main/java/processing/awt/PGraphicsJava2D.java +22 -23
  35. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  36. data/src/main/java/processing/awt/ShimAWT.java +545 -0
  37. data/src/main/java/processing/core/PApplet.java +2030 -2556
  38. data/src/main/java/processing/core/PGraphics.java +138 -124
  39. data/src/main/java/processing/core/PImage.java +1517 -1702
  40. data/src/main/java/processing/core/PSurface.java +105 -139
  41. data/src/main/java/processing/core/PSurfaceNone.java +29 -0
  42. data/src/main/java/processing/opengl/PGL.java +649 -3699
  43. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +223 -184
  44. data/src/main/java/processing/opengl/PJOGL.java +374 -1526
  45. data/src/main/java/processing/opengl/PShapeOpenGL.java +5 -6
  46. data/src/main/java/processing/opengl/PSurfaceJOGL.java +220 -86
  47. data/vendors/Rakefile +33 -21
  48. data/vendors/{picrate_sketches.geany → geany.rb} +32 -7
  49. metadata +17 -48
  50. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  51. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  52. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  53. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,3 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ def geany_config
6
+ %(
1
7
  [editor]
2
8
  line_wrapping=false
3
9
  line_break_column=72
@@ -19,7 +25,7 @@ indent_mode=2
19
25
 
20
26
  [project]
21
27
  name=picrate_samples
22
- base_path=/home/pi/projects/picrate_sketches
28
+ base_path=examples
23
29
  description=Exploring PiCrate
24
30
  file_patterns=*.rb;*.glsl;*.txt;
25
31
 
@@ -28,14 +34,9 @@ long_line_behaviour=1
28
34
  long_line_column=72
29
35
 
30
36
  [files]
31
- current_page=3
32
- FILE_NAME_0=667;Ruby;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fprojects%2Fpicrate_sketches%2Fbasics%2Farrays%2Farray.rb;0;2
33
- FILE_NAME_1=1664;Ruby;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fprojects%2Fpicrate_sketches%2Fadvanced_data%2Fload_save_json.rb;0;2
34
- FILE_NAME_2=259;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fjruby_install.sh;0;2
35
- FILE_NAME_3=236;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Ftest.sh;0;2
36
37
 
37
38
  [VTE]
38
- last_dir=/home/pi
39
+ last_dir=<%= directory %>
39
40
 
40
41
  [build-menu]
41
42
  EX_00_LB=_Execute
@@ -60,3 +61,27 @@ NF_02_WD=
60
61
  RubyFT_02_LB=_Reek
61
62
  RubyFT_02_CM=reek --failure-exit-code=0 "%f"
62
63
  RubyFT_02_WD=
64
+ )
65
+ end
66
+
67
+ # Class to merge ERB template and write config to file
68
+ class GeanyConfig
69
+ include ERB::Util
70
+ attr_accessor :home, :directory, :template
71
+
72
+ def initialize(directory, template = geany_config)
73
+ @home = home
74
+ @directory = directory
75
+ @template = template
76
+ end
77
+
78
+ def render
79
+ ERB.new(@template).result(binding)
80
+ end
81
+
82
+ def save(file)
83
+ File.open(file, 'w+') do |f|
84
+ f.write(render)
85
+ end
86
+ end
87
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre
4
+ version: 2.2.0
5
5
  platform: java
6
6
  authors:
7
7
  - monkstone
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-07 00:00:00.000000000 Z
11
+ date: 2021-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -29,15 +29,15 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '12.3'
32
+ version: '13.0'
33
33
  name: rake
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '12.3'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
@@ -58,40 +58,6 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 1.0.1
61
- - !ruby/object:Gem::Dependency
62
- requirement: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '1.1'
67
- name: geomerative
68
- type: :runtime
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '1.1'
75
- - !ruby/object:Gem::Dependency
76
- requirement: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - "~>"
79
- - !ruby/object:Gem::Version
80
- version: '2.0'
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: 2.0.4
84
- name: ruby_wordcram
85
- type: :runtime
86
- prerelease: false
87
- version_requirements: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - "~>"
90
- - !ruby/object:Gem::Version
91
- version: '2.0'
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- version: 2.0.4
95
61
  description: |
96
62
  A batteries included version of processing in ruby, for raspberrypi and
97
63
  linux. Install samples to configures geany ide.
@@ -182,10 +148,11 @@ files:
182
148
  - docs/_posts/2018-05-06-install_jruby.md
183
149
  - docs/_posts/2018-05-06-processing-api.md
184
150
  - docs/_posts/2018-05-11-arch-linux-arm.md
185
- - docs/_posts/2018-06-26-auto_install_picrate.md
186
151
  - docs/_posts/2018-11-18-building-gem.md
187
152
  - docs/_posts/2018-11-27-getting_started_geany.md
188
153
  - docs/_posts/2019-11-11-getting_started_buster.md
154
+ - docs/_posts/2020-03-09-auto_install_picrate.md
155
+ - docs/_posts/2020-05-11-getting_started_manjaro.md
189
156
  - docs/_sass/_base.scss
190
157
  - docs/_sass/_layout.scss
191
158
  - docs/_sass/_syntax-highlighting.scss
@@ -215,13 +182,15 @@ files:
215
182
  - docs/modules.md
216
183
  - docs/objects.md
217
184
  - lib/export.txt
185
+ - lib/gluegen-rt-natives-linux-aarch64.jar
218
186
  - lib/gluegen-rt-natives-linux-amd64.jar
219
187
  - lib/gluegen-rt-natives-linux-armv6hf.jar
220
188
  - lib/gluegen-rt.jar
189
+ - lib/jogl-all-natives-linux-aarch64.jar
221
190
  - lib/jogl-all-natives-linux-amd64.jar
222
191
  - lib/jogl-all-natives-linux-armv6hf.jar
223
192
  - lib/jogl-all.jar
224
- - lib/picrate-2.0.0.pre.jar
193
+ - lib/picrate-2.2.0.jar
225
194
  - lib/picrate.rb
226
195
  - lib/picrate/app.rb
227
196
  - lib/picrate/creators/parameters.rb
@@ -240,6 +209,7 @@ files:
240
209
  - library/color_group/color_group.rb
241
210
  - library/control_panel/control_panel.rb
242
211
  - library/dxf/dxf.rb
212
+ - library/jcomplex/jcomplex.rb
243
213
  - library/library_proxy/README.md
244
214
  - library/library_proxy/library_proxy.rb
245
215
  - library/net/net.rb
@@ -257,6 +227,7 @@ files:
257
227
  - src/main/java/monkstone/ColorUtil.java
258
228
  - src/main/java/monkstone/MathToolModule.java
259
229
  - src/main/java/monkstone/PicrateLibrary.java
230
+ - src/main/java/monkstone/complex/JComplex.java
260
231
  - src/main/java/monkstone/core/LibraryProxy.java
261
232
  - src/main/java/monkstone/fastmath/Deglut.java
262
233
  - src/main/java/monkstone/fastmath/package-info.java
@@ -284,8 +255,10 @@ files:
284
255
  - src/main/java/monkstone/videoevent/MovieEvent.java
285
256
  - src/main/java/monkstone/videoevent/package-info.java
286
257
  - src/main/java/processing/awt/PGraphicsJava2D.java
258
+ - src/main/java/processing/awt/PImageAWT.java
287
259
  - src/main/java/processing/awt/PShapeJava2D.java
288
260
  - src/main/java/processing/awt/PSurfaceAWT.java
261
+ - src/main/java/processing/awt/ShimAWT.java
289
262
  - src/main/java/processing/core/PApplet.java
290
263
  - src/main/java/processing/core/PConstants.java
291
264
  - src/main/java/processing/core/PFont.java
@@ -346,8 +319,6 @@ files:
346
319
  - src/main/java/processing/opengl/shaders/ColorFrag.glsl
347
320
  - src/main/java/processing/opengl/shaders/ColorVert.glsl
348
321
  - src/main/java/processing/opengl/shaders/LightFrag.glsl
349
- - src/main/java/processing/opengl/shaders/LightVert-brcm.glsl
350
- - src/main/java/processing/opengl/shaders/LightVert-vc4.glsl
351
322
  - src/main/java/processing/opengl/shaders/LightVert.glsl
352
323
  - src/main/java/processing/opengl/shaders/LineFrag.glsl
353
324
  - src/main/java/processing/opengl/shaders/LineVert.glsl
@@ -356,8 +327,6 @@ files:
356
327
  - src/main/java/processing/opengl/shaders/PointVert.glsl
357
328
  - src/main/java/processing/opengl/shaders/TexFrag.glsl
358
329
  - src/main/java/processing/opengl/shaders/TexLightFrag.glsl
359
- - src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl
360
- - src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl
361
330
  - src/main/java/processing/opengl/shaders/TexLightVert.glsl
362
331
  - src/main/java/processing/opengl/shaders/TexVert.glsl
363
332
  - src/main/resources/icon/icon-128.png
@@ -378,8 +347,8 @@ files:
378
347
  - test/test_helper.rb
379
348
  - test/vecmath_spec_test.rb
380
349
  - vendors/Rakefile
350
+ - vendors/geany.rb
381
351
  - vendors/picrate.rb
382
- - vendors/picrate_sketches.geany
383
352
  homepage: https://ruby-processing.github.io/PiCrate/
384
353
  licenses:
385
354
  - GPL-3.0
@@ -396,9 +365,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
396
365
  version: '0'
397
366
  required_rubygems_version: !ruby/object:Gem::Requirement
398
367
  requirements:
399
- - - ">"
368
+ - - ">="
400
369
  - !ruby/object:Gem::Version
401
- version: 1.3.1
370
+ version: '0'
402
371
  requirements:
403
372
  - java runtime == 11+
404
373
  rubygems_version: 3.0.6
@@ -1,154 +0,0 @@
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
- }
@@ -1,154 +0,0 @@
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
- // four lights for now
100
- for (int i = 0; i < 4; 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
- }