| 1 |
#version 330 core |
| 2 |
|
| 3 |
in EyeSpaceVertex { |
| 4 |
vec3 position; |
| 5 |
vec3 normal; |
| 6 |
} fs_in; |
| 7 |
|
| 8 |
out vec4 fragColor; |
| 9 |
|
| 10 |
uniform struct LightInfo { |
| 11 |
vec4 position; |
| 12 |
vec3 intensity; |
| 13 |
} light; |
| 14 |
|
| 15 |
uniform struct LineInfo { |
| 16 |
float width; |
| 17 |
vec4 color; |
| 18 |
} line; |
| 19 |
|
| 20 |
uniform vec3 ka; // Ambient reflectivity |
| 21 |
uniform vec3 kd; // Diffuse reflectivity |
| 22 |
|
| 23 |
vec3 rimLightModel( const in vec3 pos, const in vec3 n ) |
| 24 |
{ |
| 25 |
// Calculate the vector from the light to the fragment |
| 26 |
vec3 s = normalize( vec3( light.position ) - pos ); |
| 27 |
|
| 28 |
// Calculate the vector from the fragment to the eye position (the |
| 29 |
// origin since this is in "eye" or "camera" space |
| 30 |
vec3 v = normalize( -pos ); |
| 31 |
|
| 32 |
// Refleft the light beam using the normal at this fragment |
| 33 |
vec3 r = reflect( -s, n ); |
| 34 |
|
| 35 |
// Calculate the diffuse component, which for rim lighting it 1 minus s dot n |
| 36 |
// rather than s dot n as for standard diffuse lighting |
| 37 |
float sDotN = dot( s, n ); |
| 38 |
vec3 diffuse = vec3( 1.0 - max( sDotN, 0.0 ) ); |
| 39 |
|
| 40 |
// Combine the ambient, diffuse and specular contributions |
| 41 |
return light.intensity * ( ka + kd * diffuse ); |
| 42 |
} |
| 43 |
|
| 44 |
void main() |
| 45 |
{ |
| 46 |
vec3 n = gl_FrontFacing ? fs_in.normal : -fs_in.normal; |
| 47 |
vec4 color = vec4( rimLightModel( fs_in.position, normalize( n ) ), 1.0 ); |
| 48 |
fragColor = color; |
| 49 |
} |