diff options
Diffstat (limited to 'source/blender/draw/engines/workbench')
5 files changed, 26 insertions, 6 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl index 2ba6e0e8e55..2d913c63b00 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl @@ -4,7 +4,7 @@ struct LightData { }; struct WorldData { - vec3 spherical_harmonics_coefs[9]; + vec3 spherical_harmonics_coefs[STUDIOLIGHT_SPHERICAL_HARMONICS_MAX_COMPONENTS]; vec4 background_color_low; vec4 background_color_high; vec4 object_outline_color; diff --git a/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl index 71adc751f0a..b13c4f1b43b 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl @@ -1,32 +1,36 @@ #define BLINN -vec3 spherical_harmonics_L2(vec3 N, vec3 spherical_harmonics_coefs[9]) +vec3 spherical_harmonics(vec3 N, vec3 spherical_harmonics_coefs[STUDIOLIGHT_SPHERICAL_HARMONICS_MAX_COMPONENTS]) { vec3 sh = vec3(0.0); sh += 0.282095 * spherical_harmonics_coefs[0]; +#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL > 0 sh += -0.488603 * N.z * spherical_harmonics_coefs[1]; sh += 0.488603 * N.y * spherical_harmonics_coefs[2]; sh += -0.488603 * N.x * spherical_harmonics_coefs[3]; +#endif +#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL > 1 sh += 1.092548 * N.x * N.z * spherical_harmonics_coefs[4]; sh += -1.092548 * N.z * N.y * spherical_harmonics_coefs[5]; sh += 0.315392 * (3.0 * N.y * N.y - 1.0) * spherical_harmonics_coefs[6]; sh += -1.092548 * N.x * N.y * spherical_harmonics_coefs[7]; sh += 0.546274 * (N.x * N.x - N.z * N.z) * spherical_harmonics_coefs[8]; +#endif return sh; } vec3 get_world_diffuse_light(WorldData world_data, vec3 N) { - return (spherical_harmonics_L2(vec3(N.x, N.y, -N.z), world_data.spherical_harmonics_coefs)); + return (spherical_harmonics(vec3(N.x, N.y, -N.z), world_data.spherical_harmonics_coefs)); } vec3 get_camera_diffuse_light(WorldData world_data, vec3 N) { - return (spherical_harmonics_L2(vec3(N.x, -N.z, -N.y), world_data.spherical_harmonics_coefs)); + return (spherical_harmonics(vec3(N.x, -N.z, -N.y), world_data.spherical_harmonics_coefs)); } /* N And I are in View Space. */ diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c index 231d9a9582a..c0857cf74aa 100644 --- a/source/blender/draw/engines/workbench/workbench_materials.c +++ b/source/blender/draw/engines/workbench/workbench_materials.c @@ -95,6 +95,17 @@ char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd, int drawtype, BLI_dynstr_appendf(ds, "#define HAIR_SHADER\n"); } +#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL == 0 + BLI_dynstr_appendf(ds, "#define STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL 0\n"); +#endif +#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL == 1 + BLI_dynstr_appendf(ds, "#define STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL 1\n"); +#endif +#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL == 2 + BLI_dynstr_appendf(ds, "#define STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL 2\n"); +#endif + BLI_dynstr_appendf(ds, "#define STUDIOLIGHT_SPHERICAL_HARMONICS_MAX_COMPONENTS 9\n"); + str = BLI_dynstr_get_cstring(ds); BLI_dynstr_free(ds); return str; diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h index 9e43a5c4a48..68d50a85c35 100644 --- a/source/blender/draw/engines/workbench/workbench_private.h +++ b/source/blender/draw/engines/workbench/workbench_private.h @@ -112,7 +112,7 @@ typedef struct WORKBENCH_UBO_Light { } WORKBENCH_UBO_Light; typedef struct WORKBENCH_UBO_World { - float spherical_harmonics_coefs[9][4]; + float spherical_harmonics_coefs[STUDIOLIGHT_SPHERICAL_HARMONICS_MAX_COMPONENTS][4]; float background_color_low[4]; float background_color_high[4]; float object_outline_color[4]; diff --git a/source/blender/draw/engines/workbench/workbench_studiolight.c b/source/blender/draw/engines/workbench/workbench_studiolight.c index f2453bf7070..f9e5df91388 100644 --- a/source/blender/draw/engines/workbench/workbench_studiolight.c +++ b/source/blender/draw/engines/workbench/workbench_studiolight.c @@ -34,10 +34,15 @@ void studiolight_update_world(StudioLight *sl, WORKBENCH_UBO_World *wd) { + int i; BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_SPHERICAL_HARMONICS_COEFFICIENTS_CALCULATED); - for (int i = 0; i < 9; i++) { + + for (i = 0; i < STUDIOLIGHT_SPHERICAL_HARMONICS_COMPONENTS; i++) { copy_v3_v3(wd->spherical_harmonics_coefs[i], sl->spherical_harmonics_coefs[i]); } + for (; i < STUDIOLIGHT_SPHERICAL_HARMONICS_MAX_COMPONENTS; i++) { + copy_v3_fl(wd->spherical_harmonics_coefs[i], 0.0); + } } static void compute_parallel_lines_nor_and_dist(const float v1[2], const float v2[2], const float v3[2], float r_line[2]) |