Mesh Batch Cache: Port Texture paint batches to new batch request
[blender.git] / source / blender / draw / engines / workbench / shaders / workbench_prepass_vert.glsl
1 uniform mat4 ModelViewProjectionMatrix;
2 uniform mat4 ModelMatrixInverse;
3 uniform mat4 ProjectionMatrix;
4 uniform mat4 ViewProjectionMatrix;
5 uniform mat4 ViewMatrixInverse;
6 uniform mat3 NormalMatrix;
7
8 #ifndef HAIR_SHADER
9 in vec3 pos;
10 in vec3 nor;
11 in vec2 u; /* active texture layer */
12 #define uv u
13 #else /* HAIR_SHADER */
14 #  ifdef V3D_SHADING_TEXTURE_COLOR
15 uniform samplerBuffer u; /* active texture layer */
16 #  endif
17 flat out float hair_rand;
18 #endif /* HAIR_SHADER */
19
20 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
21 out vec3 normal_viewport;
22 #endif
23
24 #ifdef V3D_SHADING_TEXTURE_COLOR
25 out vec2 uv_interp;
26 #endif
27
28 /* From http://libnoise.sourceforge.net/noisegen/index.html */
29 float integer_noise(int n)
30 {
31         n = (n >> 13) ^ n;
32         int nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
33         return (float(nn) / 1073741824.0);
34 }
35
36 void main()
37 {
38 #ifdef HAIR_SHADER
39 #  ifdef V3D_SHADING_TEXTURE_COLOR
40         vec2 uv = hair_get_customdata_vec2(u);
41 #  endif
42         float time, thick_time, thickness;
43         vec3 pos, tan, binor;
44         hair_get_pos_tan_binor_time(
45                 (ProjectionMatrix[3][3] == 0.0),
46                 ModelMatrixInverse,
47                 ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz,
48                 pos, tan, binor, time, thickness, thick_time);
49         /* To "simulate" anisotropic shading, randomize hair normal per strand. */
50         hair_rand = integer_noise(hair_get_strand_id());
51         tan = normalize(tan);
52         vec3 nor = normalize(cross(binor, tan));
53         nor = normalize(mix(nor, -tan, hair_rand * 0.10));
54         float cos_theta = (hair_rand*2.0 - 1.0) * 0.20;
55         float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));
56         nor = nor * sin_theta + binor * cos_theta;
57         gl_Position = ViewProjectionMatrix * vec4(pos, 1.0);
58 #else
59         gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
60 #endif
61 #ifdef V3D_SHADING_TEXTURE_COLOR
62         uv_interp = uv;
63 #endif
64
65 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
66         normal_viewport = NormalMatrix * nor;
67 #  ifndef HAIR_SHADER
68         normal_viewport = normalize(normal_viewport);
69 #  endif
70 #endif
71 }