Workbench: Matcaps T55291
[blender.git] / source / blender / draw / engines / workbench / shaders / workbench_forward_transparent_accum_frag.glsl
1 #ifdef OB_TEXTURE
2 uniform sampler2D image;
3 #endif
4 uniform mat3 normalWorldMatrix;
5 uniform float alpha = 0.5;
6
7 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
8 in vec3 normal_viewport;
9 #endif /* NORMAL_VIEWPORT_PASS_ENABLED */
10 #ifdef OB_TEXTURE
11 in vec2 uv_interp;
12 #endif
13 #ifdef STUDIOLIGHT_ORIENTATION_VIEWNORMAL
14 uniform sampler2D matcapImage;
15 #endif
16
17 layout(std140) uniform world_block {
18         WorldData world_data;
19 };
20
21 layout(std140) uniform material_block {
22         MaterialData material_data;
23 };
24
25 layout(location=0) out vec4 transparentAccum;
26
27
28 void main()
29 {
30         vec4 diffuse_color;
31         vec3 diffuse_light = vec3(1.0);
32 #ifdef OB_SOLID
33         diffuse_color = material_data.diffuse_color;
34 #endif /* OB_SOLID */
35 #ifdef OB_TEXTURE
36         diffuse_color = texture(image, uv_interp);
37 #endif /* OB_TEXTURE */
38
39 #ifdef V3D_LIGHTING_MATCAP
40         diffuse_light = texture(matcapImage, normal_viewport.xy / 2.0 + 0.5).rgb;
41 #endif
42
43 #ifdef V3D_SHADING_SPECULAR_HIGHLIGHT
44         vec3 specular_color = get_world_specular_lights(world_data, vec4(material_data.specular_color.rgb, material_data.roughness), normal_viewport, vec3(0.0, 0.0, 1.0));
45 #else
46         vec3 specular_color = vec3(0.0);
47 #endif
48
49 #ifdef V3D_LIGHTING_STUDIO
50 #  ifdef STUDIOLIGHT_ORIENTATION_CAMERA
51         diffuse_light = get_camera_diffuse_light(world_data, normal_viewport);
52 #  endif
53 #  ifdef STUDIOLIGHT_ORIENTATION_WORLD
54         vec3 normal_world = normalWorldMatrix * normal_viewport;
55         diffuse_light = get_world_diffuse_light(world_data, normal_world);
56 #  endif
57 #endif
58
59         vec3 shaded_color = diffuse_light * diffuse_color.rgb + specular_color;
60
61         vec4 premultiplied = vec4(shaded_color.rgb * alpha, alpha);
62         transparentAccum = calculate_transparent_accum(premultiplied);
63 }
64