Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit b939b08

Browse files
committed
added toon stereo example
1 parent a659f90 commit b939b08

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifdef GL_ES
2+
precision mediump float;
3+
precision mediump int;
4+
#endif
5+
6+
varying vec3 vertNormal;
7+
varying vec3 vertLightDir;
8+
9+
void main() {
10+
float intensity;
11+
vec4 color;
12+
intensity = max(0.0, dot(vertLightDir, vertNormal));
13+
14+
if (intensity > 0.95) {
15+
color = vec4(1.0, 0.5, 0.5, 1.0);
16+
} else if (intensity > 0.5) {
17+
color = vec4(0.6, 0.3, 0.3, 1.0);
18+
} else if (intensity > 0.25) {
19+
color = vec4(0.4, 0.2, 0.2, 1.0);
20+
} else {
21+
color = vec4(0.2, 0.1, 0.1, 1.0);
22+
}
23+
24+
gl_FragColor = color;
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Toon shader using per-pixel lighting. Based on the glsl
2+
// tutorial from lighthouse 3D:
3+
// http://www.lighthouse3d.com/tutorials/glsl-tutorial/toon-shader-version-ii/
4+
5+
#define PROCESSING_LIGHT_SHADER
6+
7+
uniform mat4 modelview;
8+
uniform mat4 transform;
9+
uniform mat3 normalMatrix;
10+
11+
uniform vec3 lightNormal[8];
12+
13+
attribute vec4 vertex;
14+
attribute vec3 normal;
15+
16+
varying vec3 vertNormal;
17+
varying vec3 vertLightDir;
18+
19+
void main() {
20+
// Vertex in clip coordinates
21+
gl_Position = transform * vertex;
22+
23+
// Normal vector in eye coordinates is passed
24+
// to the fragment shader
25+
vertNormal = normalize(normalMatrix * normal);
26+
27+
// Assuming that there is only one directional light.
28+
// Its normal vector is passed to the fragment shader
29+
// in order to perform per-pixel lighting calculation.
30+
vertLightDir = -lightNormal[0];
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import processing.cardboard.*;
2+
3+
PShader toon;
4+
boolean shaderEnabled = true;
5+
6+
void setup() {
7+
fullScreen(PCardboard.STEREO);
8+
noStroke();
9+
fill(204);
10+
toon = loadShader("ToonFrag.glsl", "ToonVert.glsl");
11+
}
12+
13+
void draw() {
14+
if (shaderEnabled == true) shader(toon);
15+
background(80);
16+
directionalLight(204, 204, 204, 0, 0, -1);
17+
translate(width/2, height/2);
18+
sphere(500);
19+
}
20+
21+
void mousePressed() {
22+
if (shaderEnabled) {
23+
shaderEnabled = false;
24+
resetShader();
25+
}
26+
else {
27+
shaderEnabled = true;
28+
}
29+
}

0 commit comments

Comments
 (0)