picrate 2.0.0.pre-java → 2.0.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/README.md +7 -8
- data/Rakefile +9 -8
- data/docs/_config.yml +1 -1
- data/docs/_editors/geany.md +1 -0
- data/docs/_gems/gems/gems.md +1 -1
- data/docs/_posts/2018-05-06-getting_started.md +4 -4
- data/docs/_posts/2018-05-06-install_jruby.md +3 -9
- data/docs/_posts/2018-05-11-arch-linux-arm.md +1 -11
- data/docs/_posts/2018-11-18-building-gem.md +2 -2
- data/docs/_posts/2018-11-27-getting_started_geany.md +1 -1
- data/docs/_posts/2019-11-11-getting_started_buster.md +4 -7
- data/docs/_posts/2020-03-09-auto_install_picrate.md +34 -0
- data/docs/_posts/2020-05-11-getting_started_manjaro.md +94 -0
- data/docs/about.md +1 -1
- data/lib/picrate/app.rb +1 -0
- data/lib/picrate/native_folder.rb +6 -7
- data/lib/picrate/version.rb +1 -1
- data/picrate.gemspec +3 -5
- data/pom.rb +19 -17
- data/pom.xml +17 -5
- data/src/main/java/processing/core/PApplet.java +198 -198
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +2138 -2324
- data/src/main/java/processing/opengl/PShapeOpenGL.java +5 -6
- metadata +10 -45
- data/docs/_posts/2018-06-26-auto_install_picrate.md +0 -30
- data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1756,7 +1756,7 @@ public class PShapeOpenGL extends PShape {
|
|
1756
1756
|
}
|
1757
1757
|
|
1758
1758
|
VertexAttribute attrib = polyAttribs.get(name);
|
1759
|
-
float[] array = inGeo.fattribs.get(name);
|
1759
|
+
float[] array = (float[]) inGeo.fattribs.get(name);
|
1760
1760
|
for (int i = 0; i < values.length; i++) {
|
1761
1761
|
array[attrib.size * index + 0] = values[i];
|
1762
1762
|
}
|
@@ -1772,7 +1772,7 @@ public class PShapeOpenGL extends PShape {
|
|
1772
1772
|
}
|
1773
1773
|
|
1774
1774
|
VertexAttribute attrib = polyAttribs.get(name);
|
1775
|
-
int[] array = inGeo.iattribs.get(name);
|
1775
|
+
int[] array = (int[]) inGeo.iattribs.get(name);
|
1776
1776
|
for (int i = 0; i < values.length; i++) {
|
1777
1777
|
array[attrib.size * index + 0] = values[i];
|
1778
1778
|
}
|
@@ -1788,7 +1788,7 @@ public class PShapeOpenGL extends PShape {
|
|
1788
1788
|
}
|
1789
1789
|
|
1790
1790
|
VertexAttribute attrib = polyAttribs.get(name);
|
1791
|
-
byte[] array = inGeo.battribs.get(name);
|
1791
|
+
byte[] array = (byte[]) inGeo.battribs.get(name);
|
1792
1792
|
for (int i = 0; i < values.length; i++) {
|
1793
1793
|
array[attrib.size * index + 0] = (byte)(values[i]?1:0);
|
1794
1794
|
}
|
@@ -3968,8 +3968,7 @@ public class PShapeOpenGL extends PShape {
|
|
3968
3968
|
tessGeo.updateAttribBuffer(attrib.name);
|
3969
3969
|
if (!attrib.bufferCreated()) attrib.createBuffer(pgl);
|
3970
3970
|
pgl.bindBuffer(PGL.ARRAY_BUFFER, attrib.buf.glId);
|
3971
|
-
pgl.bufferData(PGL.ARRAY_BUFFER, attrib.sizeInBytes(size),
|
3972
|
-
tessGeo.polyAttribBuffers.get(name), glUsage);
|
3971
|
+
pgl.bufferData(PGL.ARRAY_BUFFER, attrib.sizeInBytes(size), (Buffer) tessGeo.polyAttribBuffers.get(name), glUsage);
|
3973
3972
|
}
|
3974
3973
|
|
3975
3974
|
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
|
@@ -4333,7 +4332,7 @@ public class PShapeOpenGL extends PShape {
|
|
4333
4332
|
protected void copyPolyAttrib(VertexAttribute attrib, int offset, int size) {
|
4334
4333
|
tessGeo.updateAttribBuffer(attrib.name, offset, size);
|
4335
4334
|
pgl.bindBuffer(PGL.ARRAY_BUFFER, attrib.buf.glId);
|
4336
|
-
Buffer buf = tessGeo.polyAttribBuffers.get(attrib.name);
|
4335
|
+
Buffer buf = (Buffer) tessGeo.polyAttribBuffers.get(attrib.name);
|
4337
4336
|
buf.position(attrib.size * offset);
|
4338
4337
|
pgl.bufferSubData(PGL.ARRAY_BUFFER, attrib.sizeInBytes(offset),
|
4339
4338
|
attrib.sizeInBytes(size), buf);
|
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.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- monkstone
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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.
|
193
|
+
- lib/picrate-2.0.1.jar
|
225
194
|
- lib/picrate.rb
|
226
195
|
- lib/picrate/app.rb
|
227
196
|
- lib/picrate/creators/parameters.rb
|
@@ -346,8 +315,6 @@ files:
|
|
346
315
|
- src/main/java/processing/opengl/shaders/ColorFrag.glsl
|
347
316
|
- src/main/java/processing/opengl/shaders/ColorVert.glsl
|
348
317
|
- 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
318
|
- src/main/java/processing/opengl/shaders/LightVert.glsl
|
352
319
|
- src/main/java/processing/opengl/shaders/LineFrag.glsl
|
353
320
|
- src/main/java/processing/opengl/shaders/LineVert.glsl
|
@@ -356,8 +323,6 @@ files:
|
|
356
323
|
- src/main/java/processing/opengl/shaders/PointVert.glsl
|
357
324
|
- src/main/java/processing/opengl/shaders/TexFrag.glsl
|
358
325
|
- 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
326
|
- src/main/java/processing/opengl/shaders/TexLightVert.glsl
|
362
327
|
- src/main/java/processing/opengl/shaders/TexVert.glsl
|
363
328
|
- src/main/resources/icon/icon-128.png
|
@@ -396,11 +361,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
396
361
|
version: '0'
|
397
362
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
398
363
|
requirements:
|
399
|
-
- - "
|
364
|
+
- - ">="
|
400
365
|
- !ruby/object:Gem::Version
|
401
|
-
version:
|
366
|
+
version: '0'
|
402
367
|
requirements:
|
403
|
-
- java runtime == 11
|
368
|
+
- java runtime == 11
|
404
369
|
rubygems_version: 3.0.6
|
405
370
|
signing_key:
|
406
371
|
specification_version: 4
|
@@ -1,30 +0,0 @@
|
|
1
|
-
---
|
2
|
-
layout: post
|
3
|
-
title: "Automated PiCrate Install"
|
4
|
-
date: 2018-06-26 07:34:13
|
5
|
-
categories: PiCrate update
|
6
|
-
permalink: /install_picrate/
|
7
|
-
---
|
8
|
-
|
9
|
-
For a semi-automated setup and install, download and extract [this gist](https://gist.github.com/monkstone/e9df8ea776aed58ce1c4de8e12982aad). To keep your system clean put the file in a folder say
|
10
|
-
`~/install_picrate`
|
11
|
-
|
12
|
-
```bash
|
13
|
-
cd ~/picrate_install
|
14
|
-
bash picrate_install.sh # to run default task
|
15
|
-
```
|
16
|
-
#### What the script does ###
|
17
|
-
1. Downloads JRuby
|
18
|
-
2. Installs JRuby to `/opt`
|
19
|
-
3. Uses `update-alternatives` to configure `jruby`, `jgem` and `jirb`
|
20
|
-
4. The script checks for `GEM_HOME`, if undefined it modifies `~/.profile` to define `GEM_HOME` and puts gem binaries on your path, at logon.
|
21
|
-
5. Installs `picrate` gem
|
22
|
-
6. Downloads and installs `picrate_samples` also configures `geanyIDE` for use with `picrate`
|
23
|
-
|
24
|
-
#### Note ####
|
25
|
-
`GEM_HOME` and path to `gem` binaries is not available until next logon, to use immediately you could:-
|
26
|
-
|
27
|
-
```bash
|
28
|
-
source ~/.profile
|
29
|
-
```
|
30
|
-
NB: this only works in current shell, so if you want to use `geanyIDE` you should logout and logon again.
|
@@ -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
|
-
}
|