mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
Adding the shader examples
This commit is contained in:
20
java/examples/Topics/Shaders/ToonShading/data/ToonFrag.glsl
Normal file
20
java/examples/Topics/Shaders/ToonShading/data/ToonFrag.glsl
Normal file
@@ -0,0 +1,20 @@
|
||||
varying vec3 vertNormal;
|
||||
varying vec3 vertLightDir;
|
||||
|
||||
void main() {
|
||||
float intensity;
|
||||
vec4 color;
|
||||
intensity = max(0.0, dot(vertLightDir, vertNormal));
|
||||
|
||||
if (intensity > 0.95) {
|
||||
color = vec4(1.0, 0.5, 0.5, 1.0);
|
||||
} else if (intensity > 0.5) {
|
||||
color = vec4(0.6, 0.3, 0.3, 1.0);
|
||||
} else if (intensity > 0.25) {
|
||||
color = vec4(0.4, 0.2, 0.2, 1.0);
|
||||
} else {
|
||||
color = vec4(0.2, 0.1, 0.1, 1.0);
|
||||
}
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
29
java/examples/Topics/Shaders/ToonShading/data/ToonVert.glsl
Normal file
29
java/examples/Topics/Shaders/ToonShading/data/ToonVert.glsl
Normal file
@@ -0,0 +1,29 @@
|
||||
// Toon shader using per-pixel lighting. Based on the glsl
|
||||
// tutorial from lighthouse 3D:
|
||||
// http://www.lighthouse3d.com/tutorials/glsl-tutorial/toon-shader-version-ii/
|
||||
|
||||
uniform mat4 modelviewMatrix;
|
||||
uniform mat4 projmodelviewMatrix;
|
||||
uniform mat3 normalMatrix;
|
||||
|
||||
uniform vec3 lightNormal[8];
|
||||
|
||||
attribute vec4 inVertex;
|
||||
attribute vec3 inNormal;
|
||||
|
||||
varying vec3 vertNormal;
|
||||
varying vec3 vertLightDir;
|
||||
|
||||
void main() {
|
||||
// Vertex in clip coordinates
|
||||
gl_Position = projmodelviewMatrix * inVertex;
|
||||
|
||||
// Normal vector in eye coordinates is passed
|
||||
// to the fragment shader
|
||||
vertNormal = normalize(normalMatrix * inNormal);
|
||||
|
||||
// Assuming that there is only one directional light.
|
||||
// Its normal vector is passed to the fragment shader
|
||||
// in order to perform per-pixel lighting calculation.
|
||||
vertLightDir = -lightNormal[0];
|
||||
}
|
||||
Reference in New Issue
Block a user