Debian Codegraph @

tests/manual/planets-qml/shaders/es2/planetD.frag

raw
1 // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2 // Copyright (C) 2017 The Qt Company Ltd.
3 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
5 uniform highp mat4 viewMatrix;
6
7 uniform highp vec3 lightPosition;
8 uniform highp vec3 lightIntensity;
9
10 uniform highp vec3 ka; // Ambient reflectivity
11 uniform highp vec3 ks; // Specular reflectivity
12 uniform highp float shininess; // Specular shininess factor
13 uniform highp float opacity; // Alpha channel
14
15 uniform sampler2D diffuseTexture;
16
17 varying highp vec4 positionInLightSpace;
18
19 varying highp vec3 position;
20 varying highp vec3 normal;
21 varying highp vec2 texCoord;
22
23 highp vec3 dModel(const highp vec2 flipYTexCoord)
24 {
25 // Calculate the vector from the light to the fragment
26 highp vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - position);
27
28 // Calculate the vector from the fragment to the eye position
29 // (origin since this is in "eye" or "camera" space)
30 highp vec3 v = normalize(-position);
31
32 // Reflect the light beam using the normal at this fragment
33 highp vec3 r = reflect(-s, normal);
34
35 // Calculate the diffuse component
36 highp float diffuse = max(dot(s, normal), 0.0);
37
38 // Calculate the specular component
39 highp float specular = 0.0;
40 if (dot(s, normal) > 0.0)
41 specular = (shininess / (8.0 * 3.14)) * pow(max(dot(r, v), 0.0), shininess);
42
43 // Lookup diffuse and specular factors
44 highp vec3 diffuseColor = texture2D(diffuseTexture, flipYTexCoord).rgb;
45
46 // Combine the ambient, diffuse and specular contributions
47 return lightIntensity * ((ka + diffuse) * diffuseColor + specular * ks);
48 }
49
50 void main()
51 {
52 highp vec2 flipYTexCoord = texCoord;
53 flipYTexCoord.y = 1.0 - texCoord.y;
54
55 highp vec3 result = dModel(flipYTexCoord);
56
57 highp float alpha = opacity * texture2D(diffuseTexture, flipYTexCoord).a;
58
59 gl_FragColor = vec4(result, alpha);
60 }