Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/svm/svm_sky.h
| Show All 31 Lines | |||||
| { | { | ||||
| 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(KernelGlobals *kg, | ccl_device float3 sky_radiance_preetham(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, | float *config_x, | ||||
| float *config_y, | float *config_y, | ||||
| Show All 36 Lines | float mieM = (1.0f + rayM) / powf((1.0f + configuration[8] * configuration[8] - | ||||
| 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(KernelGlobals *kg, | ccl_device float3 sky_radiance_hosek(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, | float *config_x, | ||||
| float *config_y, | float *config_y, | ||||
| Show All 20 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(KernelGlobals *kg, | ccl_device float3 sky_radiance_nishita(const KernelGlobals *kg, | ||||
| float3 dir, | float3 dir, | ||||
| float *nishita_data, | 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]; | ||||
| ▲ Show 20 Lines • Show All 65 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 void svm_node_tex_sky( | ccl_device_noinline int svm_node_tex_sky( | ||||
| KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) | const KernelGlobals *kg, ShaderData *sd, 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; | ||||
| /* Preetham and Hosek share the same data */ | /* Preetham and Hosek share the same data */ | ||||
| if (sky_model == 0 || sky_model == 1) { | if (sky_model == 0 || sky_model == 1) { | ||||
| /* Define variables */ | /* Define variables */ | ||||
| float sunphi, suntheta, radiance_x, radiance_y, radiance_z; | float sunphi, suntheta, radiance_x, radiance_y, radiance_z; | ||||
| float config_x[9], config_y[9], config_z[9]; | float config_x[9], config_y[9], config_z[9]; | ||||
| float4 data = read_node_float(kg, offset); | float4 data = read_node_float(kg, &offset); | ||||
| sunphi = data.x; | sunphi = data.x; | ||||
| suntheta = data.y; | suntheta = data.y; | ||||
| radiance_x = data.z; | radiance_x = data.z; | ||||
| radiance_y = data.w; | radiance_y = data.w; | ||||
| data = read_node_float(kg, offset); | data = read_node_float(kg, &offset); | ||||
| radiance_z = data.x; | radiance_z = data.x; | ||||
| config_x[0] = data.y; | config_x[0] = data.y; | ||||
| config_x[1] = data.z; | config_x[1] = data.z; | ||||
| config_x[2] = data.w; | config_x[2] = data.w; | ||||
| data = read_node_float(kg, offset); | data = read_node_float(kg, &offset); | ||||
| config_x[3] = data.x; | config_x[3] = data.x; | ||||
| config_x[4] = data.y; | config_x[4] = data.y; | ||||
| config_x[5] = data.z; | config_x[5] = data.z; | ||||
| config_x[6] = data.w; | config_x[6] = data.w; | ||||
| data = read_node_float(kg, offset); | data = read_node_float(kg, &offset); | ||||
| config_x[7] = data.x; | config_x[7] = data.x; | ||||
| config_x[8] = data.y; | config_x[8] = data.y; | ||||
| config_y[0] = data.z; | config_y[0] = data.z; | ||||
| config_y[1] = data.w; | config_y[1] = data.w; | ||||
| data = read_node_float(kg, offset); | data = read_node_float(kg, &offset); | ||||
| config_y[2] = data.x; | config_y[2] = data.x; | ||||
| config_y[3] = data.y; | config_y[3] = data.y; | ||||
| config_y[4] = data.z; | config_y[4] = data.z; | ||||
| config_y[5] = data.w; | config_y[5] = data.w; | ||||
| data = read_node_float(kg, offset); | data = read_node_float(kg, &offset); | ||||
| config_y[6] = data.x; | config_y[6] = data.x; | ||||
| config_y[7] = data.y; | config_y[7] = data.y; | ||||
| config_y[8] = data.z; | config_y[8] = data.z; | ||||
| config_z[0] = data.w; | config_z[0] = data.w; | ||||
| data = read_node_float(kg, offset); | data = read_node_float(kg, &offset); | ||||
| config_z[1] = data.x; | config_z[1] = data.x; | ||||
| config_z[2] = data.y; | config_z[2] = data.y; | ||||
| config_z[3] = data.z; | config_z[3] = data.z; | ||||
| config_z[4] = data.w; | config_z[4] = data.w; | ||||
| data = read_node_float(kg, offset); | data = read_node_float(kg, &offset); | ||||
| config_z[5] = data.x; | config_z[5] = data.x; | ||||
| config_z[6] = data.y; | config_z[6] = data.y; | ||||
| config_z[7] = data.z; | config_z[7] = data.z; | ||||
| config_z[8] = data.w; | config_z[8] = data.w; | ||||
| /* Compute Sky */ | /* Compute Sky */ | ||||
| if (sky_model == 0) { | if (sky_model == 0) { | ||||
| f = sky_radiance_preetham(kg, | f = sky_radiance_preetham(kg, | ||||
| Show All 20 Lines | else { | ||||
| config_z); | config_z); | ||||
| } | } | ||||
| } | } | ||||
| /* Nishita */ | /* Nishita */ | ||||
| else { | else { | ||||
| /* Define variables */ | /* Define variables */ | ||||
| float nishita_data[10]; | float nishita_data[10]; | ||||
| float4 data = read_node_float(kg, offset); | float4 data = read_node_float(kg, &offset); | ||||
| nishita_data[0] = data.x; | nishita_data[0] = data.x; | ||||
| nishita_data[1] = data.y; | nishita_data[1] = data.y; | ||||
| nishita_data[2] = data.z; | nishita_data[2] = data.z; | ||||
| nishita_data[3] = data.w; | nishita_data[3] = data.w; | ||||
| data = read_node_float(kg, offset); | data = read_node_float(kg, &offset); | ||||
| nishita_data[4] = data.x; | nishita_data[4] = data.x; | ||||
| nishita_data[5] = data.y; | nishita_data[5] = data.y; | ||||
| nishita_data[6] = data.z; | nishita_data[6] = data.z; | ||||
| nishita_data[7] = data.w; | nishita_data[7] = data.w; | ||||
| data = read_node_float(kg, offset); | data = read_node_float(kg, &offset); | ||||
| nishita_data[8] = data.x; | nishita_data[8] = data.x; | ||||
| nishita_data[9] = data.y; | nishita_data[9] = data.y; | ||||
| uint texture_id = __float_as_uint(data.z); | uint texture_id = __float_as_uint(data.z); | ||||
| /* Compute Sky */ | /* Compute Sky */ | ||||
| f = sky_radiance_nishita(kg, dir, nishita_data, texture_id); | f = sky_radiance_nishita(kg, dir, nishita_data, texture_id); | ||||
| } | } | ||||
| stack_store_float3(stack, out_offset, f); | stack_store_float3(stack, out_offset, f); | ||||
| return offset; | |||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||