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;
17 struct MaterialParameters
30 layout(std140) uniform GlobalMaterialParameters
32 MaterialParameters matralParameter;
38 vec4 positionWorldspace;
45 layout(std140) uniform GlobalLights
49 LightSource light[MAX_LIGHT_NUM];
54 vec3 colorTotal = vec3(0.0f, 0.0f, 0.0f);
56 vec3 vertexPositionCameraspace = (V * vec4(positionWorldspace,1)).xyz;
58 vec3 MaterialDiffuseColor = Material.matralParameter.materialColor.rgb;
60 vec3 normalDirectionCameraspace = normalCameraspace;
61 vec3 eyeDirectionCameraspace = normalize(vec3(0, 0, 0) - vertexPositionCameraspace);
62 float attenuation = 1.0;
64 vec3 lightDirectionCameraspace;
65 vec3 vertexToLightSource;
67 vec3 lightAmbient = Lights.ambient.rgb *
68 MaterialDiffuseColor *
69 Material.matralParameter.ambient.rgb
72 if ((Material.matralParameter.twoSidesLighting == 1) && (!gl_FrontFacing))
74 normalDirectionCameraspace = -normalDirectionCameraspace;
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: */