Simplify a bit
[LibreOffice.git] / canvas / opengl / radialMultiColorGradientFragmentShader.glsl
blobebc6d6f5fe105cfa9dcafea5e024b49b8ce19bc5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  */
10 #version 120
12 uniform int       i_nColors;
13 uniform sampler1D t_colorArray4d;
14 uniform sampler1D t_stopArray1d;
15 uniform mat3x2    m_transform;
16 varying vec2      v_textureCoords2d;
17 const vec2        v_center2d = vec2(0,0);
19 int max(int x, int y)
21     if(x > y)
22         return x;
23     return y;
26 int findBucket(float t)
28     int nMinBucket=0;
29     while( nMinBucket < i_nColors &&
30             texture1D(t_stopArray1d, nMinBucket).s < t )
31         ++nMinBucket;
32     return max(nMinBucket-1,0);
35 void main(void)
37     float fAlpha =
38         clamp( 1.0 - distance(
39                     vec2( m_transform * vec3(v_textureCoords2d,1)),
40                     v_center2d),
41                 0.0, 1.0 );
43     int nMinBucket=findBucket( fAlpha );
45     float fLerp =
46         (fAlpha-texture1D(t_stopArray1d, nMinBucket).s) /
47         (texture1D(t_stopArray1d, nMinBucket+1).s -
48          texture1D(t_stopArray1d, nMinBucket).s);
50     gl_FragColor = mix(texture1D(t_colorArray4d, nMinBucket),
51             texture1D(t_colorArray4d, nMinBucket+1),
52             fLerp);
55 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */