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

armature_shape_solid_vert.glsl « shaders « modes « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ccfd88892cdc40e79e868623e4fec8f2e560b54 (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

uniform mat3 NormalMatrix;
uniform mat4 ViewMatrixInverse;
uniform mat4 ViewProjectionMatrix;

uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;

/* ---- Instanciated Attribs ---- */
in vec3 pos;
in vec3 nor;

/* ---- Per instance Attribs ---- */
in mat4 InstanceModelMatrix;
in vec3 boneColor;
in vec3 stateColor;

out vec4 finalColor;

void main()
{
	mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * InstanceModelMatrix)));
	vec3 normal = normalize(NormalMatrix * nor);

	/* Do lighting at an angle to avoid flat shading on front facing bone. */
	const vec3 light = vec3(0.1, 0.1, 0.8);
	float n = dot(normal, light);

	/* Smooth lighting factor. */
	const float s = 0.2; /* [0.0-0.5] range */
	float fac = clamp((n * (1.0 - s)) + s, 0.0, 1.0);
	finalColor.rgb = mix(stateColor, boneColor, fac);
	finalColor.a = 1.0;

	gl_Position = ViewProjectionMatrix * (InstanceModelMatrix * vec4(pos, 1.0));
}