Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/svm/sky.h
| Show First 20 Lines • Show All 112 Lines • ▼ Show 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(cosf(lat) * cosf(lon), cosf(lat) * sinf(lon), sinf(lat)); | return make_float3(cosf(lat) * cosf(lon), cosf(lat) * sinf(lon), sinf(lat)); | ||||
| } | } | ||||
| ccl_device float3 sky_radiance_nishita(KernelGlobals kg, | ccl_device float3 sky_radiance_nishita(KernelGlobals kg, | ||||
| float3 dir, | float3 dir, | ||||
| uint32_t path_flag, | |||||
| float3 pixel_bottom, | float3 pixel_bottom, | ||||
| float3 pixel_top, | float3 pixel_top, | ||||
| ccl_private float *nishita_data, | ccl_private float *nishita_data, | ||||
| uint texture_id) | uint texture_id) | ||||
| { | { | ||||
| /* definitions */ | /* definitions */ | ||||
| float sun_elevation = nishita_data[0]; | float sun_elevation = nishita_data[0]; | ||||
| float sun_rotation = nishita_data[1]; | float sun_rotation = nishita_data[1]; | ||||
| float angular_diameter = nishita_data[2]; | float angular_diameter = nishita_data[2]; | ||||
| float sun_intensity = nishita_data[3]; | float sun_intensity = nishita_data[3]; | ||||
| bool sun_disc = (angular_diameter >= 0.0f); | bool sun_disc = (angular_diameter >= 0.0f); | ||||
| float3 xyz; | float3 xyz; | ||||
| /* convert dir to spherical coordinates */ | /* convert dir to spherical coordinates */ | ||||
| float2 direction = direction_to_spherical(dir); | float2 direction = direction_to_spherical(dir); | ||||
| /* render above the horizon */ | /* render above the horizon */ | ||||
| if (dir.z >= 0.0f) { | if (dir.z >= 0.0f) { | ||||
| /* definitions */ | /* definitions */ | ||||
| float3 sun_dir = geographical_to_direction(sun_elevation, sun_rotation + M_PI_2_F); | float3 sun_dir = geographical_to_direction(sun_elevation, sun_rotation + M_PI_2_F); | ||||
| float sun_dir_angle = precise_angle(dir, sun_dir); | float sun_dir_angle = precise_angle(dir, sun_dir); | ||||
| float half_angular = angular_diameter / 2.0f; | float half_angular = angular_diameter / 2.0f; | ||||
| float dir_elevation = M_PI_2_F - direction.x; | float dir_elevation = M_PI_2_F - direction.x; | ||||
| /* if ray inside sun disc render it, otherwise render sky */ | /* if ray inside sun disc render it, otherwise render sky. | ||||
| if (sun_disc && sun_dir_angle < half_angular) { | * alternatively, ignore the sun if we're evaluating the background texture. */ | ||||
| if (sun_disc && sun_dir_angle < half_angular && !(path_flag & PATH_RAY_IMPORTANCE_BAKE)) { | |||||
| /* get 2 pixels data */ | /* get 2 pixels data */ | ||||
| float y; | float y; | ||||
| /* sun interpolation */ | /* sun interpolation */ | ||||
| if (sun_elevation - half_angular > 0.0f) { | if (sun_elevation - half_angular > 0.0f) { | ||||
| if (sun_elevation + half_angular > 0.0f) { | if (sun_elevation + half_angular > 0.0f) { | ||||
| y = ((dir_elevation - sun_elevation) / angular_diameter) + 0.5f; | y = ((dir_elevation - sun_elevation) / angular_diameter) + 0.5f; | ||||
| xyz = interp(pixel_bottom, pixel_top, y) * sun_intensity; | xyz = interp(pixel_bottom, pixel_top, y) * sun_intensity; | ||||
| Show All 40 Lines | else { | ||||
| } | } | ||||
| } | } | ||||
| /* convert to RGB */ | /* convert to RGB */ | ||||
| return xyz_to_rgb_clamped(kg, xyz); | return xyz_to_rgb_clamped(kg, xyz); | ||||
| } | } | ||||
| ccl_device_noinline int svm_node_tex_sky( | ccl_device_noinline int svm_node_tex_sky( | ||||
| KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, int offset) | KernelGlobals kg, ccl_private ShaderData *sd, uint32_t path_flag, 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 95 Lines • ▼ Show 20 Lines | else { | ||||
| nishita_data[1] = data.w; | nishita_data[1] = data.w; | ||||
| data = read_node_float(kg, &offset); | data = read_node_float(kg, &offset); | ||||
| nishita_data[2] = data.x; | nishita_data[2] = data.x; | ||||
| nishita_data[3] = data.y; | nishita_data[3] = 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, pixel_bottom, pixel_top, nishita_data, texture_id); | f = sky_radiance_nishita(kg, dir, path_flag, pixel_bottom, pixel_top, nishita_data, texture_id); | ||||
| } | } | ||||
| stack_store_float3(stack, out_offset, f); | stack_store_float3(stack, out_offset, f); | ||||
| return offset; | return offset; | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||