Revert "Cycles: Remove the Preetham Sky model."

This reverts commit d91316dc67.
This commit is contained in:
Thomas Dinges
2016-04-05 12:25:54 +02:00
parent 46aaa53998
commit b8ca4819b2
11 changed files with 235 additions and 24 deletions

View File

@@ -24,6 +24,44 @@ ccl_device float sky_angle_between(float thetav, float phiv, float theta, float
return safe_acosf(cospsi);
}
/*
* "A Practical Analytic Model for Daylight"
* A. J. Preetham, Peter Shirley, Brian Smits
*/
ccl_device float sky_perez_function(float *lam, float theta, float gamma)
{
float ctheta = cosf(theta);
float cgamma = cosf(gamma);
return (1.0f + lam[0]*expf(lam[1]/ctheta)) * (1.0f + lam[2]*expf(lam[3]*gamma) + lam[4]*cgamma*cgamma);
}
ccl_device float3 sky_radiance_old(KernelGlobals *kg, float3 dir,
float sunphi, float suntheta,
float radiance_x, float radiance_y, float radiance_z,
float *config_x, float *config_y, float *config_z)
{
/* convert vector to spherical coordinates */
float2 spherical = direction_to_spherical(dir);
float theta = spherical.x;
float phi = spherical.y;
/* angle between sun direction and dir */
float gamma = sky_angle_between(theta, phi, suntheta, sunphi);
/* clamp theta to horizon */
theta = min(theta, M_PI_2_F - 0.001f);
/* compute xyY color space values */
float x = radiance_y * sky_perez_function(config_y, theta, gamma);
float y = radiance_z * sky_perez_function(config_z, theta, gamma);
float Y = radiance_x * sky_perez_function(config_x, theta, gamma);
/* convert to RGB */
float3 xyz = xyY_to_xyz(x, y, Y);
return xyz_to_rgb(xyz.x, xyz.y, xyz.z);
}
/*
* "An Analytic Model for Full Spectral Sky-Dome Radiance"
* Lukas Hosek, Alexander Wilkie
@@ -42,10 +80,10 @@ ccl_device float sky_radiance_internal(float *configuration, float theta, float
(configuration[2] + configuration[3] * expM + configuration[5] * rayM + configuration[6] * mieM + configuration[7] * zenith);
}
ccl_device float3 sky_radiance(KernelGlobals *kg, float3 dir,
float sunphi, float suntheta,
float radiance_x, float radiance_y, float radiance_z,
float *config_x, float *config_y, float *config_z)
ccl_device float3 sky_radiance_new(KernelGlobals *kg, float3 dir,
float sunphi, float suntheta,
float radiance_x, float radiance_y, float radiance_z,
float *config_x, float *config_y, float *config_z)
{
/* convert vector to spherical coordinates */
float2 spherical = direction_to_spherical(dir);
@@ -76,6 +114,7 @@ ccl_device void svm_node_tex_sky(KernelGlobals *kg, ShaderData *sd, float *stack
/* Load data */
uint dir_offset = node.y;
uint out_offset = node.z;
int sky_model = node.w;
float4 data = read_node_float(kg, offset);
sunphi = data.x;
@@ -129,9 +168,16 @@ ccl_device void svm_node_tex_sky(KernelGlobals *kg, ShaderData *sd, float *stack
float3 f;
/* Compute Sky */
f = sky_radiance(kg, dir, sunphi, suntheta,
radiance_x, radiance_y, radiance_z,
config_x, config_y, config_z);
if(sky_model == 0) {
f = sky_radiance_old(kg, dir, sunphi, suntheta,
radiance_x, radiance_y, radiance_z,
config_x, config_y, config_z);
}
else {
f = sky_radiance_new(kg, dir, sunphi, suntheta,
radiance_x, radiance_y, radiance_z,
config_x, config_y, config_z);
}
stack_store_float3(stack, out_offset, f);
}

View File

@@ -299,6 +299,11 @@ typedef enum NodeWaveProfiles {
NODE_WAVE_PROFILE_SAW,
} NodeWaveProfile;
typedef enum NodeSkyType {
NODE_SKY_OLD,
NODE_SKY_NEW
} NodeSkyType;
typedef enum NodeGradientType {
NODE_BLEND_LINEAR,
NODE_BLEND_QUADRATIC,