1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #define MAX_LIGHT_NUM 8
14 in vec3 positionWorldspace;
15 in vec3 normalCameraspace;
18 uniform vec4 materialAmbient;
19 uniform vec4 materialDiffuse;
20 uniform vec4 materialSpecular;
21 uniform vec4 materialColor;
22 uniform int twoSidesLighting;
23 uniform float materialShininess;
24 uniform vec4 lightColor[MAX_LIGHT_NUM];
25 uniform vec4 lightPosWorldspace[MAX_LIGHT_NUM];
26 uniform float lightPower[MAX_LIGHT_NUM];
28 uniform vec4 lightAmbient;
30 uniform float minCoordX;
34 if ((positionWorldspace.x <= minCoordX) && (undraw == 1))
36 vec3 colorTotal = vec3(0.0f, 0.0f, 0.0f);
38 vec3 vertexPositionCameraspace = (V * vec4(positionWorldspace,1)).xyz;
40 vec3 MaterialDiffuseColor = materialColor.rgb;
42 vec3 normalDirectionCameraspace = normalCameraspace;
43 vec3 eyeDirectionCameraspace = normalize(vec3(0, 0, 0) - vertexPositionCameraspace);
44 float attenuation = 1.0;
46 vec3 lightDirectionCameraspace;
47 vec3 vertexToLightSource;
49 vec3 totalAmbient = lightAmbient.rgb *
50 MaterialDiffuseColor *
53 if ((twoSidesLighting == 1) && (!gl_FrontFacing))
55 normalDirectionCameraspace = -normalDirectionCameraspace;
57 for (i = 0; i < lightNum; i++)
59 float LightPower = lightPower[i];
60 lightDirectionCameraspace = normalize((V * lightPosWorldspace[i]).xyz);
62 float cosTheta = clamp(dot(normalDirectionCameraspace,lightDirectionCameraspace), 0,1);
63 vec3 lightDiffuse = LightPower *
66 MaterialDiffuseColor *
70 vec3 specularReflection;
71 if (dot(normalDirectionCameraspace, lightDirectionCameraspace) < 0)
73 specularReflection = vec3(0.0, 0.0, 0.0);
77 vec3 R = reflect(-lightDirectionCameraspace,normalDirectionCameraspace);
78 float cosAlpha = clamp(dot(eyeDirectionCameraspace, R), 0,1);
79 specularReflection = attenuation *
82 materialSpecular.rgb *
83 MaterialDiffuseColor *
84 pow(max(0.0, cosAlpha), materialShininess);
86 colorTotal += lightDiffuse + specularReflection;
89 colorTotal += totalAmbient;
90 gl_FragColor = vec4(colorTotal, 1.0);
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */