Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/svm/svm_ies.h
| Show All 13 Lines | |||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| /* IES Light */ | /* IES Light */ | ||||
| ccl_device_inline float interpolate_ies_vertical( | ccl_device_inline float interpolate_ies_vertical( | ||||
| KernelGlobals *kg, int ofs, int v, int v_num, float v_frac, int h) | const KernelGlobals *kg, int ofs, int v, int v_num, float v_frac, int h) | ||||
| { | { | ||||
| /* Since lookups are performed in spherical coordinates, clamping the coordinates at the low end | /* Since lookups are performed in spherical coordinates, clamping the coordinates at the low end | ||||
| * of v (corresponding to the north pole) would result in artifacts. The proper way of dealing | * of v (corresponding to the north pole) would result in artifacts. The proper way of dealing | ||||
| * with this would be to lookup the corresponding value on the other side of the pole, but since | * with this would be to lookup the corresponding value on the other side of the pole, but since | ||||
| * the horizontal coordinates might be nonuniform, this would require yet another interpolation. | * the horizontal coordinates might be nonuniform, this would require yet another interpolation. | ||||
| * Therefore, the assumption is made that the light is going to be symmetrical, which means that | * Therefore, the assumption is made that the light is going to be symmetrical, which means that | ||||
| * we can just take the corresponding value at the current horizontal coordinate. */ | * we can just take the corresponding value at the current horizontal coordinate. */ | ||||
| #define IES_LOOKUP(v) kernel_tex_fetch(__ies, ofs + h * v_num + (v)) | #define IES_LOOKUP(v) kernel_tex_fetch(__ies, ofs + h * v_num + (v)) | ||||
| /* If v is zero, assume symmetry and read at v=1 instead of v=-1. */ | /* If v is zero, assume symmetry and read at v=1 instead of v=-1. */ | ||||
| float a = IES_LOOKUP((v == 0) ? 1 : v - 1); | float a = IES_LOOKUP((v == 0) ? 1 : v - 1); | ||||
| float b = IES_LOOKUP(v); | float b = IES_LOOKUP(v); | ||||
| float c = IES_LOOKUP(v + 1); | float c = IES_LOOKUP(v + 1); | ||||
| float d = IES_LOOKUP(min(v + 2, v_num - 1)); | float d = IES_LOOKUP(min(v + 2, v_num - 1)); | ||||
| #undef IES_LOOKUP | #undef IES_LOOKUP | ||||
| return cubic_interp(a, b, c, d, v_frac); | return cubic_interp(a, b, c, d, v_frac); | ||||
| } | } | ||||
| ccl_device_inline float kernel_ies_interp(KernelGlobals *kg, | ccl_device_inline float kernel_ies_interp(const KernelGlobals *kg, | ||||
| int slot, | int slot, | ||||
| float h_angle, | float h_angle, | ||||
| float v_angle) | float v_angle) | ||||
| { | { | ||||
| /* Find offset of the IES data in the table. */ | /* Find offset of the IES data in the table. */ | ||||
| int ofs = __float_as_int(kernel_tex_fetch(__ies, slot)); | int ofs = __float_as_int(kernel_tex_fetch(__ies, slot)); | ||||
| if (ofs == -1) { | if (ofs == -1) { | ||||
| return 100.0f; | return 100.0f; | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | #undef IES_LOOKUP_ANGLE_V | ||||
| /* Same logic here, wrap around to the second element if necessary. */ | /* Same logic here, wrap around to the second element if necessary. */ | ||||
| float d = interpolate_ies_vertical( | float d = interpolate_ies_vertical( | ||||
| kg, ofs, v_i, v_num, v_frac, (h_i + 2 == h_num) ? 1 : h_i + 2); | kg, ofs, v_i, v_num, v_frac, (h_i + 2 == h_num) ? 1 : h_i + 2); | ||||
| /* Cubic interpolation can result in negative values, so get rid of them. */ | /* Cubic interpolation can result in negative values, so get rid of them. */ | ||||
| return max(cubic_interp(a, b, c, d, h_frac), 0.0f); | return max(cubic_interp(a, b, c, d, h_frac), 0.0f); | ||||
| } | } | ||||
| ccl_device void svm_node_ies( | ccl_device_noinline void svm_node_ies(const KernelGlobals *kg, | ||||
| KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) | ShaderData *sd, | ||||
| float *stack, | |||||
| uint4 node) | |||||
| { | { | ||||
| uint vector_offset, strength_offset, fac_offset, slot = node.z; | uint vector_offset, strength_offset, fac_offset, slot = node.z; | ||||
| svm_unpack_node_uchar3(node.y, &strength_offset, &vector_offset, &fac_offset); | svm_unpack_node_uchar3(node.y, &strength_offset, &vector_offset, &fac_offset); | ||||
| float3 vector = stack_load_float3(stack, vector_offset); | float3 vector = stack_load_float3(stack, vector_offset); | ||||
| float strength = stack_load_float_default(stack, strength_offset, node.w); | float strength = stack_load_float_default(stack, strength_offset, node.w); | ||||
| vector = normalize(vector); | vector = normalize(vector); | ||||
| Show All 11 Lines | |||||