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 struct MaterialParameters
31 layout(std140) uniform GlobalMaterialParameters
33 MaterialParameters matralParameter;
39 vec4 positionWorldspace;
46 layout(std140) uniform GlobalLights
50 LightSource light[MAX_LIGHT_NUM];
55 vec3 colorTotal = vec3(0.0f, 0.0f, 0.0f);
57 vec3 vertexPositionCameraspace = (V * vec4(positionWorldspace,1)).xyz;
59 vec3 MaterialDiffuseColor = fragBarColor.rgb;
61 vec3 normalDirectionCameraspace = normalCameraspace;
62 vec3 eyeDirectionCameraspace = normalize(vec3(0, 0, 0) - vertexPositionCameraspace);
63 float attenuation = 1.0;
65 vec3 lightDirectionCameraspace;
66 vec3 vertexToLightSource;
68 vec3 lightAmbient = Lights.ambient.rgb *
69 MaterialDiffuseColor *
70 Material.matralParameter.ambient.rgb;
72 for (i = 0; i < Lights.lightNum; i++)
74 float LightPower = Lights.light[i].lightPower;
75 lightDirectionCameraspace = normalize((V * Lights.light[i].positionWorldspace).xyz);
77 float cosTheta = clamp(dot(normalDirectionCameraspace,lightDirectionCameraspace), 0,1);
78 vec3 lightDiffuse = LightPower *
80 Lights.light[i].lightColor.rgb *
81 MaterialDiffuseColor *
82 Material.matralParameter.diffuse.rgb *
85 vec3 specularReflection;
86 if (dot(normalDirectionCameraspace, lightDirectionCameraspace) < 0)
88 specularReflection = vec3(0.0, 0.0, 0.0);
92 vec3 R = reflect(-lightDirectionCameraspace,normalDirectionCameraspace);
93 float cosAlpha = clamp(dot(eyeDirectionCameraspace, R), 0,1);
94 specularReflection = attenuation *
96 Lights.light[i].lightColor.rgb *
97 Material.matralParameter.specular.rgb *
98 MaterialDiffuseColor *
99 pow(max(0.0, cosAlpha), Material.matralParameter.shininess);
101 colorTotal += lightDiffuse + specularReflection;
104 colorTotal += lightAmbient;
105 actualColor = vec4(colorTotal, 1.0);
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */