- use in/out instead of attribute/varying - use named output instead of gl_FragColor - use texture() instead of the multitude of older texture sampling functions The #if __VERSION__ == 120 paths (needed on Mac) will be removed after we switch to 3.3 core profile. Part of T49165 (general OpenGL upgrade)
122 lines
2.2 KiB
GLSL
122 lines
2.2 KiB
GLSL
|
|
uniform mat4 ModelViewMatrix;
|
|
uniform mat4 ProjectionMatrix;
|
|
uniform mat3 NormalMatrix;
|
|
|
|
#ifdef USE_OPENSUBDIV
|
|
in vec3 normal;
|
|
in vec4 position;
|
|
|
|
out block {
|
|
VertexData v;
|
|
} outpt;
|
|
#endif
|
|
|
|
#if __VERSION__ == 120
|
|
varying vec3 varposition;
|
|
varying vec3 varnormal;
|
|
#else
|
|
out vec3 varposition;
|
|
out vec3 varnormal;
|
|
#endif
|
|
|
|
#ifdef CLIP_WORKAROUND
|
|
varying float gl_ClipDistance[6];
|
|
#endif
|
|
|
|
|
|
/* Color, keep in sync with: gpu_shader_vertex_world.glsl */
|
|
|
|
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(float attr, int info, out float var)
|
|
{
|
|
var = attr;
|
|
}
|
|
|
|
void set_var_from_attr(vec2 attr, int info, out vec2 var)
|
|
{
|
|
var = attr;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
/* end color code */
|
|
|
|
|
|
void main()
|
|
{
|
|
#ifndef USE_OPENSUBDIV
|
|
vec4 position = gl_Vertex;
|
|
vec3 normal = gl_Normal;
|
|
#endif
|
|
|
|
vec4 co = ModelViewMatrix * position;
|
|
|
|
varposition = co.xyz;
|
|
varnormal = normalize(NormalMatrix * normal);
|
|
gl_Position = 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
|