Welcome to mirror list, hosted at ThFree Co, Russian Federation.

edit_mesh_overlay_vert.glsl « shaders « modes « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 982ef2ca8016ff10ae6f9dff0d1576fcfb26f186 (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
96
97
98
99
100

uniform mat3 NormalMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelMatrix;
uniform float faceAlphaMod;
uniform ivec4 dataMask = ivec4(0xFF);
uniform float ofs;

in ivec4 data;
in vec3 pos;
#ifndef FACEDOT
in vec3 vnor;
#else
in vec4 norAndFlag;
#  define vnor norAndFlag.xyz
#endif

out vec4 finalColor;
out vec4 finalColorOuter;
#ifdef USE_GEOM_SHADER
out int selectOveride;
#endif

void main()
{
#if !defined(FACE)
	mat4 projmat = ProjectionMatrix;
	projmat[3][2] -= ofs;

	gl_Position = projmat * (ModelViewMatrix * vec4(pos, 1.0));
#else

	gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
#endif

	ivec4 m_data = data & dataMask;

#if defined(VERT)
	finalColor = EDIT_MESH_vertex_color(m_data.y);
	gl_PointSize = sizeVertex * 2.0;
	gl_Position.z -= 3e-5 * ((ProjectionMatrix[3][3] == 0.0) ? 1.0 : 0.0);
	/* Make selected and active vertex always on top. */
	if ((data.x & VERT_SELECTED) != 0) {
		gl_Position.z -= 1e-7;
	}
	if ((data.x & VERT_ACTIVE) != 0) {
		gl_Position.z -= 1e-7;
	}

#elif defined(EDGE)
#  ifdef FLAT
	finalColor = EDIT_MESH_edge_color_inner(m_data.y);
	selectOveride = 1;
#  else
	finalColor = EDIT_MESH_edge_vertex_color(m_data.y);
	selectOveride = (m_data.y & EDGE_SELECTED);
#  endif

	float crease = float(m_data.z) / 255.0;
	float bweight = float(m_data.w) / 255.0;
	finalColorOuter = EDIT_MESH_edge_color_outer(m_data.y, m_data.x, crease, bweight);

#elif defined(FACE)
	finalColor = EDIT_MESH_face_color(m_data.x);
	finalColor.a *= faceAlphaMod;

#elif defined(FACEDOT)
	finalColor = EDIT_MESH_facedot_color(norAndFlag.w);
	/* Bias Facedot Z position in clipspace. */
	gl_Position.z -= 0.00035;
	gl_PointSize = sizeFaceDot;

#endif

#if !defined(FACE) && !defined(EDGE_DECORATION)
	/* Facing based color blend */
	vec4 vpos = ModelViewMatrix * vec4(pos, 1.0);
	vec3 view_normal = normalize(NormalMatrix * vnor + 1e-4);
	vec3 view_vec = (ProjectionMatrix[3][3] == 0.0)
		? normalize(vpos.xyz)
		: vec3(0.0, 0.0, 1.0);
	float facing = dot(view_vec, view_normal);
	facing = 1.0 - abs(facing) * 0.3;

	finalColor = mix(colorEditMeshMiddle, finalColor, facing);
	finalColor.a = 1.0;

#  if defined(EDGE) && !defined(FLAT)
	/* Hack to blend color in pixel shader in case of overide.  */
	finalColor.a = facing;
#  endif

#endif

#ifdef USE_WORLD_CLIP_PLANES
	world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
#endif
}