Workbench: Add "Shadow" factor to Xray
This just maintain more parity accross the 2 visuals. Note that this is not "real shadowing" just the facing factor shadowing.
This commit is contained in:
parent
bc99f4903c
commit
8134f3f0a6
|
@ -14,6 +14,11 @@ uniform vec3 materialDiffuseColor;
|
|||
uniform vec3 materialSpecularColor;
|
||||
uniform float materialRoughness;
|
||||
|
||||
uniform float shadowMultiplier = 0.5;
|
||||
uniform float lightMultiplier = 1.0;
|
||||
uniform float shadowShift = 0.1;
|
||||
uniform float shadowFocus = 1.0;
|
||||
|
||||
#ifdef NORMAL_VIEWPORT_PASS_ENABLED
|
||||
in vec3 normal_viewport;
|
||||
#endif /* NORMAL_VIEWPORT_PASS_ENABLED */
|
||||
|
@ -67,6 +72,12 @@ void main()
|
|||
nor, I_vs);
|
||||
#endif
|
||||
|
||||
#ifdef V3D_SHADING_SHADOW
|
||||
float light_factor = -dot(nor, world_data.shadow_direction_vs.xyz);
|
||||
float shadow_mix = smoothstep(shadowFocus, shadowShift, light_factor);
|
||||
shaded_color *= mix(lightMultiplier, shadowMultiplier, shadow_mix);
|
||||
#endif
|
||||
|
||||
/* Based on :
|
||||
* McGuire and Bavoil, Weighted Blended Order-Independent Transparency, Journal of
|
||||
* Computer Graphics Techniques (JCGT), vol. 2, no. 2, 122–141, 2013
|
||||
|
|
|
@ -76,6 +76,12 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
|
|||
wpd->shading.studio_light, STUDIOLIGHT_TYPE_STUDIO);
|
||||
}
|
||||
|
||||
|
||||
float shadow_focus = scene->display.shadow_focus;
|
||||
/* Clamp to avoid overshadowing and shading errors. */
|
||||
CLAMP(shadow_focus, 0.0001f, 0.99999f);
|
||||
wpd->shadow_shift = scene->display.shadow_shift;
|
||||
wpd->shadow_focus = 1.0f - shadow_focus * (1.0f - wpd->shadow_shift);
|
||||
wpd->shadow_multiplier = 1.0 - wpd->shading.shadow_intensity;
|
||||
|
||||
WORKBENCH_UBO_World *wd = &wpd->world_data;
|
||||
|
|
|
@ -699,11 +699,6 @@ void workbench_deferred_cache_init(WORKBENCH_Data *vedata)
|
|||
workbench_private_data_get_light_direction(wpd, e_data.display.light_direction);
|
||||
studiolight_update_light(wpd, e_data.display.light_direction);
|
||||
|
||||
float shadow_focus = scene->display.shadow_focus;
|
||||
/* Clamp to avoid overshadowing and shading errors. */
|
||||
CLAMP(shadow_focus, 0.0001f, 0.99999f);
|
||||
shadow_focus = 1.0f - shadow_focus * (1.0f - scene->display.shadow_shift);
|
||||
|
||||
if (SHADOW_ENABLED(wpd)) {
|
||||
psl->composite_pass = DRW_pass_create(
|
||||
"Composite", DRW_STATE_WRITE_COLOR | DRW_STATE_STENCIL_EQUAL | DRW_STATE_DEPTH_GREATER);
|
||||
|
@ -713,7 +708,7 @@ void workbench_deferred_cache_init(WORKBENCH_Data *vedata)
|
|||
DRW_shgroup_uniform_float_copy(grp, "lightMultiplier", 1.0f);
|
||||
DRW_shgroup_uniform_float(grp, "shadowMultiplier", &wpd->shadow_multiplier, 1);
|
||||
DRW_shgroup_uniform_float_copy(grp, "shadowShift", scene->display.shadow_shift);
|
||||
DRW_shgroup_uniform_float_copy(grp, "shadowFocus", shadow_focus);
|
||||
DRW_shgroup_uniform_float_copy(grp, "shadowFocus", wpd->shadow_focus);
|
||||
DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
|
||||
|
||||
/* Stencil Shadow passes. */
|
||||
|
@ -753,7 +748,7 @@ void workbench_deferred_cache_init(WORKBENCH_Data *vedata)
|
|||
DRW_shgroup_uniform_float(grp, "lightMultiplier", &wpd->shadow_multiplier, 1);
|
||||
DRW_shgroup_uniform_float(grp, "shadowMultiplier", &wpd->shadow_multiplier, 1);
|
||||
DRW_shgroup_uniform_float_copy(grp, "shadowShift", scene->display.shadow_shift);
|
||||
DRW_shgroup_uniform_float_copy(grp, "shadowFocus", shadow_focus);
|
||||
DRW_shgroup_uniform_float_copy(grp, "shadowFocus", wpd->shadow_focus);
|
||||
DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -182,6 +182,11 @@ WORKBENCH_MaterialData *workbench_forward_get_or_create_material_data(
|
|||
if (SPECULAR_HIGHLIGHT_ENABLED(wpd) || MATCAP_ENABLED(wpd)) {
|
||||
DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1);
|
||||
}
|
||||
if (SHADOW_ENABLED(wpd)) {
|
||||
DRW_shgroup_uniform_float_copy(grp, "shadowMultiplier", wpd->shadow_multiplier);
|
||||
DRW_shgroup_uniform_float_copy(grp, "shadowShift", wpd->shadow_shift);
|
||||
DRW_shgroup_uniform_float_copy(grp, "shadowFocus", wpd->shadow_focus);
|
||||
}
|
||||
|
||||
workbench_material_shgroup_uniform(wpd, grp, material, ob, false, false, interp);
|
||||
material->shgrp = grp;
|
||||
|
@ -212,7 +217,6 @@ WORKBENCH_MaterialData *workbench_forward_get_or_create_material_data(
|
|||
static GPUShader *ensure_forward_accum_shaders(WORKBENCH_PrivateData *wpd, bool use_textures, bool is_hair)
|
||||
{
|
||||
int index = workbench_material_get_accum_shader_index(wpd, use_textures, is_hair);
|
||||
BLI_assert(index < MAX_ACCUM_SHADERS);
|
||||
if (e_data.transparent_accum_sh_cache[index] == NULL) {
|
||||
char *defines = workbench_material_build_defines(wpd, use_textures, is_hair);
|
||||
char *transparent_accum_vert = workbench_build_forward_vert(is_hair);
|
||||
|
|
|
@ -179,6 +179,7 @@ int workbench_material_get_composite_shader_index(WORKBENCH_PrivateData *wpd)
|
|||
SET_FLAG_FROM_TEST(index, wpd->shading.flag & V3D_SHADING_CAVITY, 1 << 3);
|
||||
SET_FLAG_FROM_TEST(index, wpd->shading.flag & V3D_SHADING_OBJECT_OUTLINE, 1 << 4);
|
||||
SET_FLAG_FROM_TEST(index, MATDATA_PASS_ENABLED(wpd), 1 << 5);
|
||||
BLI_assert(index < MAX_COMPOSITE_SHADERS);
|
||||
return index;
|
||||
}
|
||||
|
||||
|
@ -194,6 +195,7 @@ int workbench_material_get_prepass_shader_index(
|
|||
SET_FLAG_FROM_TEST(index, MATCAP_ENABLED(wpd), 1 << 4);
|
||||
SET_FLAG_FROM_TEST(index, use_textures, 1 << 5);
|
||||
SET_FLAG_FROM_TEST(index, wpd->world_clip_planes != NULL, 1 << 6);
|
||||
BLI_assert(index < MAX_PREPASS_SHADERS);
|
||||
return index;
|
||||
}
|
||||
|
||||
|
@ -205,6 +207,9 @@ int workbench_material_get_accum_shader_index(WORKBENCH_PrivateData *wpd, bool u
|
|||
index = SPECULAR_HIGHLIGHT_ENABLED(wpd) ? 3 : wpd->shading.light;
|
||||
SET_FLAG_FROM_TEST(index, use_textures, 1 << 2);
|
||||
SET_FLAG_FROM_TEST(index, is_hair, 1 << 3);
|
||||
/* 1 bits SHADOWS (only facing factor) */
|
||||
SET_FLAG_FROM_TEST(index, SHADOW_ENABLED(wpd), 1 << 4);
|
||||
BLI_assert(index < MAX_ACCUM_SHADERS);
|
||||
return index;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
#define M_GOLDEN_RATION_CONJUGATE 0.618033988749895
|
||||
#define MAX_COMPOSITE_SHADERS (1 << 6)
|
||||
#define MAX_PREPASS_SHADERS (1 << 7)
|
||||
#define MAX_ACCUM_SHADERS (1 << 4)
|
||||
#define MAX_ACCUM_SHADERS (1 << 5)
|
||||
#define MAX_CAVITY_SHADERS (1 << 3)
|
||||
|
||||
#define TEXTURE_DRAWING_ENABLED(wpd) (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR)
|
||||
|
@ -212,6 +212,8 @@ typedef struct WORKBENCH_PrivateData {
|
|||
struct DRWShadingGroup *depth_shgrp;
|
||||
WORKBENCH_UBO_World world_data;
|
||||
float shadow_multiplier;
|
||||
float shadow_shift;
|
||||
float shadow_focus;
|
||||
float cached_shadow_direction[3];
|
||||
float shadow_mat[4][4];
|
||||
float shadow_inv[4][4];
|
||||
|
|
Loading…
Reference in New Issue