File: ICMMatrixMult4Shader.frag.txt

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (47 lines) | stat: -rw-r--r-- 1,454 bytes parent folder | download | duplicates (6)
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
46
47
/* ICMMatrixMult4Shader.frag.txt
 *
 * Multiplies first 3 components of a 4 component vec4 color vector with a
 * defined 4x4 matrix and creates a 4 component output color vector, consisting
 * of the original alpha component and the 3 rgb components from the matrix
 * multiply. This adds a 4'th constant 1 component, multiplies the resulting
 * 4 element vector with the 4x4 matrix, then divides the resulting 4 component
 * vector by its 4th component, then truncates it back to a 3 component rgb vector.
 *
 * Can be used for projective color conversions, using the fourth component to allow
 * adding or subtracting bias values.
 *
 * (C) 2012 Mario Kleiner - Released to you under MIT license.
 */

/* RGB to gray conversion weights for icmTransformColor1(): */
const vec3 ColorToGrayWeights = vec3(0.3, 0.59, 0.11);

/* 4 by 4 color transformation matrix: */
uniform mat4 M;

vec4 icmTransformColor(vec4 incolor)
{
    vec4 outcolor, tmp;

    /* Alpha is passed through unmodified: */
    outcolor.a = incolor.a;

    /* 1-extend, multiply, normalize: */
    incolor.a = 1.0;
    tmp = M * incolor;
    tmp.rgb = tmp.rgb / tmp.a;
    outcolor.rgb = tmp.rgb;
    return(outcolor);
}

float icmTransformColor1(float incolor)
{
    float outcolor;
    vec4  tmp;

    /* 1-extend, multiply, normalize: */
    tmp = M * vec4(vec3(incolor), 1.0);
    tmp.rgb = tmp.rgb / tmp.a;
    outcolor = dot(tmp.rgb, ColorToGrayWeights);
    return(outcolor);
}