Workbench: Matcaps T55291
[blender.git] / source / blender / draw / engines / workbench / shaders / workbench_prepass_frag.glsl
1 uniform int object_id = 0;
2
3 layout(std140) uniform material_block {
4         MaterialData material_data;
5 };
6
7 #ifdef OB_TEXTURE
8 uniform sampler2D image;
9 #endif
10
11 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
12 in vec3 position_viewport;
13 in vec3 normal_viewport;
14 #endif /* NORMAL_VIEWPORT_PASS_ENABLED */
15 #ifdef OB_TEXTURE
16 in vec2 uv_interp;
17 #endif /* OB_TEXTURE */
18
19 #ifdef HAIR_SHADER
20 flat in float hair_rand;
21 #endif
22
23 layout(location=0) out uint objectId;
24 layout(location=1) out vec4 diffuseColor;
25 layout(location=2) out vec4 specularColor;
26 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
27 #  ifdef WORKBENCH_ENCODE_NORMALS
28 layout(location=3) out vec2 normalViewport;
29 #  else /* WORKBENCH_ENCODE_NORMALS */
30 layout(location=3) out vec3 normalViewport;
31 #  endif /* WORKBENCH_ENCODE_NORMALS */
32 #endif /* NORMAL_VIEWPORT_PASS_ENABLED */
33
34 void main()
35 {
36         objectId = uint(object_id);
37
38 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
39         vec3 n = (gl_FrontFacing) ? normal_viewport : -normal_viewport;
40         n = normalize(n);
41 #endif
42
43 #ifdef OB_SOLID
44         diffuseColor = vec4(material_data.diffuse_color.rgb, 0.0);
45 #  ifdef STUDIOLIGHT_ORIENTATION_VIEWNORMAL
46         specularColor = vec4(material_data.diffuse_color.rgb, material_data.matcap_texture_index);
47 #  endif
48 #endif /* OB_SOLID */
49
50 #ifdef OB_TEXTURE
51         diffuseColor = texture(image, uv_interp);
52 #endif /* OB_TEXTURE */
53 #ifdef HAIR_SHADER
54         float hair_color_variation = hair_rand * 0.1;
55         diffuseColor.rgb = clamp(diffuseColor.rgb - hair_color_variation, 0.0, 1.0);
56 #endif
57
58 #ifdef V3D_SHADING_SPECULAR_HIGHLIGHT
59         specularColor = vec4(material_data.specular_color.rgb, material_data.roughness);
60 #  ifdef HAIR_SHADER
61         specularColor.rgb = clamp(specularColor.rgb - hair_color_variation, 0.0, 1.0);
62 #  endif
63 #endif
64
65 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
66 #  ifdef WORKBENCH_ENCODE_NORMALS
67         diffuseColor.a = float(gl_FrontFacing);
68         normalViewport = normal_encode(n);
69 #  else /* WORKBENCH_ENCODE_NORMALS */
70         normalViewport = n;
71 #  endif /* WORKBENCH_ENCODE_NORMALS */
72 #  ifdef HAIR_SHADER
73         diffuseColor.a = 0.5;
74 #  endif
75 #endif /* NORMAL_VIEWPORT_PASS_ENABLED */
76 }