[Bf-blender-cvs] [ee44dd1b2bc] blender2.8: Studio Lights: Big Cleanups
Clément Foucault
noreply at git.blender.org
Mon Nov 19 15:54:30 CET 2018
Commit: ee44dd1b2bcff6bbd99084a012a40fb4a7100b2c
Author: Clément Foucault
Date: Mon Nov 19 01:01:43 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBee44dd1b2bcff6bbd99084a012a40fb4a7100b2c
Studio Lights: Big Cleanups
* Less Lengthy enum/macro names.
* Optimize computation of Spherical Harmonics.
* Reduce radiance cubemap size a bit. Higher resolution is not necessary.
* Remove STUDIOLIGHT_LIGHT_DIRECTION_CALCULATED (was not used).
* Do windowing on each component separately instead of using luminance.
* Use ITER_PIXELS to iterate on each pixels, using pixel center coords.
* Remove gpu_matcap_3components as it is only needed when creating the gputex.
* Fix a lot of confusion in axis denomination/swizzle.
These changes should not affect functionallity.
===================================================================
M source/blender/blenkernel/BKE_studiolight.h
M source/blender/blenkernel/intern/studiolight.c
M source/blender/draw/engines/eevee/eevee_lookdev.c
M source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl
M source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl
M source/blender/draw/engines/workbench/workbench_deferred.c
M source/blender/draw/engines/workbench/workbench_forward.c
M source/blender/draw/engines/workbench/workbench_materials.c
M source/blender/draw/engines/workbench/workbench_private.h
M source/blender/draw/engines/workbench/workbench_studiolight.c
M source/blender/makesrna/intern/rna_userdef.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_studiolight.h b/source/blender/blenkernel/BKE_studiolight.h
index 4a7f29d7190..cbb911ee32c 100644
--- a/source/blender/blenkernel/BKE_studiolight.h
+++ b/source/blender/blenkernel/BKE_studiolight.h
@@ -61,43 +61,36 @@
#define STUDIOLIGHT_ICON_SIZE 96
-#define STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL 2
-#define STUDIOLIGHT_SPHERICAL_HARMONICS_MAX_COMPONENTS 18
+/* Only 1 - 5 is supported */
+#define STUDIOLIGHT_SH_BANDS 3
-#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL == 0
-# define STUDIOLIGHT_SPHERICAL_HARMONICS_COMPONENTS 1
-#endif
-
-#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL == 1
-# define STUDIOLIGHT_SPHERICAL_HARMONICS_COMPONENTS 4
-#endif
+#define STUDIOLIGHT_SH_COEFS_LEN (STUDIOLIGHT_SH_BANDS * STUDIOLIGHT_SH_BANDS)
-#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL == 2
-# define STUDIOLIGHT_SPHERICAL_HARMONICS_COMPONENTS 9
-# define STUDIOLIGHT_SPHERICAL_HARMONICS_WINDOWING_TARGET_LAMPLACIAN 10.0f
+#if STUDIOLIGHT_SH_BANDS > 3
+/* Bypass L3 */
+#define STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN (STUDIOLIGHT_SH_COEFS_LEN - 7)
+#else
+#define STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN STUDIOLIGHT_SH_COEFS_LEN
#endif
-#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL == 4
-# define STUDIOLIGHT_SPHERICAL_HARMONICS_COMPONENTS 18
-#endif
struct GPUTexture;
struct StudioLight;
/* StudioLight.flag */
enum StudioLightFlag {
STUDIOLIGHT_SPHERICAL_HARMONICS_COEFFICIENTS_CALCULATED = (1 << 0),
- STUDIOLIGHT_LIGHT_DIRECTION_CALCULATED = (1 << 1),
+/* STUDIOLIGHT_LIGHT_DIRECTION_CALCULATED = (1 << 1), */
STUDIOLIGHT_INTERNAL = (1 << 2),
STUDIOLIGHT_EXTERNAL_FILE = (1 << 3),
- STUDIOLIGHT_USER_DEFINED = (1 << 12),
STUDIOLIGHT_ORIENTATION_CAMERA = (1 << 4),
STUDIOLIGHT_ORIENTATION_WORLD = (1 << 5),
STUDIOLIGHT_ORIENTATION_VIEWNORMAL = (1 << 6),
STUDIOLIGHT_EXTERNAL_IMAGE_LOADED = (1 << 7),
- STUDIOLIGHT_EQUIRECTANGULAR_IRRADIANCE_IMAGE_CALCULATED = (1 << 8),
- STUDIOLIGHT_EQUIRECTANGULAR_RADIANCE_GPUTEXTURE = (1 << 9),
- STUDIOLIGHT_EQUIRECTANGULAR_IRRADIANCE_GPUTEXTURE = (1 << 10),
+ STUDIOLIGHT_EQUIRECT_IRRADIANCE_IMAGE_CALCULATED = (1 << 8),
+ STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE = (1 << 9),
+ STUDIOLIGHT_EQUIRECT_IRRADIANCE_GPUTEXTURE = (1 << 10),
STUDIOLIGHT_RADIANCE_BUFFERS_CALCULATED = (1 << 11),
+ STUDIOLIGHT_USER_DEFINED = (1 << 12),
STUDIOLIGHT_UI_EXPANDED = (1 << 13),
};
@@ -121,14 +114,13 @@ typedef struct StudioLight {
int icon_id_radiance;
int icon_id_matcap;
int icon_id_matcap_flipped;
- float spherical_harmonics_coefs[STUDIOLIGHT_SPHERICAL_HARMONICS_COMPONENTS][3];
+ float spherical_harmonics_coefs[STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN][3];
float light_direction[3];
- ImBuf *equirectangular_radiance_buffer;
- ImBuf *equirectangular_irradiance_buffer;
+ ImBuf *equirect_radiance_buffer;
+ ImBuf *equirect_irradiance_buffer;
ImBuf *radiance_cubemap_buffers[6];
- struct GPUTexture *equirectangular_radiance_gputexture;
- struct GPUTexture *equirectangular_irradiance_gputexture;
- float *gpu_matcap_3components; /* 3 channel buffer for GPU_R11F_G11F_B10F */
+ struct GPUTexture *equirect_radiance_gputexture;
+ struct GPUTexture *equirect_irradiance_gputexture;
/*
* Free function to clean up the running icons previews (wmJob) the usage is in
diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c
index 0aeb6d78d44..d04c14299dc 100644
--- a/source/blender/blenkernel/intern/studiolight.c
+++ b/source/blender/blenkernel/intern/studiolight.c
@@ -58,27 +58,23 @@
/* Statics */
static ListBase studiolights;
static int last_studiolight_id = 0;
-#define STUDIOLIGHT_RADIANCE_CUBEMAP_SIZE 128
-#define STUDIOLIGHT_IRRADIANCE_EQUIRECTANGULAR_HEIGHT 32
-#define STUDIOLIGHT_IRRADIANCE_EQUIRECTANGULAR_WIDTH (STUDIOLIGHT_IRRADIANCE_EQUIRECTANGULAR_HEIGHT * 2)
+#define STUDIOLIGHT_RADIANCE_CUBEMAP_SIZE 96
+#define STUDIOLIGHT_IRRADIANCE_EQUIRECT_HEIGHT 32
+#define STUDIOLIGHT_IRRADIANCE_EQUIRECT_WIDTH (STUDIOLIGHT_IRRADIANCE_EQUIRECT_HEIGHT * 2)
-#define STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE 0
-#define STUDIOLIGHT_IRRADIANCE_METHOD_SPHERICAL_HARMONICS 1
/*
* The method to calculate the irradiance buffers
* The irradiance buffer is only shown in the background when in LookDev.
*
* STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE is very slow, but very accurate
* STUDIOLIGHT_IRRADIANCE_METHOD_SPHERICAL_HARMONICS is faster but has artifacts
+ * Cannot have both enabled at the same time!!!
*/
-// #define STUDIOLIGHT_IRRADIANCE_METHOD STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE
-#define STUDIOLIGHT_IRRADIANCE_METHOD STUDIOLIGHT_IRRADIANCE_METHOD_SPHERICAL_HARMONICS
+// #define STUDIOLIGHT_IRRADIANCE_METHOD_RADIANCE
+#define STUDIOLIGHT_IRRADIANCE_METHOD_SPHERICAL_HARMONICS
-#if 0 /* Temporarily disabled due to the creation of textures with -nan(ind)s */
-#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL == 2
-# define STUDIOLIGHT_SPHERICAL_HARMONICS_WINDOWING
-#endif
-#endif
+/* Temporarily disabled due to the creation of textures with -nan(ind)s */
+#define STUDIOLIGHT_SH_WINDOWING 0.0f /* 0.0 is disabled */
/*
* Disable this option so caches are not loaded from disk
@@ -90,6 +86,34 @@ static const char *STUDIOLIGHT_CAMERA_FOLDER = "studiolights/camera/";
static const char *STUDIOLIGHT_WORLD_FOLDER = "studiolights/world/";
static const char *STUDIOLIGHT_MATCAP_FOLDER = "studiolights/matcap/";
+/* ITER MACRO */
+
+/** Iter on all pixel giving texel center position and pixel pointer.
+ * Arguments
+ * type : type of src.
+ * src : source buffer.
+ * channels : number of channels per pixel.
+ *
+ * Others
+ * x, y : normalized UV coordinate [0..1] of the current pixel center.
+ * texel_size[2] : UV size of a pixel in this texture.
+ * pixel[] : pointer to the current pixel.
+ */
+#define ITER_PIXELS(type, src, channels, width, height) \
+{ \
+ float texel_size[2]; \
+ texel_size[0] = 1.0f / width; \
+ texel_size[1] = 1.0f / height; \
+ type (*pixel_)[channels] = (type (*)[channels])src; \
+ for (float y = 0.5 * texel_size[1]; y < 1.0; y += texel_size[1]) { \
+ for (float x = 0.5 * texel_size[0]; x < 1.0; x += texel_size[0], pixel_++) { \
+ type *pixel = *pixel_;
+
+#define ITER_PIXELS_END \
+ } \
+ } \
+} ((void)0)
+
/* FUNCTIONS */
#define IMB_SAFE_FREE(p) do { \
if (p) { \
@@ -125,13 +149,12 @@ static void studiolight_free(struct StudioLight *sl)
for (int index = 0; index < 6; index++) {
IMB_SAFE_FREE(sl->radiance_cubemap_buffers[index]);
}
- GPU_TEXTURE_SAFE_FREE(sl->equirectangular_radiance_gputexture);
- GPU_TEXTURE_SAFE_FREE(sl->equirectangular_irradiance_gputexture);
- IMB_SAFE_FREE(sl->equirectangular_radiance_buffer);
- IMB_SAFE_FREE(sl->equirectangular_irradiance_buffer);
+ GPU_TEXTURE_SAFE_FREE(sl->equirect_radiance_gputexture);
+ GPU_TEXTURE_SAFE_FREE(sl->equirect_irradiance_gputexture);
+ IMB_SAFE_FREE(sl->equirect_radiance_buffer);
+ IMB_SAFE_FREE(sl->equirect_irradiance_buffer);
MEM_SAFE_FREE(sl->path_irr_cache);
MEM_SAFE_FREE(sl->path_sh_cache);
- MEM_SAFE_FREE(sl->gpu_matcap_3components);
MEM_SAFE_FREE(sl);
}
@@ -161,13 +184,13 @@ static struct StudioLight *studiolight_create(int flag)
return sl;
}
-static void direction_to_equirectangular(float r[2], const float dir[3])
+static void direction_to_equirect(float r[2], const float dir[3])
{
r[0] = (atan2f(dir[1], dir[0]) - M_PI) / -(M_PI * 2);
r[1] = (acosf(dir[2] / 1.0) - M_PI) / -M_PI;
}
-static void equirectangular_to_direction(float r[3], float u, float v)
+static void equirect_to_direction(float r[3], float u, float v)
{
float phi = (-(M_PI * 2)) * u + M_PI;
float theta = -M_PI * v + M_PI;
@@ -177,38 +200,47 @@ static void equirectangular_to_direction(float r[3], float u, float v)
r[2] = cosf(theta);
}
-static void studiolight_calculate_radiance(ImBuf *ibuf, float color[4], const float direction[3])
+static void direction_to_cube_face_uv(float r_uv[2], int *r_face, const float dir[3])
{
- float uv[2];
- direction_to_equirectangular(uv, direction);
- nearest_interpolation_color_wrap(ibuf, NULL, color, uv[0] * ibuf->x, uv[1] * ibuf->y);
+ if (fabsf(dir[0]) > fabsf(dir[1]) && fabsf(dir[0]) > fabsf(dir[2])) {
+ bool is_pos = (dir[0] > 0.0f);
+ *r_face = is_pos ? STUDIOLIGHT_X_POS : STUDIOLIGHT_X_NEG;
+ r_uv[0] = dir[2] / fabsf(dir[0]) * (is_pos ? 1 : -1);
+ r_uv[1] = dir[1] / fabsf(dir[0]) * (is_pos ? -1 : -1);
+ }
+ else if (fabsf(dir[1]) > fabsf(dir[0]) && fabsf(dir[1]) > fabsf(dir[2])) {
+ bool is_pos = (dir[1] > 0.0f);
+ *r_face = is_pos ? STUDIOLIGHT_Y_POS : STUDIOLIGHT_Y_NEG;
+ r_uv[0] = dir[0] / fabsf(dir[1]) * (is_pos ? 1 : 1);
+ r_uv[1] = dir[2] / fabsf(dir[1]) * (is_pos ? -1 : 1);
+ }
+ else {
+ bool is_pos = (dir[2] > 0.0f);
+ *r_face = is_pos ? STUDIOLIGHT_Z_NEG : STUDIOLIGHT_Z_POS;
+ r_uv[0] = dir[0] / fabsf(dir[2]) * (is_pos ? -1 : 1);
+ r_uv[1] = dir[1] / fabsf(dir[2]) * (is_pos ? -1 : -1);
+ }
+ r_uv[0] = r_uv[0] * 0.5f + 0.5f;
+ r_uv[1] = r_uv[1] * 0.5f + 0.5f;
}
-static void studiolight_calculate_radiance_buffer(
- ImBuf *ibuf, float *colbuf,
- const float start_x, const float add_x,
- const float start_y, const float add_y, const float z,
- const int index_x, const int index_y, const int index_z)
+static void cube_face_uv_to_direction(float r_dir[3], flo
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list