Studiolight: fixed diffuse lighting

- Orientation of the cubemap were not conform cycles and eevee
- one side of the cubemap was flipped, so one side was overlit and the
other side was to dark.
This commit is contained in:
Jeroen Bakker 2018-06-20 14:58:55 +02:00
parent c6ab911744
commit 0fb1093b14
1 changed files with 19 additions and 8 deletions

View File

@ -60,6 +60,12 @@ static ListBase studiolights;
#define STUDIOLIGHT_IRRADIANCE_EQUIRECTANGULAR_HEIGHT 32
#define STUDIOLIGHT_IRRADIANCE_EQUIRECTANGULAR_WIDTH (STUDIOLIGHT_IRRADIANCE_EQUIRECTANGULAR_HEIGHT * 2)
/*
Disable this option so caches are not loaded from disk
Do not checkin with this commented out
*/
#define STUDIOLIGHT_LOAD_CACHED_FILES
static const char *STUDIOLIGHT_CAMERA_FOLDER = "studiolights/camera/";
static const char *STUDIOLIGHT_WORLD_FOLDER = "studiolights/world/";
static const char *STUDIOLIGHT_MATCAP_FOLDER = "studiolights/matcap/";
@ -345,25 +351,25 @@ static void studiolight_calculate_cubemap_vector_weight(float normal[3], float *
copy_v3_fl3(normal, x * 2.0f - 1.0f, y * 2.0f - 1.0f, 1.0f);
const float conversion_matrices[6][3][3] = {
{
{0.0f, 0.0f, -1.0f},
{0.0f, 0.0f, 1.0f},
{0.0f, -1.0f, 0.0f},
{-1.0f, 0.0f, 0.0f},
{1.0f, 0.0f, 0.0f},
},
{
{0.0f, 0.0f, -1.0f},
{0.0f, -1.0f, 0.0f},
{-1.0f, 0.0f, 0.0f},
},
{
{1.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 1.0f},
{0.0f, -1.0f, 0.0f},
},
{
{1.0f, 0.0f, 0.0f},
{0.0f, 0.0f, -1.0f},
{0.0f, 1.0f, 0.0f},
},
{
{1.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 1.0f},
{0.0f, -1.0f, 0.0f},
},
{
{1.0f, 0.0f, 0.0f},
{0.0f, -1.0f, 0.0f},
@ -375,6 +381,7 @@ static void studiolight_calculate_cubemap_vector_weight(float normal[3], float *
{0.0f, 0.0f, 1.0f},
}
};
mul_m3_v3(conversion_matrices[face], normal);
normalize_v3(normal);
const float halfpix = 1.0f / (2.0f * STUDIOLIGHT_RADIANCE_CUBEMAP_SIZE);
@ -567,6 +574,7 @@ static void studiolight_calculate_specular_irradiance(StudioLight *sl, float col
static bool studiolight_load_irradiance_equirectangular_image(StudioLight *sl)
{
#ifdef STUDIOLIGHT_LOAD_CACHED_FILES
if (sl->flag & STUDIOLIGHT_EXTERNAL_FILE) {
ImBuf *ibuf = NULL;
ibuf = IMB_loadiffname(sl->path_irr_cache, 0, NULL);
@ -577,23 +585,26 @@ static bool studiolight_load_irradiance_equirectangular_image(StudioLight *sl)
return true;
}
}
#endif
return false;
}
static bool studiolight_load_spherical_harmonics_coefficients(StudioLight *sl)
{
#ifdef STUDIOLIGHT_LOAD_CACHED_FILES
if (sl->flag & STUDIOLIGHT_EXTERNAL_FILE) {
FILE *fp = BLI_fopen(sl->path_sh2_cache, "rb");
if (fp) {
if (fread((void*)(sl->spherical_harmonics_coefs), sizeof(sl->spherical_harmonics_coefs), 1, fp))
{
sl->flag |= STUDIOLIGHT_SPHERICAL_HARMONICS_COEFFICIENTS_CALCULATED;
fclose(fp);
fclose(fp);
return true;
}
fclose(fp);
}
}
#endif
return false;
}