4c034460bd3f6dd2304f96941cddba9234403ab0
[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 mat4 ProjectionMatrix;
5 uniform mat3 normalWorldMatrix;
6 uniform float alpha = 0.5;
7 uniform vec2 invertedViewportSize;
8 uniform vec4 viewvecs[3];
9
10 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
11 in vec3 normal_viewport;
12 #endif /* NORMAL_VIEWPORT_PASS_ENABLED */
13 #ifdef OB_TEXTURE
14 in vec2 uv_interp;
15 #endif
16 #ifdef STUDIOLIGHT_ORIENTATION_VIEWNORMAL
17 uniform sampler2D matcapImage;
18 #endif
19
20 layout(std140) uniform world_block {
21         WorldData world_data;
22 };
23
24 layout(std140) uniform material_block {
25         MaterialData material_data;
26 };
27
28 layout(location=0) out vec4 transparentAccum;
29
30
31 void main()
32 {
33         vec4 diffuse_color;
34         vec3 diffuse_light = vec3(1.0);
35 #ifdef OB_SOLID
36         diffuse_color = material_data.diffuse_color;
37 #endif /* OB_SOLID */
38 #ifdef OB_TEXTURE
39         diffuse_color = texture(image, uv_interp);
40 #endif /* OB_TEXTURE */
41
42         vec2 uv_viewport = gl_FragCoord.xy * invertedViewportSize;
43         vec3 I_vs = view_vector_from_screen_uv(uv_viewport, viewvecs, ProjectionMatrix);
44
45 #ifdef V3D_LIGHTING_MATCAP
46         bool flipped = world_data.matcap_orientation != 0;
47         vec2 matcap_uv = matcap_uv_compute(I_vs, normal_viewport, flipped);
48         diffuse_light = texture(matcapImage, matcap_uv).rgb;
49 #endif
50
51 #ifdef V3D_SHADING_SPECULAR_HIGHLIGHT
52         vec3 specular_color = get_world_specular_lights(world_data, vec4(material_data.specular_color.rgb, material_data.roughness), normal_viewport, I_vs;
53 #else
54         vec3 specular_color = vec3(0.0);
55 #endif
56
57 #ifdef V3D_LIGHTING_STUDIO
58 #  ifdef STUDIOLIGHT_ORIENTATION_CAMERA
59         diffuse_light = get_camera_diffuse_light(world_data, normal_viewport);
60 #  endif
61 #  ifdef STUDIOLIGHT_ORIENTATION_WORLD
62         vec3 normal_world = normalWorldMatrix * normal_viewport;
63         diffuse_light = get_world_diffuse_light(world_data, normal_world);
64 #  endif
65 #endif
66
67         vec3 shaded_color = diffuse_light * diffuse_color.rgb + specular_color;
68
69         vec4 premultiplied = vec4(shaded_color.rgb * alpha, alpha);
70         transparentAccum = calculate_transparent_accum(premultiplied);
71 }
72