Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/GLSL150/Example_CelShadingVp.glsl

Last change on this file was 12115, checked in by wiesep, 6 years ago

Changed folder structure, deletet some unused files and cleaned up code

File size: 1.2 KB
RevLine 
[12115]1#version 150
2
3/* Cel shading vertex program for single-pass rendering
4   In this program, we want to calculate the diffuse and specular
5   ramp components, and the edge factor (for doing simple outlining)
6   For the outlining to look good, we need a pretty well curved model.
7*/
8// Parameters
9in vec4 vertex;
10in vec3 normal;
11
12uniform vec3 lightPosition; // object space
13uniform vec3 eyePosition;   // object space
14uniform vec4 shininess;
15uniform mat4 worldViewProj;
16
17//uniform transform
18//{
19//      vec4 shininess;
20//} MaterialShininess;
21
22out float diffuseIn;
23out float specularIn;
24out float edge;
25
26void main()
27{
28        // calculate output position
29        gl_Position = worldViewProj * vertex;
30
31        // calculate light vector
32        vec3 N = normalize(normal);
33        vec3 L = normalize(lightPosition - vertex.xyz);
34       
35        // Calculate diffuse component
36        diffuseIn = max(dot(N, L) , 0.0);
37
38        // Mask off specular if diffuse is 0
39        if (diffuseIn == 0.0)
40            specularIn = 0.0;
41
42    // Calculate specular component
43    vec3 E = normalize(eyePosition - vertex.xyz);
44    vec3 H = normalize(L + E);
45    specularIn = pow(max(dot(N, H), 0.0), shininess.x);
46//    specularIn = pow(max(dot(N, H), 0.0), MaterialShininess.shininess.x);
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.