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

workbench_prepass_vert.glsl « shaders « workbench « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 82443e7336b011f3b7fd3f7f2a690955ec5e849a (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
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 ViewProjectionMatrix;
uniform mat4 ViewMatrixInverse;
uniform mat3 NormalMatrix;

#ifndef HAIR_SHADER
in vec3 pos;
in vec3 nor;
in vec2 uv;
#else /* HAIR_SHADER */
#  ifdef OB_TEXTURE
uniform samplerBuffer u; /* active texture layer */
#  endif
flat out float hair_rand;
#endif /* HAIR_SHADER */

#ifdef NORMAL_VIEWPORT_PASS_ENABLED
out vec3 normal_viewport;
#endif

#ifdef OB_TEXTURE
out vec2 uv_interp;
#endif

/* From http://libnoise.sourceforge.net/noisegen/index.html */
float integer_noise(int n)
{
	n = (n >> 13) ^ n;
	int nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
	return (float(nn) / 1073741824.0);
}

void main()
{
#ifdef HAIR_SHADER
#  ifdef OB_TEXTURE
	vec2 uv = hair_get_customdata_vec2(u);
#  endif
	float time, thick_time, thickness;
	vec3 pos, tan, binor;
	hair_get_pos_tan_binor_time(
	        (ProjectionMatrix[3][3] == 0.0),
	        ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
	        pos, tan, binor, time, thickness, thick_time);
	/* To "simulate" anisotropic shading, randomize hair normal per strand. */
	hair_rand = integer_noise(hair_get_strand_id());
	tan = normalize(tan);
	vec3 nor = normalize(cross(binor, tan));
	nor = normalize(mix(nor, -tan, hair_rand * 0.10));
	float cos_theta = (hair_rand*2.0 - 1.0) * 0.20;
	float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));
	nor = nor * sin_theta + binor * cos_theta;
	gl_Position = ViewProjectionMatrix * vec4(pos, 1.0);
#else
	gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
#endif
#ifdef OB_TEXTURE
	uv_interp = uv;
#endif

#ifdef NORMAL_VIEWPORT_PASS_ENABLED
	normal_viewport = NormalMatrix * nor;
#  ifndef HAIR_SHADER
	normal_viewport = normalize(normal_viewport);
#  endif
#endif
}