Workbench: Flipping MatCaps for forward shading
[blender.git] / source / blender / draw / engines / workbench / workbench_deferred.c
index 428e5d4f7c8e2998f9c57a4b03971b565fa36ebd..b02c8ef3a4fb885ca359aa061fa9fd23dd4be35a 100644 (file)
@@ -113,7 +113,7 @@ static char *workbench_build_composite_frag(WORKBENCH_PrivateData *wpd)
        BLI_dynstr_append(ds, datatoc_workbench_common_lib_glsl);
        BLI_dynstr_append(ds, datatoc_workbench_background_lib_glsl);
 
        BLI_dynstr_append(ds, datatoc_workbench_common_lib_glsl);
        BLI_dynstr_append(ds, datatoc_workbench_background_lib_glsl);
 
-       if ((wpd->shading.light & V3D_LIGHTING_STUDIO) || (wpd->shading.flag & V3D_SHADING_SPECULAR_HIGHLIGHT)) {
+       if ((wpd->shading.light & V3D_LIGHTING_MATCAP) || (wpd->shading.light & V3D_LIGHTING_STUDIO) || (wpd->shading.flag & V3D_SHADING_SPECULAR_HIGHLIGHT)) {
                BLI_dynstr_append(ds, datatoc_workbench_world_light_lib_glsl);
        }
        if (wpd->shading.flag & V3D_SHADING_OBJECT_OUTLINE) {
                BLI_dynstr_append(ds, datatoc_workbench_world_light_lib_glsl);
        }
        if (wpd->shading.flag & V3D_SHADING_OBJECT_OUTLINE) {
@@ -439,32 +439,14 @@ static void workbench_composite_uniforms(WORKBENCH_PrivateData *wpd, DRWShadingG
        }
        if (SPECULAR_HIGHLIGHT_ENABLED(wpd) || MATCAP_ENABLED(wpd)) {
                DRW_shgroup_uniform_texture_ref(grp, "specularBuffer", &e_data.specular_buffer_tx);
        }
        if (SPECULAR_HIGHLIGHT_ENABLED(wpd) || MATCAP_ENABLED(wpd)) {
                DRW_shgroup_uniform_texture_ref(grp, "specularBuffer", &e_data.specular_buffer_tx);
-
-#if 0
-               float invwinmat[4][4];
-               DRW_viewport_matrix_get(invwinmat, DRW_MAT_WININV);
-
-               copy_v4_fl4(e_data.screenvecs[0],  1.0f, -1.0f, 0.0f, 1.0f);
-               copy_v4_fl4(e_data.screenvecs[1], -1.0f,  1.0f, 0.0f, 1.0f);
-               copy_v4_fl4(e_data.screenvecs[2], -1.0f, -1.0f, 0.0f, 1.0f);
-               for (int i = 0; i < 3; i++) {
-                       mul_m4_v4(invwinmat, e_data.screenvecs[i]);
-                       e_data.screenvecs[i][0] /= e_data.screenvecs[i][3]; /* perspective divide */
-                       e_data.screenvecs[i][1] /= e_data.screenvecs[i][3]; /* perspective divide */
-                       e_data.screenvecs[i][2] /= e_data.screenvecs[i][3]; /* perspective divide */
-                       e_data.screenvecs[i][3] = 1.0f;
-               }
-               sub_v3_v3(e_data.screenvecs[0], e_data.screenvecs[2]);
-               sub_v3_v3(e_data.screenvecs[1], e_data.screenvecs[2]);
-               DRW_shgroup_uniform_vec4(grp, "screenvecs[0]", e_data.screenvecs[0], 3);
-#endif
+               DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)wpd->viewvecs, 3);
        }
        DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo);
        DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1);
 
        if (STUDIOLIGHT_ORIENTATION_VIEWNORMAL_ENABLED(wpd)) {
                BKE_studiolight_ensure_flag(wpd->studio_light, STUDIOLIGHT_EQUIRECTANGULAR_RADIANCE_GPUTEXTURE);
        }
        DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo);
        DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1);
 
        if (STUDIOLIGHT_ORIENTATION_VIEWNORMAL_ENABLED(wpd)) {
                BKE_studiolight_ensure_flag(wpd->studio_light, STUDIOLIGHT_EQUIRECTANGULAR_RADIANCE_GPUTEXTURE);
-               DRW_shgroup_uniform_texture(grp, "matcapImage", wpd->studio_light->equirectangular_radiance_gputexture);
+               DRW_shgroup_uniform_texture(grp, "matcapImage", wpd->studio_light->equirectangular_radiance_gputexture);                DRW_shgroup_uniform_texture(grp, "matcapImage", wpd->studio_light->equirectangular_radiance_gputexture);
        }
 
        workbench_material_set_normal_world_matrix(grp, wpd, e_data.normal_world_matrix);
        }
 
        workbench_material_set_normal_world_matrix(grp, wpd, e_data.normal_world_matrix);