13#if defined(WITH_FFTW3)
45#define MAX_GLARE_ITERATIONS 5
57 {0,
nullptr, 0,
nullptr,
nullptr},
64 {0,
nullptr, 0,
nullptr,
nullptr},
77 N_(
"The kernel is a float and will be convolved with all input channels")},
82 N_(
"The kernel is a color and each channel of the kernel will be convolved with each "
83 "respective channel in the input")},
84 {0,
nullptr, 0,
nullptr,
nullptr},
89 b.use_custom_socket_order();
90 b.allow_any_socket_order();
93 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
97 .structure_type(StructureType::Dynamic)
98 .
description(
"The image with the generated glare added")
99 .align_with_previous();
102 .structure_type(StructureType::Dynamic)
105 .structure_type(StructureType::Dynamic)
106 .
description(
"The extracted highlights from which the glare was generated");
122 "The brightness level at which pixels are considered part of the highlights that "
129 .description(
"The smoothness of the extracted highlights");
134 .default_value(
false)
138 .default_value(10.0f)
141 "Clamp bright highlights such that their brightness are not larger than this value");
149 .description(
"Adjusts the brightness of the glare");
155 .description(
"Adjusts the saturation of the glare");
157 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
158 .description(
"Tints the glare. Consider desaturating the glare to more accurate tinting");
166 .usage_by_menu(
"Type"_ustr,
169 "The size of the glare relative to the image. 1 means the glare covers the entire "
170 "image, 0.5 means the glare covers half the image, and so on");
181 .description(
"The angle that the first streak makes with the horizontal axis");
186 .usage_by_menu(
"Type"_ustr,
189 "The number of ghosts for Ghost glare or the quality and spread of Glare for Streaks "
197 .description(
"Streak fade-out factor");
204 .description(
"Modulates colors of streaks and ghosts for a spectral dispersion effect");
212 .default_value({0.5f, 0.5f})
217 "The position of the source of the rays in normalized coordinates. 0 means lower left "
218 "corner and 1 means upper right corner");
226 "The amount of jitter to introduce while computing rays, higher jitter can be faster "
227 "but can produce grainy or noisy results");
248 NodeGlare *ndg = MEM_new<NodeGlare>(__func__);
257 ntree->ensure_topology_cache();
258 const bNodeSocket *type_input =
node->input_by_identifier(
"Type"_ustr);
260 if (type_input->is_logically_linked()) {
268 if (item->value == type_value) {
354 if (this->
context().use_gpu()) {
385 return highlights_result;
398 output.allocate_texture(highlights_size);
404 float4 color = float4(0.0f);
407 case CMP_NODE_GLARE_QUALITY_HIGH: {
408 color = float4(input.load_pixel<Color>(texel));
415 case CMP_NODE_GLARE_QUALITY_MEDIUM: {
416 float2 normalized_coordinates = (float2(texel) * 2.0f + float2(1.0f)) /
418 color = float4(input.sample_bilinear_extended<Color>(normalized_coordinates));
426 case CMP_NODE_GLARE_QUALITY_LOW: {
428 float2 lower_left_coordinates = (float2(texel) * 4.0f + float2(1.0f)) /
430 float4 lower_left_color = float4(
431 input.sample_bilinear_extended<Color>(lower_left_coordinates));
433 float2 lower_right_coordinates = (float2(texel) * 4.0f + float2(3.0f, 1.0f)) /
435 float4 lower_right_color = float4(
436 input.sample_bilinear_extended<Color>(lower_right_coordinates));
438 float2 upper_left_coordinates = (float2(texel) * 4.0f + float2(1.0f, 3.0f)) /
440 float4 upper_left_color = float4(
441 input.sample_bilinear_extended<Color>(upper_left_coordinates));
443 float2 upper_right_coordinates = (float2(texel) * 4.0f + float2(3.0f)) /
445 float4 upper_right_color = float4(
446 input.sample_bilinear_extended<Color>(upper_right_coordinates));
448 color = (upper_left_color + upper_right_color + lower_left_color + lower_right_color) /
467 hsva.z, threshold, max_brightness, highlights_smoothness);
470 hsva.z = clamped_brightness - threshold;
485 return std::numeric_limits<float>::max();
501 float smooth_min(
const float a,
const float b,
const float smoothness)
503 if (smoothness == 0.0f) {
507 return math::min(a,
b) - h * h * smoothness * (1.0f / 4.0f);
510 float smooth_max(
const float a,
const float b,
const float smoothness)
518 const float min_value,
519 const float max_value,
520 const float min_smoothness,
521 const float max_smoothness)
524 max_value, this->
smooth_max(min_value,
x, min_smoothness), max_smoothness);
540 const float min_value,
541 const float max_value,
542 const float smoothness)
544 const float range_distance =
math::distance(min_value, max_value);
545 const float distance_from_min_to_zero =
math::distance(min_value, 0.0f);
546 const float distance_from_max_to_zero =
math::distance(max_value, 0.0f);
548 const float max_safe_smoothness_for_min =
math::min(distance_from_min_to_zero, range_distance);
549 const float max_safe_smoothness_for_max =
math::min(distance_from_max_to_zero, range_distance);
551 const float min_smoothness =
math::min(smoothness, max_safe_smoothness_for_min);
552 const float max_smoothness =
math::min(smoothness, max_safe_smoothness_for_max);
554 return this->
smooth_clamp(
x, min_value, max_value, min_smoothness, max_smoothness);
560 this->
get_input(
"Highlights Threshold").get_single_value_default<float>());
566 this->
get_input(
"Highlights Smoothness").get_single_value_default<float>());
571 return this->
get_input(
"Clamp Highlights").get_single_value_default<
bool>();
577 this->
get_input(
"Maximum Highlights").get_single_value_default<float>());
584 if (this->
context().use_gpu()) {
661 return this->
get_result(
"Glare").should_compute() ||
681 horizontal_pass_result);
682 horizontal_pass_result.
release();
683 return vertical_pass_result;
687 const Result &horizontal_pass_result)
689 if (this->
context().use_gpu()) {
696 const Result &horizontal_pass_result)
717 const int width = size.x;
724 return vertical_pass_result;
728 const Result &horizontal_pass_result)
734 output.allocate_texture(size);
740 const float fade_factor = this->
get_fade();
743 const int width = size.x;
750 for (
int i = 0; i < iterations; i++) {
755 for (
int y = 0;
y < height;
y++) {
761 float4 neighbor_average = (previous_output + next_input) / 2.0f;
770 for (
int y = height - 1;
y >= 0;
y--) {
776 float4 neighbor_average = (previous_output + next_input) / 2.0f;
778 current_input, neighbor_average, fade_factor);
779 output.store_pixel(texel,
Color(non_causal_output));
785 for (
int y = 0;
y < height;
y++) {
789 float4 combined = horizontal + vertical;
800 if (this->
context().use_gpu()) {
830 return horizontal_pass_result;
845 const float fade_factor = this->
get_fade();
848 const int width = size.x;
850 for (const int64_t y : sub_range) {
853 for (int i = 0; i < iterations; i++) {
858 for (int x = 0; x < width; x++) {
859 int2 texel = int2(x, y);
860 float4 previous_output = float4(
861 horizontal_pass_result.load_pixel_zero<Color>(texel - int2(i, 0)));
862 float4 current_input = float4(horizontal_pass_result.load_pixel<Color>(texel));
863 float4 next_input = float4(
864 horizontal_pass_result.load_pixel_zero<Color>(texel + int2(i, 0)));
866 float4 neighbor_average = (previous_output + next_input) / 2.0f;
867 float4 causal_output = math::interpolate(current_input, neighbor_average, fade_factor);
868 horizontal_pass_result.store_pixel(texel, Color(causal_output));
875 for (int x = width - 1; x >= 0; x--) {
876 int2 texel = int2(x, y);
877 float4 previous_output = float4(
878 horizontal_pass_result.load_pixel_zero<Color>(texel + int2(i, 0)));
879 float4 current_input = float4(horizontal_pass_result.load_pixel<Color>(texel));
880 float4 next_input = float4(
881 horizontal_pass_result.load_pixel_zero<Color>(texel - int2(i, 0)));
883 float4 neighbor_average = (previous_output + next_input) / 2.0f;
884 float4 non_causal_output = math::interpolate(
885 current_input, neighbor_average, fade_factor);
886 horizontal_pass_result.store_pixel(texel, Color(non_causal_output));
892 return horizontal_pass_result;
899 highlights, diagonal_pass_result);
900 diagonal_pass_result.
release();
901 return anti_diagonal_pass_result;
905 const Result &diagonal_pass_result)
907 if (this->
context().use_gpu()) {
914 const Result &diagonal_pass_result)
941 return anti_diagonal_pass_result;
945 const Result &diagonal_pass_result)
951 output.allocate_texture(size);
957 const float fade_factor = this->
get_fade();
966 int2 end = start + (anti_diagonal_length - 1) * direction;
970 for (
int i = 0; i < iterations; i++) {
975 for (
int j = 0; j < anti_diagonal_length; j++) {
976 int2 texel = start + j * direction;
981 float4 neighbor_average = (previous_output + next_input) / 2.0f;
990 for (
int j = 0; j < anti_diagonal_length; j++) {
991 int2 texel = end - j * direction;
996 float4 neighbor_average = (previous_output + next_input) / 2.0f;
998 current_input, neighbor_average, fade_factor);
999 output.store_pixel(texel,
Color(non_causal_output));
1005 for (
int j = 0; j < anti_diagonal_length; j++) {
1006 int2 texel = start + j * direction;
1009 float4 combined = horizontal + vertical;
1020 if (this->
context().use_gpu()) {
1050 return diagonal_pass_result;
1065 const float fade_factor = this->
get_fade();
1074 int2 end = start + (diagonal_length - 1) * direction;
1078 for (
int i = 0; i < iterations; i++) {
1083 for (
int j = 0; j < diagonal_length; j++) {
1084 int2 texel = start + j * direction;
1091 float4 neighbor_average = (previous_output + next_input) / 2.0f;
1100 for (
int j = 0; j < diagonal_length; j++) {
1101 int2 texel = end - j * direction;
1108 float4 neighbor_average = (previous_output + next_input) / 2.0f;
1110 current_input, neighbor_average, fade_factor);
1117 return diagonal_pass_result;
1122 return this->
get_input(
"Diagonal Star").get_single_value_default<
bool>();
1135 if (this->
context().use_gpu()) {
1154 return accumulated_streaks_result;
1159 if (this->
context().use_gpu()) {
1184 for (
const int iteration : iterations_range) {
1188 const float2 streak_vector = streak_direction * iteration_magnitude;
1208 if (iteration != iterations_range.
last()) {
1214 input_streak_result.
release();
1217 return output_streak_result;
1232 output.allocate_texture(size);
1237 for (
const int iteration : iterations_range) {
1241 const float2 streak_vector = streak_direction * iteration_magnitude;
1260 neighbors[0] *=
float4(1.0f, color_modulator, color_modulator, 1.0f);
1261 neighbors[1] *=
float4(color_modulator, color_modulator, 1.0f, 1.0f);
1262 neighbors[2] *=
float4(color_modulator, 1.0f, color_modulator, 1.0f);
1267 for (
int i = 0; i < 3; i++) {
1268 weighted_neighbors_sum += fade_factors[i] * neighbors[i];
1275 float4 output_color = (center_color + weighted_neighbors_sum) / 2.0f;
1282 if (iteration != iterations_range.
last()) {
1295 if (this->
context().use_gpu()) {
1329 float4 combined_streaks = current_accumulated_streaks + attenuated_streak;
1353 const float angle = start_angle + (
float(streak_index) / number_of_streaks) * (
M_PI * 2.0f);
1384 const float fade_factor = std::pow(this->
get_fade(), iteration_magnitude);
1385 return float3(fade_factor, std::pow(fade_factor, 2.0f), std::pow(fade_factor, 3.0f));
1396 return std::pow(4.0f, iteration);
1406 return this->
get_input(
"Streaks Angle").get_single_value_default<
float>();
1417 if (this->
context().use_gpu()) {
1425 return accumulated_ghosts_result;
1437 color_modulators.size(),
1438 (
const float (*)[4])color_modulators.data());
1457 for (
const int i : iterations_range) {
1472 if (i != iterations_range.
last()) {
1497 input.allocate_texture(size);
1507 for (
const int i : iterations_range) {
1518 for (
int i = 0; i < 4; i++) {
1519 float scale = scales[i];
1520 float4 color_modulator = color_modulators[i];
1524 float2 scaled_coordinates = (coordinates - 0.5f) *
scale + 0.5f;
1534 float4 multiplier = attenuator * color_modulator;
1535 accumulated_ghost +=
float4(input.sample_bilinear_zero<
Color>(scaled_coordinates)) *
1541 float4 combined_ghost = current_accumulated_ghost + accumulated_ghost;
1548 if (i != iterations_range.last()) {
1550 input.store_pixel(texel, accumulated_ghosts_result.
load_pixel<
Color>(texel));
1578 if (this->
context().use_gpu()) {
1588 return base_ghost_result;
1592 const Result &big_ghost_result,
1593 Result &base_ghost_result)
1618 const Result &big_ghost_result,
1635 float small_ghost_scale = 2.13f;
1636 float big_ghost_scale = -0.97f;
1641 float2 small_ghost_coordinates = (coordinates - 0.5f) * small_ghost_scale + 0.5f;
1642 float2 big_ghost_coordinates = (coordinates - 0.5f) * big_ghost_scale + 0.5f;
1648 float small_ghost_attenuator =
math::max(0.0f,
1649 1.0f - distance_to_center * small_ghost_scale);
1651 0.0f, 1.0f - distance_to_center *
math::abs(big_ghost_scale));
1654 small_ghost_coordinates)) *
1655 small_ghost_attenuator;
1658 big_ghost_attenuator;
1674 std::array<float4, 4> color_modulators;
1675 color_modulators[0] =
float4(1.0f);
1676 color_modulators[1] =
float4(1.0f, color_modulation_factor, color_modulation_factor, 1.0f);
1677 color_modulators[2] =
float4(color_modulation_factor, color_modulation_factor, 1.0f, 1.0f);
1678 color_modulators[3] =
float4(color_modulation_factor, 1.0f, color_modulation_factor, 1.0f);
1680 return color_modulators;
1700 std::array<float, 4> scales;
1701 for (
const int i :
IndexRange(scales.size())) {
1703 const int global_i = iteration * 4 + i;
1707 scales[i] = 2.1f * (1.0f - progression);
1712 scales[i] = -0.99f / scales[i];
1778 if (chain_length < 2) {
1781 if (this->
context().use_gpu()) {
1786 bloom_result.store_pixel(texel, highlights.load_pixel<Color>(texel));
1789 return bloom_result;
1795 const IndexRange upsample_passes_range(chain_length - 1);
1797 for (
const int i : upsample_passes_range) {
1798 Result &input = downsample_chain[upsample_passes_range.
last() - i + 1];
1800 if (this->
context().use_gpu()) {
1810 bloom_output.
share_data(downsample_chain[0]);
1811 downsample_chain[0].release();
1812 return bloom_output;
1828 output.unbind_as_image();
1859 coordinates + pixel_size *
float2(-1.0f, 0.0f)));
1861 coordinates + pixel_size *
float2(0.0f, 1.0f)));
1863 coordinates + pixel_size *
float2(1.0f, 0.0f)));
1865 coordinates + pixel_size *
float2(0.0f, -1.0f)));
1867 coordinates + pixel_size *
float2(-1.0f, -1.0f)));
1869 coordinates + pixel_size *
float2(-1.0f, 1.0f)));
1871 coordinates + pixel_size *
float2(1.0f, -1.0f)));
1873 coordinates + pixel_size *
float2(1.0f, 1.0f)));
1889 downsample_chain.
reserve(chain_length);
1890 for (
int i = 0; i < chain_length; i++) {
1896 Result &base_layer = downsample_chain[0];
1898 if (this->
context().use_gpu()) {
1903 base_layer.store_pixel(texel, highlights.load_pixel<Color>(texel));
1909 const IndexRange downsample_passes_range(chain_length - 1);
1911 for (
const int i : downsample_passes_range) {
1916 const bool use_karis_average = i == downsample_passes_range.first();
1917 if (this->
context().use_gpu()) {
1919 downsample_chain[i], downsample_chain[i + 1], use_karis_average);
1922 if (use_karis_average) {
1931 return downsample_chain;
1936 const bool use_karis_average)
1939 use_karis_average ?
"compositor_glare_bloom_downsample_karis_average" :
1940 "compositor_glare_bloom_downsample_simple_average");
1952 output.unbind_as_image();
1956 template<
bool UseKarisAverage>
1960 output.allocate_texture(size);
2011 if constexpr (!UseKarisAverage) {
2020 result = (4.0f / 32.0f) * center +
2022 (upper_left_near + upper_right_near + lower_left_near + lower_right_near) +
2023 (2.0f / 32.0f) * (left_far + right_far + upper_far + lower_far) +
2025 (upper_left_far + upper_right_far + lower_left_far + lower_right_far);
2035 upper_left_near, upper_right_near, lower_right_near, lower_left_near);
2037 upper_left_far, upper_far, center, left_far);
2039 upper_far, upper_right_far, right_far, center);
2041 center, right_far, lower_right_far, lower_far);
2043 left_far, center, lower_far, lower_left_far);
2050 result = (4.0f / 8.0f) * center_weighted_sum +
2051 (1.0f / 8.0f) * (upper_left_weighted_sum + upper_right_weighted_sum +
2052 lower_left_weighted_sum + lower_right_weighted_sum);
2074 float4 weights = 1.0f / (brightness + 1.0f);
2075 return (color1 * weights.x + color2 * weights.y + color3 * weights.z + color4 * weights.w) *
2089 const float scaled_dimension = smaller_dimension * this->
get_size();
2090 return int(std::log2(
math::max(1.0f, scaled_dimension)));
2099#if defined(WITH_FFTW3)
2106 const int needed_padding_amount = kernel_size;
2108 const int2 needed_spatial_size = image_size + needed_padding_amount - 1;
2115 const int2 frequency_size =
int2(spatial_size.x / 2 + 1, spatial_size.y);
2118 const int channels_count = 3;
2119 const int image_channels_count = 4;
2120 const int64_t spatial_pixels_per_channel =
int64_t(spatial_size.x) * spatial_size.y;
2121 const int64_t frequency_pixels_per_channel =
int64_t(frequency_size.x) * frequency_size.y;
2122 const int64_t spatial_pixels_count = spatial_pixels_per_channel * channels_count;
2123 const int64_t frequency_pixels_count = frequency_pixels_per_channel * channels_count;
2125 float *image_spatial_domain = fftwf_alloc_real(spatial_pixels_count);
2126 std::complex<float> *image_frequency_domain =
reinterpret_cast<std::complex<float> *
>(
2127 fftwf_alloc_complex(frequency_pixels_count));
2130 fftwf_plan forward_plan = fftwf_plan_dft_r2c_2d(
2133 image_spatial_domain,
2134 reinterpret_cast<fftwf_complex *
>(image_frequency_domain),
2137 const float *highlights_buffer =
nullptr;
2138 if (this->
context().use_gpu()) {
2140 highlights_buffer =
static_cast<const float *
>(
2144 highlights_buffer =
static_cast<const float *
>(highlights.
cpu_data().
data());
2150 for (const int64_t y : sub_y_range) {
2151 for (const int64_t x : IndexRange(spatial_size.x)) {
2152 const bool is_inside_image = x < image_size.x && y < image_size.y;
2153 for (const int64_t channel : IndexRange(channels_count)) {
2154 const int64_t base_index = y * spatial_size.x + x;
2155 const int64_t output_index = base_index + spatial_pixels_per_channel * channel;
2156 if (is_inside_image) {
2157 const int64_t image_index = (y * image_size.x + x) * image_channels_count + channel;
2158 image_spatial_domain[output_index] = highlights_buffer[image_index];
2161 image_spatial_domain[output_index] = 0.0f;
2169 for (
const int64_t channel : sub_range) {
2170 fftwf_execute_dft_r2c(forward_plan,
2171 image_spatial_domain + spatial_pixels_per_channel * channel,
2172 reinterpret_cast<fftwf_complex *
>(image_frequency_domain) +
2173 frequency_pixels_per_channel * channel);
2177 const FogGlowKernel &fog_glow_kernel = context().cache_manager().fog_glow_kernels.get(
2178 kernel_size, spatial_size, this->compute_fog_glow_field_of_view());
2185 const float normalization_scale =
float(spatial_size.x) * spatial_size.y *
2186 fog_glow_kernel.normalization_factor();
2188 for (const int64_t channel : IndexRange(channels_count)) {
2189 for (const int64_t y : sub_y_range) {
2190 for (const int64_t x : IndexRange(frequency_size.x)) {
2191 const int64_t base_index = x + y * frequency_size.x;
2192 const int64_t output_index = base_index + frequency_pixels_per_channel * channel;
2193 const std::complex<float> kernel_value = fog_glow_kernel.frequencies()[base_index];
2194 image_frequency_domain[output_index] *= kernel_value / normalization_scale;
2201 fftwf_plan backward_plan = fftwf_plan_dft_c2r_2d(
2204 reinterpret_cast<fftwf_complex *
>(image_frequency_domain),
2205 image_spatial_domain,
2209 for (
const int64_t channel : sub_range) {
2210 fftwf_execute_dft_c2r(backward_plan,
2211 reinterpret_cast<fftwf_complex *
>(image_frequency_domain) +
2212 frequency_pixels_per_channel * channel,
2213 image_spatial_domain + spatial_pixels_per_channel * channel);
2218 fog_glow_result.allocate_texture(highlights.domain());
2223 const_cast<float *
>(highlights_buffer) :
2224 static_cast<
float *>(fog_glow_result.cpu_data_for_write().
data());
2228 for (const int64_t y : sub_y_range) {
2229 for (const int64_t x : IndexRange(image_size.x)) {
2230 for (const int64_t channel : IndexRange(channels_count)) {
2231 const int64_t output_index = (x + y * image_size.x) * image_channels_count;
2232 const int64_t base_index = x + y * spatial_size.x;
2233 const int64_t input_index = base_index + spatial_pixels_per_channel * channel;
2234 output[output_index + channel] = image_spatial_domain[input_index];
2235 output[output_index + 3] = highlights_buffer[output_index + 3];
2241 if (this->
context().use_gpu()) {
2247 fftwf_destroy_plan(forward_plan);
2248 fftwf_destroy_plan(backward_plan);
2249 fftwf_free(image_spatial_domain);
2250 fftwf_free(image_frequency_domain);
2254 if (this->
context().use_gpu()) {
2259 fog_glow_result.store_pixel(texel, highlights.load_pixel<float4>(texel));
2264 return fog_glow_result;
2292 if (max_steps == 0) {
2295 if (this->
context().use_gpu()) {
2300 sun_beams_result.store_pixel(texel, highlights.load_pixel<Color>(texel));
2303 return sun_beams_result;
2306 if (this->
context().use_gpu()) {
2337 return output_image;
2343 return "compositor_glare_sun_beams_jitter";
2345 return "compositor_glare_sun_beams";
2364 int steps =
math::min(max_steps,
int(unbounded_steps));
2371 float2 vector_to_source = source - coordinates;
2372 float2 step_vector = vector_to_source / unbounded_steps;
2374 float accumulated_weight = 0.0f;
2377 int number_of_steps = (1.0f - jitter_factor) * steps;
2380 for (
int i = 0; i <= number_of_steps; i++) {
2395 float weight =
math::square(1.0f - position_index /
float(steps));
2397 accumulated_weight += weight;
2398 accumulated_color += sample_color * weight;
2401 if (accumulated_weight != 0.0f) {
2402 accumulated_color /= accumulated_weight;
2407 output.store_pixel(texel,
Color(accumulated_color));
2422 const bool use_jitter,
2423 float jitter_factor,
2453 if (this->
context().use_gpu()) {
2458 kernel_result.store_pixel(texel, highlights.load_pixel<Color>(texel));
2461 return kernel_result;
2469 convolve(this->
context(), highlights, downsampled_kernel, kernel_result,
true);
2473 return kernel_result;
2478 if (this->
context().use_gpu()) {
2506 return downsampled_kernel;
2529 return downsampled_kernel;
2535 return "compositor_glare_kernel_downsample_float";
2537 return "compositor_glare_kernel_downsample_color";
2555 this->
get_input(
"Kernel Data Type").get_single_value_default<MenuValue>().value);
2569 if (this->
context().use_gpu()) {
2613 output.allocate_texture(domain);
2618 float4 input_color = math::max(float4(0.0f), float4(input.load_pixel<Color>(texel)));
2620 float2 normalized_coordinates = (float2(texel) + float2(0.5f)) /
2621 float2(input.domain().data_size);
2622 float4 glare_color = float4(
2623 glare_result.sample_bilinear_extended<Color>(normalized_coordinates));
2627 rgb_to_hsv_v(glare_color, glare_hsva);
2628 glare_hsva.y = math::clamp(glare_hsva.y * saturation, 0.0f, 1.0f);
2630 hsv_to_rgb_v(glare_hsva, glare_rgba);
2632 float3 combined_color = input_color.xyz() + glare_rgba.xyz() * tint;
2634 output.store_pixel(texel, Color(float4(combined_color, input_color.w)));
2643 if (this->
context().use_gpu()) {
2671 output.unbind_as_image();
2692 glare_hsva.y =
math::clamp(glare_hsva.y * saturation, 0.0f, 1.0f);
2696 float3 adjusted_glare_value = glare_rgba.xyz() * tint;
2745 return math::max(0.0f, this->
get_input(
"Strength").get_single_value_default<float>());
2750 return math::max(0.0f, this->
get_input(
"Saturation").get_single_value_default<float>());
2755 return float4(this->
get_input(
"Tint").get_single_value_default<Color>()).xyz();
2776 this->
get_input(
"Color Modulation").get_single_value_default<float>(), 0.0f, 1.0f);
2781 return this->
get_input(
"Sun Position").get_single_value_default<
float2>();
2816 this->
get_input(
"Quality").get_single_value_default<MenuValue>().value);
2831 ntype.
ui_description =
"Add lens flares, fog and glows around bright parts of the image";
#define NODE_CLASS_OP_FILTER
Read Blender memory allocation and freeing.
#define NOD_REGISTER_NODE(REGISTER_FUNC)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
constexpr IndexRange()=default
Result create_result(ResultType type, ResultPrecision precision)
gpu::Shader * get_shader(const char *info_name, ResultPrecision precision)
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
void allocate_default_remaining_outputs()
Context & context() const
Result & get_input(StringRef identifier) const
virtual Domain compute_domain()
void share_data(const Result &source)
bool is_single_value() const
T sample_bilinear_extended(const float2 &coordinates) const
void store_pixel(const int2 &texel, const T &pixel_value)
bool should_compute() const
void allocate_texture(const Domain domain, const bool from_pool=true, const std::optional< ResultStorageType > storage_type=std::nullopt)
void unbind_as_texture() const
T load_pixel_zero(const int2 &texel) const
static ResultType type(gpu::TextureFormat format)
void bind_as_texture(gpu::Shader *shader, const char *texture_name) const
T sample_bilinear_zero(const float2 &coordinates) const
T load_pixel(const int2 &texel) const
void unbind_as_image() const
void bind_as_image(gpu::Shader *shader, const char *image_name, bool read=false) const
DeclType::Builder & add_input(UString name, UString identifier=""_ustr)
PanelDeclarationBuilder & add_panel(UString name, int identifier=-1)
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
const bNodeTree & node_tree() const
const bNodeSocket & other_socket() const
void update_and_connect_available_socket(bNode &new_node, UString socket_name)
bNode & add_node(UString idname)
Self & default_closed(bool closed)
StructureType structure_type
void write_highlights_output_cpu(const Result &highlights)
void execute_mix_cpu(const Result &glare_result)
NodeOperation(Context &context, const bNode &node)
Result execute_sun_beams_gpu(Result &highlights, const int max_steps)
float get_small_ghost_radius()
CMPNodeGlareType get_type()
float get_jitter_factor()
void write_glare_output(const Result &glare)
void write_highlights_output_gpu(const Result &highlights)
void compute_bloom_upsample_gpu(const Result &input, Result &output)
Result execute_fog_glow(const Result &highlights)
float get_ghost_color_modulation_factor()
float3 compute_streak_fade_factors(float iteration_magnitude)
int get_number_of_streaks()
Result execute_sun_beams_cpu(Result &highlights, const int max_steps)
Result downsample_kernel_gpu(const Result &kernel)
Result apply_streak_filter(const Result &highlights, const float2 &streak_direction)
float adaptive_smooth_clamp(const float x, const float min_value, const float max_value, const float smoothness)
Result compute_glare(Result &highlights_result)
void accumulate_streak_gpu(const Result &streak_result, Result &accumulated_streaks_result)
Result execute_highlights_cpu()
Result execute_highlights_gpu()
bool get_clamp_highlights()
void write_highlights_output(const Result &highlights)
Result execute_simple_star_anti_diagonal_pass(const Result &highlights, const Result &diagonal_pass_result)
float3 get_corrected_tint()
void write_glare_output_gpu(const Result &glare)
float smooth_min(const float a, const float b, const float smoothness)
Result compute_highlights()
void compute_base_ghost_gpu(const Result &small_ghost_result, const Result &big_ghost_result, Result &base_ghost_result)
float2 get_sun_position()
float compute_streak_attenuation_factor()
Result execute_simple_star_axis_aligned(const Result &highlights)
math::AngleRadian compute_fog_glow_field_of_view()
Result execute_simple_star_horizontal_pass_gpu(const Result &highlights)
Domain get_glare_image_domain()
Result apply_streak_filter_gpu(const Result &highlights, const float2 &streak_direction)
Result downsample_kernel_cpu(const Result &kernel)
float smooth_clamp(const float x, const float min_value, const float max_value, const float min_smoothness, const float max_smoothness)
float get_maximum_brightness()
void execute_mix(const Result &glare_result)
Vector< Result > compute_bloom_downsample_chain(const Result &highlights, int chain_length)
std::array< float4, 4 > compute_ghost_color_modulators()
Result execute_simple_star_horizontal_pass(const Result &highlights)
Result execute_simple_star_diagonal_pass_cpu(const Result &highlights)
Result execute_simple_star_anti_diagonal_pass_gpu(const Result &highlights, const Result &diagonal_pass_result)
void compute_bloom_downsample_cpu(const Result &input, Result &output)
void accumulate_ghosts_cpu(const Result &base_ghost, Result &accumulated_ghosts_result)
Result execute_simple_star_vertical_pass_cpu(const Result &highlights, const Result &horizontal_pass_result)
float get_normalization_scale()
int compute_bloom_chain_length()
Result execute_simple_star_horizontal_pass_cpu(const Result &highlights)
CMPNodeGlareQuality get_quality()
float compute_streak_iteration_magnitude(int iteration)
Result execute_simple_star_vertical_pass(const Result &highlights, const Result &horizontal_pass_result)
void compute_bloom_upsample_cpu(const Result &input, Result &output)
float smooth_max(const float a, const float b, const float smoothness)
Result execute_simple_star_diagonal_pass(const Result &highlights)
Result execute_simple_star_vertical_pass_gpu(const Result &highlights, const Result &horizontal_pass_result)
float compute_streak_color_modulator(int iteration)
const char * get_kernel_downsample_shader_name(const Result &kernel)
Result execute_simple_star(const Result &highlights)
Result execute_bloom(Result &highlights)
Result compute_base_ghost(const Result &highlights)
void write_glare_output_cpu(const Result &glare)
Result downsample_kernel(const Result &kernel)
bool should_compute_glare()
Result execute_simple_star_diagonal_pass_gpu(const Result &highlights)
Result execute_streaks(const Result &highlights)
void accumulate_streak(const Result &streak_result, Result &accumulated_streaks_result)
void accumulate_streak_cpu(const Result &streak, Result &accumulated_streaks)
Result execute_sun_beams(Result &highlights)
Result execute_simple_star_diagonal(const Result &highlights)
const char * get_compositor_sun_beams_shader()
const Result & get_kernel_input()
float get_big_ghost_radius()
Result apply_streak_filter_cpu(const Result &highlights, const float2 &streak_direction)
float get_highlights_smoothness()
void execute_mix_gpu(const Result &glare_result)
float get_color_modulation()
void compute_base_ghost_cpu(const Result &small_ghost_result, const Result &big_ghost_result, Result &combined_ghost)
float2 compute_streak_direction(int streak_index)
void compute_bloom_downsample_gpu(const Result &input, Result &output, const bool use_karis_average)
float get_streaks_angle()
Result execute_simple_star_anti_diagonal_pass_cpu(const Result &highlights, const Result &diagonal_pass_result)
float get_sample_position(const int i, const bool use_jitter, float jitter_factor, const float random_offset)
float4 karis_brightness_weighted_sum(const float4 &color1, const float4 &color2, const float4 &color3, const float4 &color4)
Result execute_ghost(const Result &highlights)
float get_max_highlights()
Result execute_kernel(const Result &highlights)
std::array< float, 4 > compute_ghost_scales(int iteration)
void accumulate_ghosts_gpu(const Result &base_ghost_result, Result &accumulated_ghosts_result)
int get_number_of_iterations()
KernelDataType get_kernel_data_type()
void operator()(LinkSearchOpParams ¶ms)
float3x3 scale(float3x3 mat, float2 scale)
void node_register_type(bNodeType &ntype)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
int compute_diagonal_length(const int2 &size, const int diagonal_index)
int2 compute_anti_diagonal_start(const int2 &size, const int index)
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
int compute_anti_diagonal_length(const int2 &size, const int diagonal_index)
void symmetric_separable_blur(Context &context, const Result &input, Result &output, const float2 &radius, const math::FilterKernel filter_type=math::FilterKernel::Gauss, const bool extend_bounds=false)
int compute_number_of_diagonals(const int2 &size)
ColorSceneLinear4f< eAlpha::Premultiplied > Color
void convolve(Context &context, const Result &input, const Result &kernel, Result &output, const bool normalize_kernel)
int2 compute_diagonal_start(const int2 &size, const int index)
int2 get_diagonal_direction()
int2 get_anti_diagonal_direction()
void parallel_for(const int2 range, const Function &function)
int context(const bContext *C, const char *member, bContextDataResult *result)
int optimal_size_for_real_transform(int size)
AngleRadianBase< float > AngleRadian
T cos(const AngleRadianBase< T > &a)
T pow(const T &x, const T &power)
T clamp(const T &a, const T &min, const T &max)
T safe_divide(const T &a, const T &b)
T reduce_max(const VecBase< T, Size > &a)
T distance(const T &a, const T &b)
VecBase< T, Size > divide_ceil(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
T length(const VecBase< T, Size > &a)
T reduce_min(const VecBase< T, Size > &a)
T min(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
T sin(const AngleRadianBase< T > &a)
T max(const T &a, const T &b)
T reduce_add(const VecBase< T, Size > &a)
static const EnumPropertyItem type_items[]
static void node_declare(NodeDeclarationBuilder &b)
static const EnumPropertyItem quality_items[]
static void node_update_glare_label(const bNodeTree *ntree, const bNode *node, char *label, int maxlen)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void gather_link_searches(GatherLinkSearchOpParams ¶ms)
static const EnumPropertyItem kernel_data_type_items[]
static void node_register()
static void node_init(bNodeTree *, bNode *node)
float hash_to_float(uint32_t kx)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
void GPU_texture_update(gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
void GPU_texture_copy(gpu::Texture *dst, gpu::Texture *src)
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
void GPU_shader_uniform_4fv(gpu::Shader *sh, const char *name, const float data[4])
@ CMP_NODE_GLARE_QUALITY_MEDIUM
@ CMP_NODE_GLARE_QUALITY_HIGH
@ CMP_NODE_GLARE_QUALITY_LOW
void GPU_shader_uniform_4fv_array(gpu::Shader *sh, const char *name, int len, const float(*val)[4])
@ CMP_NODE_GLARE_SUN_BEAMS
@ CMP_NODE_GLARE_SIMPLE_STAR
@ CMP_NODE_GLARE_FOG_GLOW
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void GPU_memory_barrier(GPUBarrier barrier)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
BMesh const char void * data
void GPU_shader_uniform_3fv(gpu::Shader *sh, const char *name, const float data[3])
void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter)
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1i(gpu::Shader *sh, const char *name, int value)
@ GPU_BARRIER_TEXTURE_UPDATE
void GPU_shader_uniform_2fv(gpu::Shader *sh, const char *name, const float data[2])
void GPU_texture_extend_mode(gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
void GPU_shader_uniform_1f(gpu::Shader *sh, const char *name, float value)
void GPU_texture_clear(gpu::Texture *texture, eGPUDataFormat data_format, const void *data)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
void node_free_standard_storage(bNode *node)
void * GPU_texture_read(gpu::Texture *texture, eGPUDataFormat data_format, int mip_level)
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define MAX_GLARE_ITERATIONS
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::bNodeTreeType * typeinfo
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
std::string ui_description
void(*) labelfunc(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
NodeGetCompositorOperationFunction get_compositor_operation
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
static AngleRadianBase from_degree(const float °rees)
void reserve(int new_size)