Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/svm/svm_sky.h
| Show All 22 Lines | ccl_device float sky_angle_between(float thetav, float phiv, float theta, float phi) | ||||
| float cospsi = sinf(thetav) * sinf(theta) * cosf(phi - phiv) + cosf(thetav) * cosf(theta); | float cospsi = sinf(thetav) * sinf(theta) * cosf(phi - phiv) + cosf(thetav) * cosf(theta); | ||||
| return safe_acosf(cospsi); | return safe_acosf(cospsi); | ||||
| } | } | ||||
| /* | /* | ||||
| * "A Practical Analytic Model for Daylight" | * "A Practical Analytic Model for Daylight" | ||||
| * A. J. Preetham, Peter Shirley, Brian Smits | * A. J. Preetham, Peter Shirley, Brian Smits | ||||
| */ | */ | ||||
| ccl_device float sky_perez_function(float *lam, float theta, float gamma) | ccl_device float sky_perez_function(ccl_private float *lam, float theta, float gamma) | ||||
| { | { | ||||
| float ctheta = cosf(theta); | float ctheta = cosf(theta); | ||||
| float cgamma = cosf(gamma); | float cgamma = cosf(gamma); | ||||
| return (1.0f + lam[0] * expf(lam[1] / ctheta)) * | return (1.0f + lam[0] * expf(lam[1] / ctheta)) * | ||||
| (1.0f + lam[2] * expf(lam[3] * gamma) + lam[4] * cgamma * cgamma); | (1.0f + lam[2] * expf(lam[3] * gamma) + lam[4] * cgamma * cgamma); | ||||
| } | } | ||||
| ccl_device float3 sky_radiance_preetham(const KernelGlobals *kg, | ccl_device float3 sky_radiance_preetham(ccl_global const KernelGlobals *kg, | ||||
| float3 dir, | float3 dir, | ||||
| float sunphi, | float sunphi, | ||||
| float suntheta, | float suntheta, | ||||
| float radiance_x, | float radiance_x, | ||||
| float radiance_y, | float radiance_y, | ||||
| float radiance_z, | float radiance_z, | ||||
| float *config_x, | ccl_private float *config_x, | ||||
| float *config_y, | ccl_private float *config_y, | ||||
| float *config_z) | ccl_private float *config_z) | ||||
| { | { | ||||
| /* convert vector to spherical coordinates */ | /* convert vector to spherical coordinates */ | ||||
| float2 spherical = direction_to_spherical(dir); | float2 spherical = direction_to_spherical(dir); | ||||
| float theta = spherical.x; | float theta = spherical.x; | ||||
| float phi = spherical.y; | float phi = spherical.y; | ||||
| /* angle between sun direction and dir */ | /* angle between sun direction and dir */ | ||||
| float gamma = sky_angle_between(theta, phi, suntheta, sunphi); | float gamma = sky_angle_between(theta, phi, suntheta, sunphi); | ||||
| Show All 10 Lines | ccl_device float3 sky_radiance_preetham(ccl_global const KernelGlobals *kg, | ||||
| float3 xyz = xyY_to_xyz(x, y, Y); | float3 xyz = xyY_to_xyz(x, y, Y); | ||||
| return xyz_to_rgb(kg, xyz); | return xyz_to_rgb(kg, xyz); | ||||
| } | } | ||||
| /* | /* | ||||
| * "An Analytic Model for Full Spectral Sky-Dome Radiance" | * "An Analytic Model for Full Spectral Sky-Dome Radiance" | ||||
| * Lukas Hosek, Alexander Wilkie | * Lukas Hosek, Alexander Wilkie | ||||
| */ | */ | ||||
| ccl_device float sky_radiance_internal(float *configuration, float theta, float gamma) | ccl_device float sky_radiance_internal(ccl_private float *configuration, float theta, float gamma) | ||||
| { | { | ||||
| float ctheta = cosf(theta); | float ctheta = cosf(theta); | ||||
| float cgamma = cosf(gamma); | float cgamma = cosf(gamma); | ||||
| float expM = expf(configuration[4] * gamma); | float expM = expf(configuration[4] * gamma); | ||||
| float rayM = cgamma * cgamma; | float rayM = cgamma * cgamma; | ||||
| float mieM = (1.0f + rayM) / powf((1.0f + configuration[8] * configuration[8] - | float mieM = (1.0f + rayM) / powf((1.0f + configuration[8] * configuration[8] - | ||||
| 2.0f * configuration[8] * cgamma), | 2.0f * configuration[8] * cgamma), | ||||
| 1.5f); | 1.5f); | ||||
| float zenith = sqrtf(ctheta); | float zenith = sqrtf(ctheta); | ||||
| return (1.0f + configuration[0] * expf(configuration[1] / (ctheta + 0.01f))) * | return (1.0f + configuration[0] * expf(configuration[1] / (ctheta + 0.01f))) * | ||||
| (configuration[2] + configuration[3] * expM + configuration[5] * rayM + | (configuration[2] + configuration[3] * expM + configuration[5] * rayM + | ||||
| configuration[6] * mieM + configuration[7] * zenith); | configuration[6] * mieM + configuration[7] * zenith); | ||||
| } | } | ||||
| ccl_device float3 sky_radiance_hosek(const KernelGlobals *kg, | ccl_device float3 sky_radiance_hosek(ccl_global const KernelGlobals *kg, | ||||
| float3 dir, | float3 dir, | ||||
| float sunphi, | float sunphi, | ||||
| float suntheta, | float suntheta, | ||||
| float radiance_x, | float radiance_x, | ||||
| float radiance_y, | float radiance_y, | ||||
| float radiance_z, | float radiance_z, | ||||
| float *config_x, | ccl_private float *config_x, | ||||
| float *config_y, | ccl_private float *config_y, | ||||
| float *config_z) | ccl_private float *config_z) | ||||
| { | { | ||||
| /* convert vector to spherical coordinates */ | /* convert vector to spherical coordinates */ | ||||
| float2 spherical = direction_to_spherical(dir); | float2 spherical = direction_to_spherical(dir); | ||||
| float theta = spherical.x; | float theta = spherical.x; | ||||
| float phi = spherical.y; | float phi = spherical.y; | ||||
| /* angle between sun direction and dir */ | /* angle between sun direction and dir */ | ||||
| float gamma = sky_angle_between(theta, phi, suntheta, sunphi); | float gamma = sky_angle_between(theta, phi, suntheta, sunphi); | ||||
| Show All 11 Lines | |||||
| } | } | ||||
| /* Nishita improved sky model */ | /* Nishita improved sky model */ | ||||
| ccl_device float3 geographical_to_direction(float lat, float lon) | ccl_device float3 geographical_to_direction(float lat, float lon) | ||||
| { | { | ||||
| return make_float3(cos(lat) * cos(lon), cos(lat) * sin(lon), sin(lat)); | return make_float3(cos(lat) * cos(lon), cos(lat) * sin(lon), sin(lat)); | ||||
| } | } | ||||
| ccl_device float3 sky_radiance_nishita(const KernelGlobals *kg, | ccl_device float3 sky_radiance_nishita(ccl_global const KernelGlobals *kg, | ||||
| float3 dir, | float3 dir, | ||||
| float *nishita_data, | ccl_private float *nishita_data, | ||||
| uint texture_id) | uint texture_id) | ||||
| { | { | ||||
| /* definitions */ | /* definitions */ | ||||
| float sun_elevation = nishita_data[6]; | float sun_elevation = nishita_data[6]; | ||||
| float sun_rotation = nishita_data[7]; | float sun_rotation = nishita_data[7]; | ||||
| float angular_diameter = nishita_data[8]; | float angular_diameter = nishita_data[8]; | ||||
| float sun_intensity = nishita_data[9]; | float sun_intensity = nishita_data[9]; | ||||
| bool sun_disc = (angular_diameter >= 0.0f); | bool sun_disc = (angular_diameter >= 0.0f); | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | else { | ||||
| xyz = float4_to_float3(kernel_tex_image_interp(kg, texture_id, x, -0.5)) * fade; | xyz = float4_to_float3(kernel_tex_image_interp(kg, texture_id, x, -0.5)) * fade; | ||||
| } | } | ||||
| } | } | ||||
| /* convert to RGB */ | /* convert to RGB */ | ||||
| return xyz_to_rgb(kg, xyz); | return xyz_to_rgb(kg, xyz); | ||||
| } | } | ||||
| ccl_device_noinline int svm_node_tex_sky( | ccl_device_noinline int svm_node_tex_sky(ccl_global const KernelGlobals *kg, | ||||
| const KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int offset) | ccl_private ShaderData *sd, | ||||
| ccl_private float *stack, | |||||
| uint4 node, | |||||
| int offset) | |||||
| { | { | ||||
| /* Load data */ | /* Load data */ | ||||
| uint dir_offset = node.y; | uint dir_offset = node.y; | ||||
| uint out_offset = node.z; | uint out_offset = node.z; | ||||
| int sky_model = node.w; | int sky_model = node.w; | ||||
| float3 dir = stack_load_float3(stack, dir_offset); | float3 dir = stack_load_float3(stack, dir_offset); | ||||
| float3 f; | float3 f; | ||||
| ▲ Show 20 Lines • Show All 112 Lines • Show Last 20 Lines | |||||