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/.
13 layout(triangle_strip, max_vertices=27) out;
15 in mat4 projectionMatrix[];
16 in mat4 modelViewMatrix[];
17 in mat4 shadowMatrix[];
19 uniform float hexagonSize;
20 uniform sampler2D permTexture;
22 out vec2 texturePosition;
26 out vec4 shadowCoordinate;
28 const float expandFactor = 0.0318;
32 return texture(permTexture, p).r;
35 mat4 identityMatrix(void)
37 return mat4(1.0, 0.0, 0.0, 0.0,
43 mat4 scaleMatrix(vec3 axis)
45 mat4 matrix = identityMatrix();
46 matrix[0][0] = axis.x;
47 matrix[1][1] = axis.y;
48 matrix[2][2] = axis.z;
52 mat4 translationMatrix(vec3 axis)
54 mat4 matrix = identityMatrix();
55 matrix[3] = vec4(axis, 1.0);
59 void emitHexagonVertex(vec3 center, vec2 translation)
61 vec4 pos = vec4(center + hexagonSize * expandFactor * vec3(translation, 0.0), 1.0);
62 gl_Position = projectionMatrix[0] * modelViewMatrix[0] * pos;
63 shadowCoordinate = translationMatrix(vec3(0.5, 0.5, 0.5)) * scaleMatrix(vec3(0.5, 0.5, 0.5)) * shadowMatrix[0] * modelViewMatrix[0] * pos;
64 texturePosition = vec2((pos.x + 1), (1 - pos.y)) / 2;
70 const vec2 translateVectors[6] = vec2[](
79 vec3 center = gl_in[0].gl_Position.xyz;
81 v_center = (1 + center.xy) / 2;
82 fuzz = snoise(center.xy);
84 // Draw “walls” to the hexagons.
85 if (hexagonSize < 1.0) {
86 vec3 rearCenter = vec3(center.xy, -0.3);
87 normal = vec3(0.0, 0.0, 0.3);
88 emitHexagonVertex(center, translateVectors[5]);
89 emitHexagonVertex(rearCenter, translateVectors[5]);
91 for (int i = 0; i < 6; ++i) {
92 emitHexagonVertex(center, translateVectors[i]);
93 emitHexagonVertex(rearCenter, translateVectors[i]);
99 // Draw the main hexagon part.
100 normal = vec3(0.0, 0.0, 1.0);
101 emitHexagonVertex(center, translateVectors[5]);
103 for (int i = 0; i < 6; ++i) {
104 emitHexagonVertex(center, translateVectors[i]);
105 emitHexagonVertex(center, vec2(0.0, 0.0));
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */