20 flags_.can_be_constant =
true;
23 distortion_const_ =
false;
24 dispersion_const_ =
false;
25 variables_ready_ =
false;
30 distortion_ = distortion;
31 distortion_const_ =
true;
36 dispersion_ = dispersion;
37 dispersion_const_ =
true;
48 distortion_ =
static_cast<ConstantOperation *
>(distortion_op)->get_constant_elem()[0];
51 dispersion_ =
static_cast<ConstantOperation *
>(dispersion_op)->get_constant_elem()[0];
53 update_variables(distortion_, dispersion_);
65void ScreenLensDistortionOperation::get_uv(
const float xy[2],
float uv[2])
const
67 uv[0] = sc_ * ((
xy[0] + 0.5f) - cx_) / cx_;
68 uv[1] = sc_ * ((
xy[1] + 0.5f) - cy_) / cy_;
71void ScreenLensDistortionOperation::distort_uv(
const float uv[2],
float t,
float xy[2])
const
73 float d = 1.0f / (1.0f +
sqrtf(t));
78bool ScreenLensDistortionOperation::get_delta(
float r_sq,
83 float t = 1.0f - k4 * r_sq;
85 distort_uv(uv, t, delta);
92void ScreenLensDistortionOperation::accumulate(
const MemoryBuffer *buffer,
97 const float delta[3][2],
103 float dsf =
len_v2v2(delta[a], delta[
b]) + 1.0f;
104 int ds = jitter_ ? (dsf < 4.0f ? 2 :
int(
sqrtf(dsf))) :
int(dsf);
105 float sd = 1.0f /
float(ds);
110 for (
float z = 0;
z < ds;
z++) {
112 float t = 1.0f - (k4 + tz * dk4) * r_sq;
115 distort_uv(uv, t,
xy);
116 buffer->read_elem_bilinear(
xy[0],
xy[1], color);
118 sum[a] += (1.0f - tz) * color[a];
119 sum[
b] += (tz)*color[
b];
130void ScreenLensDistortionOperation::determineUV(
float result[6],
float x,
float y)
const
132 const float xy[2] = {
x,
y};
140 get_delta(uv_dot, k4_[0], uv,
result + 0);
141 get_delta(uv_dot, k4_[1], uv,
result + 2);
142 get_delta(uv_dot, k4_[2], uv,
result + 4);
145void ScreenLensDistortionOperation::update_variables(
float distortion,
float dispersion)
149 float d = 0.25f *
max_ff(
min_ff(dispersion, 1.0f), 0.0f);
152 maxk_ =
max_fff(k_[0], k_[1], k_[2]);
153 sc_ = (fit_ && (maxk_ > 0.0f)) ? (1.0f / (1.0f + 2.0f * maxk_)) : (1.0f / (1.0f + maxk_));
154 dk4_[0] = 4.0f * (k_[1] - k_[0]);
155 dk4_[1] = 4.0f * (k_[2] - k_[1]);
175 if (input_idx != 0) {
186 r_input_area =
image->get_canvas();
205 const bool valid_r = get_delta(uv_dot, k4_[0], uv, delta[0]);
206 const bool valid_g = get_delta(uv_dot, k4_[1], uv, delta[1]);
207 const bool valid_b = get_delta(uv_dot, k4_[2], uv, delta[2]);
208 if (!(valid_r && valid_g && valid_b)) {
213 int count[3] = {0, 0, 0};
214 float sum[4] = {0, 0, 0, 0};
215 accumulate(input_image, 0, 1, uv_dot, uv, delta,
sum,
count);
216 accumulate(input_image, 1, 2, uv_dot, uv, delta,
sum,
count);
MINLINE float max_fff(float a, float b, float c)
MINLINE float max_ff(float a, float b)
MINLINE float min_ff(float a, float b)
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE float len_squared_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void zero_v4(float r[4])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
struct RNG * BLI_rng_new(unsigned int seed)
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
float BLI_rng_get_float(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Platform independent time functions.
long int BLI_time_now_seconds_i(void)
#define POINTER_AS_INT(i)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
static T sum(const btAlignedObjectArray< T > &items)
a MemoryBuffer contains access to the data
bool is_a_single_elem() const
float * get_elem(int x, int y)
NodeOperation contains calculation logic.
unsigned int get_height() const
void add_output_socket(DataType datatype)
const NodeOperationFlags get_flags() const
SocketReader * get_input_socket_reader(unsigned int index)
unsigned int get_width() const
NodeOperationFlags flags_
NodeOperation * get_input_operation(int index)
void set_determined_canvas_modifier(std::function< void(rcti &canvas)> fn)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
virtual void determine_canvas(const rcti &preferred_area, rcti &r_area)
void deinit_execution() override
void set_distortion(float distortion)
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override
Get input operation area being read by this operation on rendering given output area.
void determine_canvas(const rcti &preferred_area, rcti &r_area) override
ScreenLensDistortionOperation()
void init_data() override
void set_dispersion(float dispersion)
void init_execution() override
input_tx image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "preview_img") .compute_source("compositor_compute_preview.glsl") .do_static_compilation(true)
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
constexpr rcti COM_CONSTANT_INPUT_AREA_OF_INTEREST
NodeOperation SocketReader
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static blender::bke::bNodeSocketTemplate inputs[]
bool is_constant_operation