File: color_phong.frag

package info (click to toggle)
qt6-base 6.9.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 316,752 kB
  • sloc: cpp: 2,112,334; ansic: 381,848; xml: 142,587; python: 21,632; java: 8,505; asm: 4,009; javascript: 2,290; sh: 1,657; perl: 1,028; makefile: 131
file content (39 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download | duplicates (15)
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
#version 440

layout(location = 0) in vec3 vECVertNormal;
layout(location = 1) in vec3 vECVertPos;
layout(location = 2) flat in vec3 vDiffuseAdjust;

layout(std140, binding = 1) uniform buf {
    vec3 ECCameraPosition;
    vec3 ka;
    vec3 kd;
    vec3 ks;
    // Have one light only for now.
    vec3 ECLightPosition;
    vec3 attenuation;
    vec3 color;
    float intensity;
    float specularExp;
} ubuf;

layout(location = 0) out vec4 fragColor;

void main()
{
    vec3 unnormL = ubuf.ECLightPosition - vECVertPos;
    float dist = length(unnormL);
    float att = 1.0 / (ubuf.attenuation.x + ubuf.attenuation.y * dist + ubuf.attenuation.z * dist * dist);

    vec3 N = normalize(vECVertNormal);
    vec3 L = normalize(unnormL);
    float NL = max(0.0, dot(N, L));
    vec3 dColor = att * ubuf.intensity * ubuf.color * NL;

    vec3 R = reflect(-L, N);
    vec3 V = normalize(ubuf.ECCameraPosition - vECVertPos);
    float RV = max(0.0, dot(R, V));
    vec3 sColor = att * ubuf.intensity * ubuf.color * pow(RV, ubuf.specularExp);

    fragColor = vec4(ubuf.ka + (ubuf.kd + vDiffuseAdjust) * dColor + ubuf.ks * sColor, 1.0);
}