File: ribbon.frag

package info (click to toggle)
qt6-3d 6.4.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 219,572 kB
  • sloc: cpp: 444,068; cobol: 65,664; ansic: 41,133; xml: 10,866; python: 9,582; asm: 3,071; java: 2,303; ada: 1,681; pascal: 1,405; cs: 879; sh: 478; objc: 382; makefile: 337; javascript: 207
file content (49 lines) | stat: -rw-r--r-- 1,307 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#version 330 core

in EyeSpaceVertex {
    vec3 position;
    vec3 normal;
} fs_in;

out vec4 fragColor;

uniform struct LightInfo {
    vec4 position;
    vec3 intensity;
} light;

uniform struct LineInfo {
    float width;
    vec4 color;
} line;

uniform vec3 ka;            // Ambient reflectivity
uniform vec3 kd;            // Diffuse reflectivity

vec3 rimLightModel( const in vec3 pos, const in vec3 n )
{
    // Calculate the vector from the light to the fragment
    vec3 s = normalize( vec3( light.position ) - pos );

    // Calculate the vector from the fragment to the eye position (the
    // origin since this is in "eye" or "camera" space
    vec3 v = normalize( -pos );

    // Refleft the light beam using the normal at this fragment
    vec3 r = reflect( -s, n );

    // Calculate the diffuse component, which for rim lighting it 1 minus s dot n
    // rather than s dot n as for standard diffuse lighting
    float sDotN = dot( s, n );
    vec3 diffuse = vec3( 1.0 - max( sDotN, 0.0 ) );

    // Combine the ambient, diffuse and specular contributions
    return light.intensity * ( ka + kd * diffuse );
}

void main()
{
    vec3 n = gl_FrontFacing ? fs_in.normal : -fs_in.normal;
    vec4 color = vec4( rimLightModel( fs_in.position, normalize( n ) ), 1.0 );
    fragColor = color;
}