Skip to content

Commit 8de9a4c

Browse files
Added core-androidx source assets
1 parent 60212f2 commit 8de9a4c

15 files changed

+815
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Part of the Processing project - http://processing.org
3+
4+
Copyright (c) 2012-16 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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Part of the Processing project - http://processing.org
3+
4+
Copyright (c) 2012-16 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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Part of the Processing project - http://processing.org
3+
4+
Copyright (c) 2012-16 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+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
Part of the Processing project - http://processing.org
3+
4+
Copyright (c) 2012-16 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+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Part of the Processing project - http://processing.org
3+
4+
Copyright (c) 2012-16 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+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
Part of the Processing project - http://processing.org
3+
4+
Copyright (c) 2012-17 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+
// don't normalize zero vector (line join triangles and lines perpendicular to the eye plane)
76+
tangent = length(tangent) == 0.0 ? vec2(0.0, 0.0) : normalize(tangent);
77+
78+
// flip tangent to normal (it's already normalized)
79+
vec2 normal = vec2(-tangent.y, tangent.x);
80+
81+
float thickness = direction.w;
82+
vec2 offset = normal * thickness;
83+
84+
// Perspective ---
85+
// convert from world to clip by multiplying with projection scaling factor
86+
// to get the right thickness (see https://github.com/processing/processing/issues/5182)
87+
// invert Y, projections in Processing invert Y
88+
vec2 perspScale = (projectionMatrix * vec4(1, -1, 0, 0)).xy;
89+
90+
// No Perspective ---
91+
// multiply by W (to cancel out division by W later in the pipeline) and
92+
// convert from screen to clip (derived from clip to screen above)
93+
vec2 noPerspScale = p.w / (0.5 * viewport.zw);
94+
95+
gl_Position.xy = p.xy + offset.xy * mix(noPerspScale, perspScale, float(perspective > 0));
96+
gl_Position.zw = p.zw;
97+
98+
vertColor = color;
99+
}

0 commit comments

Comments
 (0)