Workbench: Rename orientation to type and Camera studio light to Studio
[blender.git] / source / blender / draw / engines / workbench / shaders / workbench_prepass_frag.glsl
1 uniform int object_id = 0;
2
3 uniform vec4 materialDiffuseColor;
4 uniform vec4 materialSpecularColor;
5 uniform float materialRoughness;
6
7 #ifdef V3D_SHADING_TEXTURE_COLOR
8 uniform sampler2D image;
9 uniform float ImageTransparencyCutoff = 0.1;
10
11 #endif
12
13 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
14 in vec3 normal_viewport;
15 #endif /* NORMAL_VIEWPORT_PASS_ENABLED */
16
17 #ifdef V3D_SHADING_TEXTURE_COLOR
18 in vec2 uv_interp;
19 #endif /* V3D_SHADING_TEXTURE_COLOR */
20
21 #ifdef HAIR_SHADER
22 flat in float hair_rand;
23 #endif
24
25 layout(location=0) out uint objectId;
26 layout(location=1) out vec4 diffuseColor;
27 layout(location=2) out vec4 specularColor;
28 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
29 #  ifdef WORKBENCH_ENCODE_NORMALS
30 layout(location=3) out vec2 normalViewport;
31 #  else /* WORKBENCH_ENCODE_NORMALS */
32 layout(location=3) out vec3 normalViewport;
33 #  endif /* WORKBENCH_ENCODE_NORMALS */
34 #endif /* NORMAL_VIEWPORT_PASS_ENABLED */
35
36 void main()
37 {
38         objectId = uint(object_id);
39
40 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
41         vec3 n = (gl_FrontFacing) ? normal_viewport : -normal_viewport;
42         n = normalize(n);
43 #endif
44
45 #ifdef V3D_SHADING_TEXTURE_COLOR
46         diffuseColor = texture(image, uv_interp);
47         if (diffuseColor.a < ImageTransparencyCutoff) {
48                 discard;
49         }
50 #else
51         diffuseColor = vec4(materialDiffuseColor.rgb, 0.0);
52 #  ifdef STUDIOLIGHT_TYPE_MATCAP
53         specularColor = vec4(materialDiffuseColor.rgb, 0.0);
54
55 #  endif
56 #endif /* V3D_SHADING_TEXTURE_COLOR */
57
58 #ifdef HAIR_SHADER
59         float hair_color_variation = hair_rand * 0.1;
60         diffuseColor.rgb = clamp(diffuseColor.rgb - hair_color_variation, 0.0, 1.0);
61 #endif
62
63 #ifdef V3D_SHADING_SPECULAR_HIGHLIGHT
64         specularColor = vec4(materialSpecularColor.rgb, materialRoughness);
65 #  ifdef HAIR_SHADER
66         specularColor.rgb = clamp(specularColor.rgb - hair_color_variation, 0.0, 1.0);
67 #  endif
68 #endif
69
70 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
71 #  ifdef WORKBENCH_ENCODE_NORMALS
72         diffuseColor.a = float(gl_FrontFacing);
73         normalViewport = normal_encode(n);
74 #  else /* WORKBENCH_ENCODE_NORMALS */
75         normalViewport = n;
76 #  endif /* WORKBENCH_ENCODE_NORMALS */
77 #  ifdef HAIR_SHADER
78         diffuseColor.a = 0.5;
79 #  endif
80 #endif /* NORMAL_VIEWPORT_PASS_ENABLED */
81 }