6 #include "COM_SMAAAreaTexture.h"
37 #define SMAA_AREATEX_SIZE 80
38 #define SMAA_AREATEX_MAX_DISTANCE 20
39 #define SMAA_AREATEX_MAX_DISTANCE_DIAG 20
40 #define SMAA_MAX_SEARCH_STEPS 362
41 #define SMAA_MAX_SEARCH_STEPS_DIAG 19
66 float iy =
floorf(yoffset);
67 float fy = yoffset - iy;
70 float color00[4], color01[4];
72 sample(reader,
x + 0,
y + 0, color00);
73 sample(reader,
x + 0,
y + 1, color01);
84 float ix =
floorf(xoffset);
85 float fx = xoffset - ix;
88 float color00[4], color10[4];
90 sample(reader,
x + 0,
y + 0, color00);
91 sample(reader,
x + 1,
y + 0, color10);
113 static void area(
int d1,
int d2,
int e1,
int e2,
float weights[2])
120 float fx =
x - ix, fy =
y - iy;
121 int X = (int)ix,
Y = (
int)iy;
129 interpf(weights11[0], weights01[0], fx),
interpf(weights10[0], weights00[0], fx), fy);
131 interpf(weights11[1], weights01[1], fx),
interpf(weights10[1], weights00[1], fx), fy);
138 static void area_diag(
int d1,
int d2,
int e1,
int e2,
float weights[2])
200 const rcti &output_area,
203 r_input_area.
xmax = output_area.
xmax + 1;
204 r_input_area.
xmin = output_area.
xmin - 2;
205 r_input_area.
ymax = output_area.
ymax + 1;
206 r_input_area.
ymin = output_area.
ymin - 2;
220 float Dleft =
fabsf(
L - Lleft);
221 float Dtop =
fabsf(
L - Ltop);
239 float Dright =
fabsf(
L - Lright);
240 float Dbottom =
fabsf(
L - Lbottom);
256 float Dleftleft =
fabsf(Lleft - Lleftleft);
257 float Dlefttop =
fabsf(Lleft - Llefttop);
258 float Dleftbottom =
fabsf(Lleft - Lleftbottom);
261 max_delta =
fmaxf(max_delta,
fmaxf(Dleftleft,
fmaxf(Dlefttop, Dleftbottom)));
276 float Dtoptop =
fabsf(Ltop - Ltoptop);
277 float Dtopleft =
fabsf(Ltop - Llefttop);
278 float Dtopright =
fabsf(Ltop - Ltopright);
281 max_delta =
fmaxf(max_delta,
fmaxf(Dtoptop,
fmaxf(Dtopleft, Dtopright)));
307 const float Dleft =
fabsf(
L - Lleft);
308 const float Dtop =
fabsf(
L - Ltop);
311 it.out[0] = (
x > 0 && Dleft >=
threshold_) ? 1.0f : 0.0f;
312 it.out[1] = (
y > 0 && Dtop >=
threshold_) ? 1.0f : 0.0f;
326 const float Dright =
fabsf(
L - Lright);
327 const float Dbottom =
fabsf(
L - Lbottom);
337 if (it.out[0] != 0.0f) {
343 const float Dleftleft =
fabsf(Lleft - Lleftleft);
344 const float Dlefttop =
fabsf(Lleft - Llefttop);
345 const float Dleftbottom =
fabsf(Lleft - Lleftbottom);
348 max_delta =
fmaxf(max_delta,
fmaxf(Dleftleft,
fmaxf(Dlefttop, Dleftbottom)));
357 if (it.out[1] != 0.0f) {
363 const float Dtoptop =
fabsf(Ltop - Ltoptop);
364 const float Dtopleft =
fabsf(Ltop - Llefttop);
365 const float Dtopright =
fabsf(Ltop - Ltopright);
368 max_delta =
fmaxf(max_delta,
fmaxf(Dtoptop,
fmaxf(Dtopleft, Dtopright)));
387 image_reader_ =
nullptr;
400 sample_image_fn_ = [=](
int x,
int y,
float *
out) {
sample(image_reader_,
x,
y,
out); };
407 corner_rounding_ =
static_cast<int>(
scalenorm(0, 100, rounding));
415 float edges[4],
c[4];
421 if (edges[1] > 0.0f) {
424 calculate_diag_weights(
x,
y, edges,
output);
433 int left = search_xleft(
x,
y);
434 int right = search_xright(
x,
y);
461 if (corner_rounding_) {
467 if (edges[0] > 0.0f) {
469 if (is_vertical_search_unneeded(
x,
y)) {
474 int top = search_yup(
x,
y);
501 if (corner_rounding_) {
511 sample_image_fn_ = [=](
int x,
int y,
float *
out) {
image->read_elem_checked(
x,
y,
out); };
523 sample_image_fn_(
x,
y, edges);
527 if (edges[1] > 0.0f) {
530 calculate_diag_weights(
x,
y, edges, it.out);
539 int left = search_xleft(
x,
y);
540 int right = search_xright(
x,
y);
545 sample_image_fn_(
left,
y - 1,
c);
549 sample_image_fn_(
left,
y,
c);
553 sample_image_fn_(
right + 1,
y - 1,
c);
557 sample_image_fn_(
right + 1,
y,
c);
564 area(d1, d2, e1, e2, it.out);
567 if (corner_rounding_) {
568 detect_horizontal_corner_pattern(it.out,
left,
right,
y, d1, d2);
573 if (edges[0] > 0.0f) {
575 if (is_vertical_search_unneeded(
x,
y)) {
580 int top = search_yup(
x,
y);
586 sample_image_fn_(
x - 1,
top,
c);
590 sample_image_fn_(
x,
top,
c);
594 sample_image_fn_(
x - 1,
bottom + 1,
c);
604 area(d1, d2, e1, e2, it.out + 2);
607 if (corner_rounding_) {
608 detect_vertical_corner_pattern(it.out + 2,
x,
top,
bottom, d1, d2);
616 image_reader_ =
nullptr;
635 const rcti &output_area,
638 r_input_area.
xmax = output_area.
xmax +
640 r_input_area.
xmin = output_area.
xmin -
643 r_input_area.
ymin = output_area.
ymin -
650 int SMAABlendingWeightCalculationOperation::search_diag1(
int x,
int y,
int dir,
bool *found)
659 sample_image_fn_(
x,
y,
e);
666 return (dir < 0) ?
x :
x - dir;
673 int SMAABlendingWeightCalculationOperation::search_diag2(
int x,
int y,
int dir,
bool *found)
682 sample_image_fn_(
x,
y,
e);
687 sample_image_fn_(
x + 1,
y,
e);
690 return (dir > 0) ?
x :
x - dir;
697 void SMAABlendingWeightCalculationOperation::calculate_diag_weights(
int x,
699 const float edges[2],
703 bool d1_found, d2_found;
713 if (edges[0] > 0.0f) {
714 d1 =
x - search_diag1(
x,
y, -1, &d1_found);
720 d2 = search_diag1(
x,
y, 1, &d2_found) -
x;
758 d1 =
x - search_diag2(
x,
y, -1, &d1_found);
759 sample_image_fn_(
x + 1,
y,
e);
761 d2 = search_diag2(
x,
y, 1, &d2_found) -
x;
806 bool SMAABlendingWeightCalculationOperation::is_vertical_search_unneeded(
int x,
int y)
817 sample_image_fn_(
x - 1,
y,
e);
819 d1 =
x - search_diag2(
x - 1,
y, -1, &found);
824 d2 = search_diag2(
x - 1,
y, 1, &found) -
x;
826 return (d1 + d2 > 2);
832 int SMAABlendingWeightCalculationOperation::search_xleft(
int x,
int y)
838 sample_image_fn_(
x,
y,
e);
845 sample_image_fn_(
x,
y - 1,
e);
855 int SMAABlendingWeightCalculationOperation::search_xright(
int x,
int y)
862 sample_image_fn_(
x,
y,
e);
867 sample_image_fn_(
x,
y - 1,
e);
876 int SMAABlendingWeightCalculationOperation::search_yup(
int x,
int y)
882 sample_image_fn_(
x,
y,
e);
889 sample_image_fn_(
x - 1,
y,
e);
899 int SMAABlendingWeightCalculationOperation::search_ydown(
int x,
int y)
906 sample_image_fn_(
x,
y,
e);
911 sample_image_fn_(
x - 1,
y,
e);
923 void SMAABlendingWeightCalculationOperation::detect_horizontal_corner_pattern(
924 float weights[2],
int left,
int right,
int y,
int d1,
int d2)
926 float factor[2] = {1.0f, 1.0f};
927 float rounding = corner_rounding_ / 100.0f;
931 rounding *= (d1 == d2) ? 0.5f : 1.0f;
935 sample_image_fn_(
left,
y + 1,
e);
936 factor[0] -= rounding *
e[0];
937 sample_image_fn_(
left,
y - 2,
e);
938 factor[1] -= rounding *
e[0];
942 sample_image_fn_(
right + 1,
y + 1,
e);
943 factor[0] -= rounding *
e[0];
944 sample_image_fn_(
right + 1,
y - 2,
e);
945 factor[1] -= rounding *
e[0];
948 weights[0] *=
CLAMPIS(factor[0], 0.0f, 1.0f);
949 weights[1] *=
CLAMPIS(factor[1], 0.0f, 1.0f);
952 void SMAABlendingWeightCalculationOperation::detect_vertical_corner_pattern(
953 float weights[2],
int x,
int top,
int bottom,
int d1,
int d2)
955 float factor[2] = {1.0f, 1.0f};
956 float rounding = corner_rounding_ / 100.0f;
960 rounding *= (d1 == d2) ? 0.5f : 1.0f;
964 sample_image_fn_(
x + 1,
top,
e);
965 factor[0] -= rounding *
e[1];
966 sample_image_fn_(
x - 2,
top,
e);
967 factor[1] -= rounding *
e[1];
971 sample_image_fn_(
x + 1,
bottom + 1,
e);
972 factor[0] -= rounding *
e[1];
973 sample_image_fn_(
x - 2,
bottom + 1,
e);
974 factor[1] -= rounding *
e[1];
977 weights[0] *=
CLAMPIS(factor[0], 0.0f, 1.0f);
978 weights[1] *=
CLAMPIS(factor[1], 0.0f, 1.0f);
991 image1Reader_ =
nullptr;
992 image2Reader_ =
nullptr;
1029 float offset1, offset2, weight1, weight2, color1[4], color2[4];
1047 samplefunc(image1Reader_,
x,
y, offset1, color1);
1048 samplefunc(image1Reader_,
x,
y, offset2, color2);
1055 const rcti &out_area,
1061 const float x = it.x;
1062 const float y = it.y;
1069 const float right =
w[3];
1081 float offset1, offset2, weight1, weight2, color1[4], color2[4];
1099 sample_fn(image1,
x,
y, offset1, color1);
1100 sample_fn(image1,
x,
y, offset2, color2);
1109 image1Reader_ =
nullptr;
1110 image2Reader_ =
nullptr;
1127 const rcti &output_area,
1130 r_input_area = output_area;
typedef float(TangentPoint)[2]
#define CMP_DEFAULT_SMAA_CORNER_ROUNDING
#define CMP_DEFAULT_SMAA_CONTRAST_LIMIT
#define CMP_DEFAULT_SMAA_THRESHOLD
MINLINE float scalenorm(float a, float b, float x)
MINLINE float interpf(float a, float b, float t)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f)
MINLINE void zero_v4(float r[4])
MINLINE void zero_v2(float r[2])
MINLINE bool is_zero_v2(const float a[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
#define SMAA_AREATEX_MAX_DISTANCE
#define SMAA_AREATEX_MAX_DISTANCE_DIAG
#define SMAA_AREATEX_SIZE
#define SMAA_MAX_SEARCH_STEPS
#define SMAA_MAX_SEARCH_STEPS_DIAG
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble right
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble top
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble bottom
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
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 Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input 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 a color
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
a MemoryBuffer contains access to the data of a chunk
void read_elem_checked(int x, int y, float *out) const
NodeOperation contains calculation logic.
unsigned int get_height() const
void add_output_socket(DataType datatype)
SocketReader * get_input_socket_reader(unsigned int index)
unsigned int get_width() const
eExecutionModel execution_model_
NodeOperationFlags flags_
NodeOperation * get_input_operation(int index)
void read(float result[4], int x, int y, void *chunk_data)
virtual bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
virtual void * initialize_tile_data(rcti *)
void update_memory_buffer_started(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void set_corner_rounding(float rounding)
bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output) 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 deinit_execution() override
void execute_pixel(float output[4], int x, int y, void *data) override
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
SMAABlendingWeightCalculationOperation()
void * initialize_tile_data(rcti *rect) override
void init_execution() override
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
SocketReader * value_reader_
SocketReader * image_reader_
void set_local_contrast_adaptation_factor(float factor)
void init_execution() 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.
bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output) override
void set_threshold(float threshold)
void deinit_execution() override
virtual void execute_pixel(float output[4], int x, int y, void *data) override
SMAAEdgeDetectionOperation()
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void deinit_execution() override
void * initialize_tile_data(rcti *rect) override
void execute_pixel(float output[4], int x, int y, void *data) override
bool determine_depending_area_of_interest(rcti *input, ReadBufferOperation *read_operation, rcti *output) override
SMAANeighborhoodBlendingOperation()
void init_execution() 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.
SyclQueue void void size_t num_bytes void
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
ccl_gpu_kernel_postfix ccl_global float int int int int float threshold
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_global KernelShaderEvalInput * input
static void area(int d1, int d2, int e1, int e2, float weights[2])
void expand_area_for_sampler(rcti &area, PixelSampler sampler)
static void sample_bilinear_vertical(T *reader, int x, int y, float yoffset, float color[4])
typename BuffersIteratorBuilder< T >::Iterator BuffersIterator
static const float * areatex_sample_internal(const float *areatex, int x, int y)
static void sample(SocketReader *reader, int x, int y, float color[4])
static void sample_bilinear_horizontal(T *reader, int x, int y, float xoffset, float color[4])
static void area_diag(int d1, int d2, int e1, int e2, float weights[2])
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static bNodeSocketTemplate inputs[]