2022-02-11 14:56:03 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2011 Blender Foundation. */
|
2012-07-11 19:32:32 +00:00
|
|
|
|
____
`````|````` | | | ..''''
| | | |______ .''
| | | | ..'
| | |_______ |___________ ....''
merge to TRUNK!
* The old compositor is still available (Debug Menu: 200)
This commit was brought to you by:
Developers:
* Monique Dewanchand
* Jeroen Bakker
* Dalai Felinto
* Lukas Tönne
Review:
* Brecht van Lommel
Testers:
* Nate Wiebe
* Wolfgang Faehnle
* Carlo Andreacchio
* Daniel Salazar
* Artur Mag
* Christian Krupa
* Francesco Siddi
* Dan McGrath
* Bassam Kurdali
But mostly by the community:
Gold:
Joshua Faulkner
Michael Tiemann
Francesco Paglia
Blender Guru
Blender Developers Fund
Silver:
Pablo Vazquez
Joel Heethaar
Amrein Olivier
Ilias Karasavvidis
Thomas Kumlehn
Sebastian Koenig
Hannu Hoffrén
Benjamin Dansie
Fred M'ule
Michel Vilain
Bradley Cathey
Gianmichele Mariani
Gottfried Hofmann
Bjørnar Frøyse
Valentijn Bruning
Paul Holmes
Clemens Rudolph
Juris Graphix
David Strebel
Ronan Zeegers
François Tarlier
Felipe Andres Esquivel Reed
Olaf Beckman
Jesus Alberto Olmos Linares
Kajimba
Maria Figueiredo
Alexandr Galperin
Francesco Siddi
Julio Iglesias Lopez
Kjartan Tysdal
Thomas Torfs
Film Works
Teruyuki Nakamura
Roger Luethi
Benoit Bolsee
Stefan Abrahamsen
Andreas Mattijat
Xavier Bouchoux
Blender 3D Graphics and Animation
Henk Vostermans
Daniel Blanco Delgado
BlenderDay/2011
Bradley Cathey
Matthieu Dupont de Dinechin
Gianmichele Mariani
Jérôme Scaillet
Bronze (Ivo Grigull, Dylan Urquidi, Philippe Derungs, Phil Beauchamp, Bruce Parrott, Mathieu Quiblier, Daniel Martinez, Leandro Inocencio, Lluc Romaní Brasó,
Jonathan Williamson, Michael Ehlen, Karlis Stigis, Dreamsteep, Martin Lindelöf, Filippo Saracino, Douwe van der Veen, Olli Äkräs, Bruno D'Arcangeli,
Francisco Sedrez Warmling, Watchmike.ca, peter lener, Matteo Novellino, Martin Kirsch, Austars Schnore, KC Elliott, Massimiliano Puliero, Karl Stein,
Wood Design Studios, Omer Khan, Jyrki Kanto, Michał Krupa, Lars Brubaker, Neil Richmond, Adam Kalisz, Robert Garlington, Ian Wilson, Carlo Andreacchio,
Jeremias Boos, Robert Holcomb, Gabriel Zöller, Robert Cude, Natibel de Leon, Nathan Turnage, Nicolas Vergnes, Philipp Kleinhenz, Norman Hartig, Louis Kreusel,
Christopher Taylor, Giovanni Remondini, Daniel Rentzsch, Nico Partipilo, Thomas Ventresco, Johannes Schwarz, Александр Коротеев, Brendon Harvey,
Marcelo G. Malheiros, Marius Giurgi, Richard Burns, Perttu Iso-Metsälä, Steve Bazin, Radoslav Borisov, Yoshiyuki Shida, Julien Guigner, Andrew Hunter,
Philipp Oeser, Daniel Thul, Thobias Johansson, Mauro Bonecchi, Georg Piorczynski, Sebastian Michailidis, L M Weedy, Gen X, Stefan Hinze, Nicolò Zubbini,
Erik Pusch, Rob Scott, Florian Koch, Charles Razack, Adrian Baker, Oliver Villar Diz, David Revoy, Julio Iglesias Lopez, Coen Spoor, Carlos Folch,
Joseph Christie, Victor Hernández García, David Mcsween, James Finnerty, Cory Kruckenberg, Giacomo Graziosi, Olivier Saraja, Lars Brubaker, Eric Hudson,
Johannes Schwarz, David Elguea, Marcus Schulderinsky, Karel De Bruijn, Lucas van Wijngaarden, Stefano Ciarrocchi, Mehmet Eribol, Thomas Berglund, Zuofei Song,
Dylan Urquidi )
2012-05-17 12:49:33 +00:00
|
|
|
/// This file contains all opencl kernels for node-operation implementations
|
|
|
|
|
|
2012-06-08 09:17:07 +00:00
|
|
|
// Global SAMPLERS
|
2012-07-11 19:32:32 +00:00
|
|
|
const sampler_t SAMPLER_NEAREST = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;
|
|
|
|
|
const sampler_t SAMPLER_NEAREST_CLAMP = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;
|
2012-06-08 09:17:07 +00:00
|
|
|
|
2019-10-29 09:35:24 +01:00
|
|
|
__constant const int2 zero = {0,0};
|
2012-06-08 09:17:07 +00:00
|
|
|
|
|
|
|
|
// KERNEL --- BOKEH BLUR ---
|
2021-10-13 23:01:15 +02:00
|
|
|
__kernel void bokeh_blur_kernel(__read_only image2d_t bounding_box, __read_only image2d_t input_image,
|
|
|
|
|
__read_only image2d_t bokeh_image, __write_only image2d_t output,
|
|
|
|
|
int2 offset_input, int2 offset_output, int radius, int step, int2 dimension, int2 offset)
|
2012-05-19 13:55:54 +00:00
|
|
|
{
|
2019-10-29 09:35:24 +01:00
|
|
|
int2 coords = {get_global_id(0), get_global_id(1)};
|
2012-06-08 09:17:07 +00:00
|
|
|
coords += offset;
|
2021-10-13 23:01:15 +02:00
|
|
|
float temp_bounding_box;
|
2019-10-29 09:35:24 +01:00
|
|
|
float4 color = {0.0f,0.0f,0.0f,0.0f};
|
|
|
|
|
float4 multiplyer = {0.0f,0.0f,0.0f,0.0f};
|
|
|
|
|
float4 bokeh;
|
2012-06-08 09:17:07 +00:00
|
|
|
const float radius2 = radius*2.0f;
|
2021-10-13 23:01:15 +02:00
|
|
|
const int2 real_coordinate = coords + offset_output;
|
|
|
|
|
int2 image_coordinates = real_coordinate - offset_input;
|
2012-06-08 09:17:07 +00:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
temp_bounding_box = read_imagef(bounding_box, SAMPLER_NEAREST, coords).s0;
|
2012-06-08 09:17:07 +00:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
if (temp_bounding_box > 0.0f && radius > 0 ) {
|
|
|
|
|
const int2 bokeh_image_dim = get_image_dim(bokeh_image);
|
|
|
|
|
const int2 bokeh_image_center = bokeh_image_dim/2;
|
|
|
|
|
const int2 minXY = max(real_coordinate - radius, zero);
|
|
|
|
|
const int2 maxXY = min(real_coordinate + radius, dimension);
|
2012-06-08 09:17:07 +00:00
|
|
|
int nx, ny;
|
|
|
|
|
|
|
|
|
|
float2 uv;
|
2021-10-13 23:01:15 +02:00
|
|
|
int2 input_xy;
|
2012-06-08 09:17:07 +00:00
|
|
|
|
2014-02-18 13:15:08 +01:00
|
|
|
if (radius < 2) {
|
2021-10-13 23:01:15 +02:00
|
|
|
color = read_imagef(input_image, SAMPLER_NEAREST, image_coordinates);
|
2014-02-18 13:15:08 +01:00
|
|
|
multiplyer = (float4)(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
for (ny = minXY.y, input_xy.y = ny - offset_input.y ; ny < maxXY.y ; ny += step, input_xy.y += step) {
|
|
|
|
|
uv.y = ((real_coordinate.y-ny)/radius2)*bokeh_image_dim.y+bokeh_image_center.y;
|
2012-06-08 09:17:07 +00:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
for (nx = minXY.x, input_xy.x = nx - offset_input.x; nx < maxXY.x ; nx += step, input_xy.x += step) {
|
|
|
|
|
uv.x = ((real_coordinate.x-nx)/radius2)*bokeh_image_dim.x+bokeh_image_center.x;
|
|
|
|
|
bokeh = read_imagef(bokeh_image, SAMPLER_NEAREST, uv);
|
|
|
|
|
color += bokeh * read_imagef(input_image, SAMPLER_NEAREST, input_xy);
|
2012-06-08 09:17:07 +00:00
|
|
|
multiplyer += bokeh;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
color /= multiplyer;
|
2012-12-18 01:46:15 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2021-10-13 23:01:15 +02:00
|
|
|
color = read_imagef(input_image, SAMPLER_NEAREST, image_coordinates);
|
2012-06-08 09:17:07 +00:00
|
|
|
}
|
|
|
|
|
|
____
`````|````` | | | ..''''
| | | |______ .''
| | | | ..'
| | |_______ |___________ ....''
merge to TRUNK!
* The old compositor is still available (Debug Menu: 200)
This commit was brought to you by:
Developers:
* Monique Dewanchand
* Jeroen Bakker
* Dalai Felinto
* Lukas Tönne
Review:
* Brecht van Lommel
Testers:
* Nate Wiebe
* Wolfgang Faehnle
* Carlo Andreacchio
* Daniel Salazar
* Artur Mag
* Christian Krupa
* Francesco Siddi
* Dan McGrath
* Bassam Kurdali
But mostly by the community:
Gold:
Joshua Faulkner
Michael Tiemann
Francesco Paglia
Blender Guru
Blender Developers Fund
Silver:
Pablo Vazquez
Joel Heethaar
Amrein Olivier
Ilias Karasavvidis
Thomas Kumlehn
Sebastian Koenig
Hannu Hoffrén
Benjamin Dansie
Fred M'ule
Michel Vilain
Bradley Cathey
Gianmichele Mariani
Gottfried Hofmann
Bjørnar Frøyse
Valentijn Bruning
Paul Holmes
Clemens Rudolph
Juris Graphix
David Strebel
Ronan Zeegers
François Tarlier
Felipe Andres Esquivel Reed
Olaf Beckman
Jesus Alberto Olmos Linares
Kajimba
Maria Figueiredo
Alexandr Galperin
Francesco Siddi
Julio Iglesias Lopez
Kjartan Tysdal
Thomas Torfs
Film Works
Teruyuki Nakamura
Roger Luethi
Benoit Bolsee
Stefan Abrahamsen
Andreas Mattijat
Xavier Bouchoux
Blender 3D Graphics and Animation
Henk Vostermans
Daniel Blanco Delgado
BlenderDay/2011
Bradley Cathey
Matthieu Dupont de Dinechin
Gianmichele Mariani
Jérôme Scaillet
Bronze (Ivo Grigull, Dylan Urquidi, Philippe Derungs, Phil Beauchamp, Bruce Parrott, Mathieu Quiblier, Daniel Martinez, Leandro Inocencio, Lluc Romaní Brasó,
Jonathan Williamson, Michael Ehlen, Karlis Stigis, Dreamsteep, Martin Lindelöf, Filippo Saracino, Douwe van der Veen, Olli Äkräs, Bruno D'Arcangeli,
Francisco Sedrez Warmling, Watchmike.ca, peter lener, Matteo Novellino, Martin Kirsch, Austars Schnore, KC Elliott, Massimiliano Puliero, Karl Stein,
Wood Design Studios, Omer Khan, Jyrki Kanto, Michał Krupa, Lars Brubaker, Neil Richmond, Adam Kalisz, Robert Garlington, Ian Wilson, Carlo Andreacchio,
Jeremias Boos, Robert Holcomb, Gabriel Zöller, Robert Cude, Natibel de Leon, Nathan Turnage, Nicolas Vergnes, Philipp Kleinhenz, Norman Hartig, Louis Kreusel,
Christopher Taylor, Giovanni Remondini, Daniel Rentzsch, Nico Partipilo, Thomas Ventresco, Johannes Schwarz, Александр Коротеев, Brendon Harvey,
Marcelo G. Malheiros, Marius Giurgi, Richard Burns, Perttu Iso-Metsälä, Steve Bazin, Radoslav Borisov, Yoshiyuki Shida, Julien Guigner, Andrew Hunter,
Philipp Oeser, Daniel Thul, Thobias Johansson, Mauro Bonecchi, Georg Piorczynski, Sebastian Michailidis, L M Weedy, Gen X, Stefan Hinze, Nicolò Zubbini,
Erik Pusch, Rob Scott, Florian Koch, Charles Razack, Adrian Baker, Oliver Villar Diz, David Revoy, Julio Iglesias Lopez, Coen Spoor, Carlos Folch,
Joseph Christie, Victor Hernández García, David Mcsween, James Finnerty, Cory Kruckenberg, Giacomo Graziosi, Olivier Saraja, Lars Brubaker, Eric Hudson,
Johannes Schwarz, David Elguea, Marcus Schulderinsky, Karel De Bruijn, Lucas van Wijngaarden, Stefano Ciarrocchi, Mehmet Eribol, Thomas Berglund, Zuofei Song,
Dylan Urquidi )
2012-05-17 12:49:33 +00:00
|
|
|
write_imagef(output, coords, color);
|
|
|
|
|
}
|
2012-06-13 12:34:56 +00:00
|
|
|
|
2012-07-06 11:31:40 +00:00
|
|
|
//KERNEL --- DEFOCUS /VARIABLESIZEBOKEHBLUR ---
|
2021-10-13 23:01:15 +02:00
|
|
|
__kernel void defocus_kernel(__read_only image2d_t input_image, __read_only image2d_t bokeh_image,
|
|
|
|
|
__read_only image2d_t input_size,
|
|
|
|
|
__write_only image2d_t output, int2 offset_input, int2 offset_output,
|
|
|
|
|
int step, int max_blur_scalar, float threshold, float scalar, int2 dimension, int2 offset)
|
2012-07-06 11:31:40 +00:00
|
|
|
{
|
|
|
|
|
float4 color = {1.0f, 0.0f, 0.0f, 1.0f};
|
|
|
|
|
int2 coords = {get_global_id(0), get_global_id(1)};
|
|
|
|
|
coords += offset;
|
2021-10-13 23:01:15 +02:00
|
|
|
const int2 real_coordinate = coords + offset_output;
|
2012-07-06 11:31:40 +00:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
float4 read_color;
|
|
|
|
|
float4 temp_color;
|
2012-07-06 11:31:40 +00:00
|
|
|
float4 bokeh;
|
2012-08-08 18:04:40 +00:00
|
|
|
float size;
|
2012-07-06 11:31:40 +00:00
|
|
|
float4 multiplier_accum = {1.0f, 1.0f, 1.0f, 1.0f};
|
|
|
|
|
float4 color_accum;
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
int minx = max(real_coordinate.s0 - max_blur_scalar, 0);
|
|
|
|
|
int miny = max(real_coordinate.s1 - max_blur_scalar, 0);
|
|
|
|
|
int maxx = min(real_coordinate.s0 + max_blur_scalar, dimension.s0);
|
|
|
|
|
int maxy = min(real_coordinate.s1 + max_blur_scalar, dimension.s1);
|
2012-07-06 11:31:40 +00:00
|
|
|
|
|
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
int2 input_coordinate = real_coordinate - offset_input;
|
|
|
|
|
float size_center = read_imagef(input_size, SAMPLER_NEAREST, input_coordinate).s0 * scalar;
|
|
|
|
|
color_accum = read_imagef(input_image, SAMPLER_NEAREST, input_coordinate);
|
|
|
|
|
read_color = color_accum;
|
2012-07-06 11:31:40 +00:00
|
|
|
|
2012-08-08 18:04:40 +00:00
|
|
|
if (size_center > threshold) {
|
2012-07-11 20:51:00 +00:00
|
|
|
for (int ny = miny; ny < maxy; ny += step) {
|
2021-10-13 23:01:15 +02:00
|
|
|
input_coordinate.s1 = ny - offset_input.s1;
|
|
|
|
|
float dy = ny - real_coordinate.s1;
|
2012-07-11 20:51:00 +00:00
|
|
|
for (int nx = minx; nx < maxx; nx += step) {
|
2021-10-13 23:01:15 +02:00
|
|
|
float dx = nx - real_coordinate.s0;
|
2012-07-11 20:51:00 +00:00
|
|
|
if (dx != 0 || dy != 0) {
|
2021-10-13 23:01:15 +02:00
|
|
|
input_coordinate.s0 = nx - offset_input.s0;
|
|
|
|
|
size = min(read_imagef(input_size, SAMPLER_NEAREST, input_coordinate).s0 * scalar, size_center);
|
2012-08-08 18:04:40 +00:00
|
|
|
if (size > threshold) {
|
|
|
|
|
if (size >= fabs(dx) && size >= fabs(dy)) {
|
|
|
|
|
float2 uv = {256.0f + dx * 255.0f / size,
|
|
|
|
|
256.0f + dy * 255.0f / size};
|
2021-10-13 23:01:15 +02:00
|
|
|
bokeh = read_imagef(bokeh_image, SAMPLER_NEAREST, uv);
|
|
|
|
|
temp_color = read_imagef(input_image, SAMPLER_NEAREST, input_coordinate);
|
|
|
|
|
color_accum += bokeh * temp_color;
|
2012-07-09 15:21:43 +00:00
|
|
|
multiplier_accum += bokeh;
|
2012-07-06 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2012-07-11 20:51:00 +00:00
|
|
|
}
|
2012-07-06 11:31:40 +00:00
|
|
|
|
2012-08-08 18:10:13 +00:00
|
|
|
color = color_accum * (1.0f / multiplier_accum);
|
|
|
|
|
|
|
|
|
|
/* blend in out values over the threshold, otherwise we get sharp, ugly transitions */
|
|
|
|
|
if ((size_center > threshold) &&
|
|
|
|
|
(size_center < threshold * 2.0f))
|
|
|
|
|
{
|
|
|
|
|
/* factor from 0-1 */
|
|
|
|
|
float fac = (size_center - threshold) / threshold;
|
2021-10-13 23:01:15 +02:00
|
|
|
color = (read_color * (1.0f - fac)) + (color * fac);
|
2012-08-08 18:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
write_imagef(output, coords, color);
|
|
|
|
|
}
|
2012-07-06 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-06-13 12:34:56 +00:00
|
|
|
// KERNEL --- DILATE ---
|
2021-10-13 23:01:15 +02:00
|
|
|
__kernel void dilate_kernel(__read_only image2d_t input_image, __write_only image2d_t output,
|
|
|
|
|
int2 offset_input, int2 offset_output, int scope, int distance_squared, int2 dimension,
|
2012-06-13 12:34:56 +00:00
|
|
|
int2 offset)
|
|
|
|
|
{
|
2012-10-21 05:46:41 +00:00
|
|
|
int2 coords = {get_global_id(0), get_global_id(1)};
|
2012-06-13 12:34:56 +00:00
|
|
|
coords += offset;
|
2021-10-13 23:01:15 +02:00
|
|
|
const int2 real_coordinate = coords + offset_output;
|
2012-06-13 12:34:56 +00:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
const int2 minXY = max(real_coordinate - scope, zero);
|
|
|
|
|
const int2 maxXY = min(real_coordinate + scope, dimension);
|
2012-06-13 12:34:56 +00:00
|
|
|
|
|
|
|
|
float value = 0.0f;
|
|
|
|
|
int nx, ny;
|
2021-10-13 23:01:15 +02:00
|
|
|
int2 input_xy;
|
2012-06-13 12:34:56 +00:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
for (ny = minXY.y, input_xy.y = ny - offset_input.y ; ny < maxXY.y ; ny ++, input_xy.y++) {
|
|
|
|
|
const float deltaY = (real_coordinate.y - ny);
|
|
|
|
|
for (nx = minXY.x, input_xy.x = nx - offset_input.x; nx < maxXY.x ; nx ++, input_xy.x++) {
|
|
|
|
|
const float deltaX = (real_coordinate.x - nx);
|
|
|
|
|
const float measured_distance = deltaX * deltaX + deltaY * deltaY;
|
|
|
|
|
if (measured_distance <= distance_squared) {
|
|
|
|
|
value = max(value, read_imagef(input_image, SAMPLER_NEAREST, input_xy).s0);
|
2012-06-13 12:34:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float4 color = {value,0.0f,0.0f,0.0f};
|
|
|
|
|
write_imagef(output, coords, color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// KERNEL --- DILATE ---
|
2021-10-13 23:01:15 +02:00
|
|
|
__kernel void erode_kernel(__read_only image2d_t input_image, __write_only image2d_t output,
|
|
|
|
|
int2 offset_input, int2 offset_output, int scope, int distance_squared, int2 dimension,
|
2012-06-13 12:34:56 +00:00
|
|
|
int2 offset)
|
|
|
|
|
{
|
2012-10-21 05:46:41 +00:00
|
|
|
int2 coords = {get_global_id(0), get_global_id(1)};
|
2012-06-13 12:34:56 +00:00
|
|
|
coords += offset;
|
2021-10-13 23:01:15 +02:00
|
|
|
const int2 real_coordinate = coords + offset_output;
|
2012-06-13 12:34:56 +00:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
const int2 minXY = max(real_coordinate - scope, zero);
|
|
|
|
|
const int2 maxXY = min(real_coordinate + scope, dimension);
|
2012-06-13 12:34:56 +00:00
|
|
|
|
|
|
|
|
float value = 1.0f;
|
|
|
|
|
int nx, ny;
|
2021-10-13 23:01:15 +02:00
|
|
|
int2 input_xy;
|
2012-06-13 12:34:56 +00:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
for (ny = minXY.y, input_xy.y = ny - offset_input.y ; ny < maxXY.y ; ny ++, input_xy.y++) {
|
|
|
|
|
for (nx = minXY.x, input_xy.x = nx - offset_input.x; nx < maxXY.x ; nx ++, input_xy.x++) {
|
|
|
|
|
const float deltaX = (real_coordinate.x - nx);
|
|
|
|
|
const float deltaY = (real_coordinate.y - ny);
|
|
|
|
|
const float measured_distance = deltaX * deltaX+deltaY * deltaY;
|
|
|
|
|
if (measured_distance <= distance_squared) {
|
|
|
|
|
value = min(value, read_imagef(input_image, SAMPLER_NEAREST, input_xy).s0);
|
2012-06-13 12:34:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float4 color = {value,0.0f,0.0f,0.0f};
|
|
|
|
|
write_imagef(output, coords, color);
|
|
|
|
|
}
|
2012-07-11 19:32:32 +00:00
|
|
|
|
|
|
|
|
// KERNEL --- DIRECTIONAL BLUR ---
|
2021-10-13 23:01:15 +02:00
|
|
|
__kernel void directional_blur_kernel(__read_only image2d_t input_image, __write_only image2d_t output,
|
|
|
|
|
int2 offset_output, int iterations, float scale, float rotation, float2 translate,
|
2014-11-20 21:05:03 +01:00
|
|
|
float2 center, int2 offset)
|
2012-07-11 19:32:32 +00:00
|
|
|
{
|
2012-10-21 05:46:41 +00:00
|
|
|
int2 coords = {get_global_id(0), get_global_id(1)};
|
2012-07-11 19:32:32 +00:00
|
|
|
coords += offset;
|
2021-10-13 23:01:15 +02:00
|
|
|
const int2 real_coordinate = coords + offset_output;
|
2012-07-11 19:32:32 +00:00
|
|
|
|
|
|
|
|
float4 col;
|
|
|
|
|
float2 ltxy = translate;
|
|
|
|
|
float lsc = scale;
|
|
|
|
|
float lrot = rotation;
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
col = read_imagef(input_image, SAMPLER_NEAREST, real_coordinate);
|
2012-07-11 19:32:32 +00:00
|
|
|
|
|
|
|
|
/* blur the image */
|
|
|
|
|
for (int i = 0; i < iterations; ++i) {
|
|
|
|
|
const float cs = cos(lrot), ss = sin(lrot);
|
|
|
|
|
const float isc = 1.0f / (1.0f + lsc);
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
const float v = isc * (real_coordinate.s1 - center.s1) + ltxy.s1;
|
|
|
|
|
const float u = isc * (real_coordinate.s0 - center.s0) + ltxy.s0;
|
2012-07-11 19:32:32 +00:00
|
|
|
float2 uv = {
|
|
|
|
|
cs * u + ss * v + center.s0,
|
|
|
|
|
cs * v - ss * u + center.s1
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
col += read_imagef(input_image, SAMPLER_NEAREST_CLAMP, uv);
|
2012-07-11 19:32:32 +00:00
|
|
|
|
|
|
|
|
/* double transformations */
|
|
|
|
|
ltxy += translate;
|
|
|
|
|
lrot += rotation;
|
|
|
|
|
lsc += scale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
col *= (1.0f/(iterations+1));
|
|
|
|
|
|
|
|
|
|
write_imagef(output, coords, col);
|
|
|
|
|
}
|
2014-10-06 14:59:26 +02:00
|
|
|
|
|
|
|
|
// KERNEL --- GAUSSIAN BLUR ---
|
2021-10-13 23:01:15 +02:00
|
|
|
__kernel void gaussian_xblur_operation_kernel(__read_only image2d_t input_image,
|
|
|
|
|
int2 offset_input,
|
2014-10-06 14:59:26 +02:00
|
|
|
__write_only image2d_t output,
|
2021-10-13 23:01:15 +02:00
|
|
|
int2 offset_output,
|
2014-10-06 14:59:26 +02:00
|
|
|
int filter_size,
|
|
|
|
|
int2 dimension,
|
|
|
|
|
__global float *gausstab,
|
|
|
|
|
int2 offset)
|
|
|
|
|
{
|
|
|
|
|
float4 color = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
int2 coords = {get_global_id(0), get_global_id(1)};
|
|
|
|
|
coords += offset;
|
2021-10-13 23:01:15 +02:00
|
|
|
const int2 real_coordinate = coords + offset_output;
|
|
|
|
|
int2 input_coordinate = real_coordinate - offset_input;
|
2014-10-06 14:59:26 +02:00
|
|
|
float weight = 0.0f;
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
int xmin = max(real_coordinate.x - filter_size, 0) - offset_input.x;
|
|
|
|
|
int xmax = min(real_coordinate.x + filter_size + 1, dimension.x) - offset_input.x;
|
2014-10-06 14:59:26 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
for (int nx = xmin, i = max(filter_size - real_coordinate.x, 0); nx < xmax; ++nx, ++i) {
|
2014-10-06 14:59:26 +02:00
|
|
|
float w = gausstab[i];
|
2021-10-13 23:01:15 +02:00
|
|
|
input_coordinate.x = nx;
|
|
|
|
|
color += read_imagef(input_image, SAMPLER_NEAREST, input_coordinate) * w;
|
2014-10-06 14:59:26 +02:00
|
|
|
weight += w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
color *= (1.0f / weight);
|
|
|
|
|
|
|
|
|
|
write_imagef(output, coords, color);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
__kernel void gaussian_yblur_operation_kernel(__read_only image2d_t input_image,
|
|
|
|
|
int2 offset_input,
|
2014-10-06 14:59:26 +02:00
|
|
|
__write_only image2d_t output,
|
2021-10-13 23:01:15 +02:00
|
|
|
int2 offset_output,
|
2014-10-06 14:59:26 +02:00
|
|
|
int filter_size,
|
|
|
|
|
int2 dimension,
|
|
|
|
|
__global float *gausstab,
|
|
|
|
|
int2 offset)
|
|
|
|
|
{
|
|
|
|
|
float4 color = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
int2 coords = {get_global_id(0), get_global_id(1)};
|
|
|
|
|
coords += offset;
|
2021-10-13 23:01:15 +02:00
|
|
|
const int2 real_coordinate = coords + offset_output;
|
|
|
|
|
int2 input_coordinate = real_coordinate - offset_input;
|
2014-10-06 14:59:26 +02:00
|
|
|
float weight = 0.0f;
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
int ymin = max(real_coordinate.y - filter_size, 0) - offset_input.y;
|
|
|
|
|
int ymax = min(real_coordinate.y + filter_size + 1, dimension.y) - offset_input.y;
|
2014-10-06 14:59:26 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
for (int ny = ymin, i = max(filter_size - real_coordinate.y, 0); ny < ymax; ++ny, ++i) {
|
2014-10-06 14:59:26 +02:00
|
|
|
float w = gausstab[i];
|
2021-10-13 23:01:15 +02:00
|
|
|
input_coordinate.y = ny;
|
|
|
|
|
color += read_imagef(input_image, SAMPLER_NEAREST, input_coordinate) * w;
|
2014-10-06 14:59:26 +02:00
|
|
|
weight += w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
color *= (1.0f / weight);
|
|
|
|
|
|
|
|
|
|
write_imagef(output, coords, color);
|
|
|
|
|
}
|