bc7741f853c9a95b176f2ed5930720c0144f23a1
[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 #ifdef OB_SOLID
38         diffuseColor = vec4(material_data.diffuse_color.rgb, 0.0);
39 #endif /* OB_SOLID */
40 #ifdef OB_TEXTURE
41         diffuseColor = texture(image, uv_interp);
42 #endif /* OB_TEXTURE */
43 #ifdef HAIR_SHADER
44         float hair_color_variation = hair_rand * 0.1;
45         diffuseColor.rgb = clamp(diffuseColor.rgb - hair_color_variation, 0.0, 1.0);
46 #endif
47
48 #ifdef V3D_SHADING_SPECULAR_HIGHLIGHT
49         specularColor = vec4(material_data.specular_color.rgb, material_data.roughness);
50 #ifdef HAIR_SHADER
51         specularColor.rgb = clamp(specularColor.rgb - hair_color_variation, 0.0, 1.0);
52 #endif
53 #endif
54
55 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
56         vec3 n = (gl_FrontFacing) ? normal_viewport : -normal_viewport;
57         n = normalize(n);
58 #  ifdef WORKBENCH_ENCODE_NORMALS
59         diffuseColor.a = float(gl_FrontFacing);
60         normalViewport = normal_encode(n);
61 #  else /* WORKBENCH_ENCODE_NORMALS */
62         normalViewport = n;
63 #  endif /* WORKBENCH_ENCODE_NORMALS */
64 #  ifdef HAIR_SHADER
65         diffuseColor.a = 0.5;
66 #  endif
67 #endif /* NORMAL_VIEWPORT_PASS_ENABLED */
68 }