summaryrefslogtreecommitdiffstats
path: root/res/effectlib/blendColorLayers.glsllib
blob: e07fe6135a8fbeaf59932d1488b4ed74b186d8cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef BLEND_COLOR_LAYERS_GLSLLIB
#define BLEND_COLOR_LAYERS_GLSLLIB

float maxValue( in vec3 t )
{
    return max( max( t.x, t.y ), t.z );
}

vec3 blendColor( in vec3 t, in vec3 b, in float weight, in int blendMode)
{
    vec3 blendResult = t;
    switch( blendMode )
      {
          case color_layer_add :
              blendResult += b;
              break;
          case color_layer_multiply :
              blendResult *= b;
              break;
          case color_layer_screen :
              blendResult += t - t * b;
              break;
          case color_layer_overlay:
              blendResult = (maxValue(t) >= 0.5) ? 2.0 * (t+b - t*b - 0.5) : 2.0 * t*b;
              break;
          case color_layer_blend:
          default:
              // nothing to be done
              break;
      }

      return mix( b, blendResult, weight );
}

texture_return blendColorLayers( in color_layer colorLayer[1], in vec3 base, in int monoSource )
{
    vec3 result = blendColor( colorLayer[0].layer_color, base, colorLayer[0].weight, colorLayer[0].mode );

    texture_return tr;
      tr.tint = result;
      tr.mono = monoChannel( vec4( result, 1.0 ), monoSource );
      return( tr );
}

#endif