Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/Example_CelShadingVp.glsles @ 12091

Last change on this file since 12091 was 12091, checked in by wiesep, 5 years ago

Updated programs and adjusted Material to work with GLSL>150

File size: 1.2 KB
Line 
1#version 100
2precision mediump int;
3precision mediump float;
4
5/* Cel shading vertex program for single-pass rendering
6   In this program, we want to calculate the diffuse and specular
7   ramp components, and the edge factor (for doing simple outlining)
8   For the outlining to look good, we need a pretty well curved model.
9*/
10// Parameters
11attribute vec4 vertex;
12attribute vec3 normal;
13
14uniform vec3 lightPosition; // object space
15uniform vec3 eyePosition;   // object space
16uniform vec4 shininess;
17uniform mat4 worldViewProj;
18
19varying float diffuseIn;
20varying float specularIn;
21varying float edge;
22
23void main()
24{
25        // calculate output position
26        gl_Position = worldViewProj * vertex;
27
28        // calculate light vector
29        vec3 N = normalize(normal);
30        vec3 L = normalize(lightPosition - vertex.xyz);
31        vec3 E = normalize(eyePosition - vertex.xyz);
32       
33        // Calculate diffuse component
34        diffuseIn = max(dot(N, L) , 0.0);
35
36        // Mask off specular if diffuse is 0
37        if (diffuseIn == 0.0)
38        {
39            specularIn = 0.0;
40        }
41        else
42        {
43                // Calculate specular component
44                vec3 H = normalize(L + E);
45                specularIn = pow(max(dot(N, H), 0.0), shininess.x);
46        }
47
48        // Edge detection, dot eye and normal vectors
49        edge = max(dot(N, E), 0.0);
50}
Note: See TracBrowser for help on using the repository browser.