From 8b955e9b19dd8616f61c27d5e9d2d80d66dacd96 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Sat, 17 Aug 2013 16:08:03 +0000 Subject: Cycles / Sky Model: * Replaced the Preetham model with the newer Hosek / Wilkie model: "An Analytic Model for Full Spectral Sky-Dome Radiance" http://cgg.mff.cuni.cz/projects/SkylightModelling/ * We use the sample code data, which comes with the paper, but removed some unnecessary parts, we only need the xyz version. * New "Albedo" UI paraemeter, to control the ground albedo (between 0 and 1). * Works with SVM only atm (CPU and CUDA). Example render: http://www.pasteall.org/pic/show.php?id=57635 ToDo / Open Questions: * OSL still uses the old model, will be done later. In the meantime it's useful to compare the two models this way. * The new model needs a much weaker Strength value (0.01), otherwise it's white. Can this be fixed? * Code cleanup. --- intern/cycles/kernel/kernel_types.h | 7 +++---- intern/cycles/kernel/svm/svm_sky.h | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'intern/cycles/kernel') diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index 836eacf7cb6..69a3a4fe28c 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -718,12 +718,11 @@ typedef struct KernelBackground { typedef struct KernelSunSky { /* sun direction in spherical and cartesian */ - float theta, phi, pad3, pad4; + float theta, phi; /* perez function parameters */ - float zenith_Y, zenith_x, zenith_y, pad2; - float perez_Y[5], perez_x[5], perez_y[5]; - float pad5; + float radiance_x, radiance_y, radiance_z; + float config_x[9], config_y[9], config_z[9]; } KernelSunSky; typedef struct KernelIntegrator { diff --git a/intern/cycles/kernel/svm/svm_sky.h b/intern/cycles/kernel/svm/svm_sky.h index 8b4e35816d0..d81f6ece46c 100644 --- a/intern/cycles/kernel/svm/svm_sky.h +++ b/intern/cycles/kernel/svm/svm_sky.h @@ -19,8 +19,8 @@ CCL_NAMESPACE_BEGIN /* - * "A Practical Analytic Model for Daylight" - * A. J. Preetham, Peter Shirley, Brian Smits + * "An Analytic Model for Full Spectral Sky-Dome Radiance" + * Lukas Hosek, Alexander Wilkie */ __device float sky_angle_between(float thetav, float phiv, float theta, float phi) @@ -29,12 +29,16 @@ __device float sky_angle_between(float thetav, float phiv, float theta, float ph return safe_acosf(cospsi); } -__device float sky_perez_function(__constant float *lam, float theta, float gamma) +/* ArHosekSkyModel_GetRadianceInternal */ +__device float sky_radiance_internal(__constant float *configuration, float theta, float gamma) { - float ctheta = cosf(theta); - float cgamma = cosf(gamma); + const float expM = expf(configuration[4] * gamma); + const float rayM = cosf(gamma)*cosf(gamma); + const float mieM = (1.0f + cosf(gamma)*cosf(gamma)) / powf((1.0f + configuration[8]*configuration[8] - 2.0f*configuration[8]*cosf(gamma)), 1.5f); + const float zenith = sqrt(cosf(theta)); - return (1.0f + lam[0]*expf(lam[1]/ctheta)) * (1.0f + lam[2]*expf(lam[3]*gamma) + lam[4]*cgamma*cgamma); + return (1.0f + configuration[0] * expf(configuration[1] / (cosf(theta) + 0.01f))) * + (configuration[2] + configuration[3] * expM + configuration[5] * rayM + configuration[6] * mieM + configuration[7] * zenith); } __device float3 sky_radiance(KernelGlobals *kg, float3 dir) @@ -50,14 +54,13 @@ __device float3 sky_radiance(KernelGlobals *kg, float3 dir) /* clamp theta to horizon */ theta = min(theta, M_PI_2_F - 0.001f); - /* compute xyY color space values */ - float x = kernel_data.sunsky.zenith_x * sky_perez_function(kernel_data.sunsky.perez_x, theta, gamma); - float y = kernel_data.sunsky.zenith_y * sky_perez_function(kernel_data.sunsky.perez_y, theta, gamma); - float Y = kernel_data.sunsky.zenith_Y * sky_perez_function(kernel_data.sunsky.perez_Y, theta, gamma); + /* compute xyz color space values */ + float x = sky_radiance_internal(kernel_data.sunsky.config_x, theta, gamma) * kernel_data.sunsky.radiance_x; + float y = sky_radiance_internal(kernel_data.sunsky.config_y, theta, gamma) * kernel_data.sunsky.radiance_y; + float z = sky_radiance_internal(kernel_data.sunsky.config_z, theta, gamma) * kernel_data.sunsky.radiance_z; /* convert to RGB */ - float3 xyz = xyY_to_xyz(x, y, Y); - return xyz_to_rgb(xyz.x, xyz.y, xyz.z); + return xyz_to_rgb(x, y, z); } __device void svm_node_tex_sky(KernelGlobals *kg, ShaderData *sd, float *stack, uint dir_offset, uint out_offset) -- cgit v1.2.3