Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/svm/svm_sky.h
| Show First 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | ccl_device float3 sky_radiance_nishita(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]; | ||||
| float sun_intensity = nishita_data[9]; | |||||
| 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) { | if (sun_disc && sun_dir_angle < half_angular) { | ||||
| /* get 3 pixels data */ | /* get 2 pixels data */ | ||||
| float3 pixel_bottom = make_float3(nishita_data[0], nishita_data[1], nishita_data[2]); | float3 pixel_bottom = make_float3(nishita_data[0], nishita_data[1], nishita_data[2]); | ||||
| float3 pixel_top = make_float3(nishita_data[3], nishita_data[4], nishita_data[5]); | float3 pixel_top = make_float3(nishita_data[3], nishita_data[4], nishita_data[5]); | ||||
| 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); | xyz = interp(pixel_bottom, pixel_top, y) * sun_intensity; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (sun_elevation + half_angular > 0.0f) { | if (sun_elevation + half_angular > 0.0f) { | ||||
| y = dir_elevation / (sun_elevation + half_angular); | y = dir_elevation / (sun_elevation + half_angular); | ||||
| xyz = interp(pixel_bottom, pixel_top, y); | xyz = interp(pixel_bottom, pixel_top, y) * sun_intensity; | ||||
| } | } | ||||
| } | } | ||||
| /* limb darkening, coefficient is 0.6f */ | /* limb darkening, coefficient is 0.6f */ | ||||
| float limb_darkening = (1.0f - | float limb_darkening = (1.0f - | ||||
| 0.6f * (1.0f - sqrtf(1.0f - sqr(sun_dir_angle / half_angular)))); | 0.6f * (1.0f - sqrtf(1.0f - sqr(sun_dir_angle / half_angular)))); | ||||
| xyz *= limb_darkening; | xyz *= limb_darkening; | ||||
| } | } | ||||
| /* sky */ | /* sky */ | ||||
| else { | else { | ||||
| /* sky interpolation */ | /* sky interpolation */ | ||||
| float x = (direction.y + M_PI_F + sun_rotation) / M_2PI_F; | float x = (direction.y + M_PI_F + sun_rotation) / M_2PI_F; | ||||
| float y = dir_elevation / M_PI_2_F; | /* more pixels toward horizon compensation */ | ||||
| float y = safe_sqrtf(dir_elevation / M_PI_2_F); | |||||
lukasstockner97: Same here (safe_sqrtf outside of OSL). | |||||
| if (x > 1.0f) { | if (x > 1.0f) { | ||||
| x -= 1.0f; | x -= 1.0f; | ||||
| } | } | ||||
| xyz = float4_to_float3(kernel_tex_image_interp(kg, texture_id, x, y)); | xyz = float4_to_float3(kernel_tex_image_interp(kg, texture_id, x, y)); | ||||
| } | } | ||||
| } | } | ||||
| /* ground */ | /* ground */ | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | else { | ||||
| config_x, | config_x, | ||||
| config_y, | config_y, | ||||
| config_z); | config_z); | ||||
| } | } | ||||
| } | } | ||||
| /* Nishita */ | /* Nishita */ | ||||
| else { | else { | ||||
| /* Define variables */ | /* Define variables */ | ||||
| float nishita_data[9]; | 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; | ||||
| uint texture_id = __float_as_uint(data.y); | nishita_data[9] = data.y; | ||||
| 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); | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
Same here (safe_sqrtf outside of OSL).