blob: a91d9e3e6f2e6900e01387bdb4158df1c715a6b8 (
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#ifdef USE_OPENSUBDIV
in vec3 normal;
in vec4 position;
out block {
VertexData v;
} outpt;
#endif
varying vec3 varposition;
varying vec3 varnormal;
#ifdef CLIP_WORKAROUND
varying float gl_ClipDistance[6];
#endif
float srgb_to_linearrgb(float c)
{
if (c < 0.04045)
return (c < 0.0) ? 0.0 : c * (1.0 / 12.92);
else
return pow((c + 0.055) * (1.0 / 1.055), 2.4);
}
void srgb_to_linearrgb(vec3 col_from, out vec3 col_to)
{
col_to.r = srgb_to_linearrgb(col_from.r);
col_to.g = srgb_to_linearrgb(col_from.g);
col_to.b = srgb_to_linearrgb(col_from.b);
}
void srgb_to_linearrgb(vec4 col_from, out vec4 col_to)
{
col_to.r = srgb_to_linearrgb(col_from.r);
col_to.g = srgb_to_linearrgb(col_from.g);
col_to.b = srgb_to_linearrgb(col_from.b);
col_to.a = col_from.a;
}
bool is_srgb(int info)
{
#ifdef USE_NEW_SHADING
return (info == 1)? true: false;
#else
return false;
#endif
}
void set_var_from_attr(vec3 attr, int info, out vec3 var)
{
if (is_srgb(info)) {
srgb_to_linearrgb(attr, var);
}
else {
var = attr;
}
}
void set_var_from_attr(vec4 attr, int info, out vec4 var)
{
if (is_srgb(info)) {
srgb_to_linearrgb(attr, var);
}
else {
var = attr;
}
}
void main()
{
#ifndef USE_OPENSUBDIV
vec4 position = gl_Vertex;
vec3 normal = gl_Normal;
#endif
vec4 co = gl_ModelViewMatrix * position;
varposition = co.xyz;
varnormal = normalize(gl_NormalMatrix * normal);
gl_Position = gl_ProjectionMatrix * co;
#ifdef CLIP_WORKAROUND
int i;
for (i = 0; i < 6; i++)
gl_ClipDistance[i] = dot(co, gl_ClipPlane[i]);
#elif !defined(GPU_ATI)
// Setting gl_ClipVertex is necessary to get glClipPlane working on NVIDIA
// graphic cards, while on ATI it can cause a software fallback.
gl_ClipVertex = co;
#endif
#ifdef USE_OPENSUBDIV
outpt.v.position = co;
outpt.v.normal = varnormal;
#endif
|