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/.
11 #define MAX_LIGHT_NUM 8
13 in vec3 positionWorldspace;
14 in vec3 normalCameraspace;
18 uniform float minCoordX;
20 struct MaterialParameters
33 layout(std140) uniform GlobalMaterialParameters
35 MaterialParameters matralParameter;
41 vec4 positionWorldspace;
48 layout(std140) uniform GlobalLights
52 LightSource light[MAX_LIGHT_NUM];
57 if ((positionWorldspace.x <= minCoordX) && (undraw == 1))
59 vec3 colorTotal = vec3(0.0f, 0.0f, 0.0f);
61 vec3 vertexPositionCameraspace = (V * vec4(positionWorldspace,1)).xyz;
63 vec3 MaterialDiffuseColor = fragBarColor.rgb;
65 vec3 normalDirectionCameraspace = normalCameraspace;
66 vec3 eyeDirectionCameraspace = normalize(vec3(0, 0, 0) - vertexPositionCameraspace);
67 float attenuation = 1.0;
69 vec3 lightDirectionCameraspace;
70 vec3 vertexToLightSource;
72 vec3 lightAmbient = Lights.ambient.rgb *
73 MaterialDiffuseColor *
74 Material.matralParameter.ambient.rgb;
76 for (i = 0; i < Lights.lightNum; i++)
78 float LightPower = Lights.light[i].lightPower;
79 lightDirectionCameraspace = normalize((V * Lights.light[i].positionWorldspace).xyz);
81 float cosTheta = clamp(dot(normalDirectionCameraspace,lightDirectionCameraspace), 0,1);
82 vec3 lightDiffuse = LightPower *
84 Lights.light[i].lightColor.rgb *
85 MaterialDiffuseColor *
86 Material.matralParameter.diffuse.rgb *
89 vec3 specularReflection;
90 if (dot(normalDirectionCameraspace, lightDirectionCameraspace) < 0)
92 specularReflection = vec3(0.0, 0.0, 0.0);
96 vec3 R = reflect(-lightDirectionCameraspace,normalDirectionCameraspace);
97 float cosAlpha = clamp(dot(eyeDirectionCameraspace, R), 0,1);
98 specularReflection = attenuation *
100 Lights.light[i].lightColor.rgb *
101 Material.matralParameter.specular.rgb *
102 MaterialDiffuseColor *
103 pow(max(0.0, cosAlpha), Material.matralParameter.shininess);
105 colorTotal += lightDiffuse + specularReflection;
108 colorTotal += lightAmbient;
109 actualColor = vec4(colorTotal, 1.0);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */