2010-03-05 20:42:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Fredrik Höglund <fredrik@kde.org>
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
* Copyright © 2018 Alex Nemeth <alex.nemeth329@gmail.com>
|
2010-03-05 20:42:10 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. if not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLURSHADER_H
|
|
|
|
#define BLURSHADER_H
|
|
|
|
|
|
|
|
#include <kwinglutils.h>
|
2018-05-29 14:50:12 +00:00
|
|
|
|
|
|
|
#include <QMatrix4x4>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QScopedPointer>
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
#include <QVector2D>
|
|
|
|
#include <QVector4D>
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2018-05-29 14:50:12 +00:00
|
|
|
class BlurShader : public QObject
|
2010-03-05 20:42:10 +00:00
|
|
|
{
|
2018-05-29 14:50:12 +00:00
|
|
|
Q_OBJECT
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2018-05-29 14:50:12 +00:00
|
|
|
public:
|
|
|
|
BlurShader(QObject *parent = nullptr);
|
|
|
|
~BlurShader() override;
|
2010-03-12 15:56:19 +00:00
|
|
|
|
2018-05-29 14:50:12 +00:00
|
|
|
bool isValid() const;
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
|
|
|
|
enum SampleType {
|
|
|
|
DownSampleType,
|
|
|
|
UpSampleType,
|
Added noise blur effect
Summary:
Added the option to turn on noise behind the blurred area.
The lowest strength value disables it completely, so it is optional and is disabled by default.
Test Plan:
Edit: this new screenshot shows the updated noise generation.
Edit2: separated the screenshots so you can flick through them to clearly see the differences
{F5694024}
{F5694031}
{F5694025}
{F5694028}
Reviewers: #kwin, #vdg, fredrik
Reviewed By: #vdg, fredrik
Subscribers: davidedmundson, matheusm, romangg, ivan, zzag, ngraham, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10281
2018-02-13 23:12:39 +00:00
|
|
|
CopySampleType,
|
|
|
|
NoiseSampleType
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
};
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2018-05-29 14:50:12 +00:00
|
|
|
void bind(SampleType sampleType);
|
|
|
|
void unbind();
|
2010-03-08 20:45:58 +00:00
|
|
|
|
2018-05-29 14:50:12 +00:00
|
|
|
void setModelViewProjectionMatrix(const QMatrix4x4 &matrix);
|
|
|
|
void setOffset(float offset);
|
|
|
|
void setTargetTextureSize(const QSize &renderTextureSize);
|
|
|
|
void setNoiseTextureSize(const QSize &noiseTextureSize);
|
|
|
|
void setTexturePosition(const QPoint &texPos);
|
|
|
|
void setBlurRect(const QRect &blurRect, const QSize &screenSize);
|
2010-03-08 20:45:58 +00:00
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
private:
|
2018-05-29 14:50:12 +00:00
|
|
|
QScopedPointer<GLShader> m_shaderDownsample;
|
|
|
|
QScopedPointer<GLShader> m_shaderUpsample;
|
|
|
|
QScopedPointer<GLShader> m_shaderCopysample;
|
|
|
|
QScopedPointer<GLShader> m_shaderNoisesample;
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
|
|
|
|
int m_mvpMatrixLocationDownsample;
|
|
|
|
int m_offsetLocationDownsample;
|
|
|
|
int m_renderTextureSizeLocationDownsample;
|
|
|
|
int m_halfpixelLocationDownsample;
|
|
|
|
|
|
|
|
int m_mvpMatrixLocationUpsample;
|
|
|
|
int m_offsetLocationUpsample;
|
|
|
|
int m_renderTextureSizeLocationUpsample;
|
|
|
|
int m_halfpixelLocationUpsample;
|
|
|
|
|
|
|
|
int m_mvpMatrixLocationCopysample;
|
|
|
|
int m_renderTextureSizeLocationCopysample;
|
|
|
|
int m_blurRectLocationCopysample;
|
|
|
|
|
Added noise blur effect
Summary:
Added the option to turn on noise behind the blurred area.
The lowest strength value disables it completely, so it is optional and is disabled by default.
Test Plan:
Edit: this new screenshot shows the updated noise generation.
Edit2: separated the screenshots so you can flick through them to clearly see the differences
{F5694024}
{F5694031}
{F5694025}
{F5694028}
Reviewers: #kwin, #vdg, fredrik
Reviewed By: #vdg, fredrik
Subscribers: davidedmundson, matheusm, romangg, ivan, zzag, ngraham, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10281
2018-02-13 23:12:39 +00:00
|
|
|
int m_mvpMatrixLocationNoisesample;
|
|
|
|
int m_offsetLocationNoisesample;
|
|
|
|
int m_renderTextureSizeLocationNoisesample;
|
|
|
|
int m_noiseTextureSizeLocationNoisesample;
|
|
|
|
int m_texStartPosLocationNoisesample;
|
|
|
|
int m_halfpixelLocationNoisesample;
|
|
|
|
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
//Caching uniform values to aviod unnecessary setUniform calls
|
2018-05-29 14:50:12 +00:00
|
|
|
int m_activeSampleType = -1;
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
|
2018-05-29 14:50:12 +00:00
|
|
|
float m_offsetDownsample = 0.0;
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
QMatrix4x4 m_matrixDownsample;
|
|
|
|
|
2018-05-29 14:50:12 +00:00
|
|
|
float m_offsetUpsample = 0.0;
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
QMatrix4x4 m_matrixUpsample;
|
|
|
|
|
|
|
|
QMatrix4x4 m_matrixCopysample;
|
|
|
|
|
2018-05-29 14:50:12 +00:00
|
|
|
float m_offsetNoisesample = 0.0;
|
Added noise blur effect
Summary:
Added the option to turn on noise behind the blurred area.
The lowest strength value disables it completely, so it is optional and is disabled by default.
Test Plan:
Edit: this new screenshot shows the updated noise generation.
Edit2: separated the screenshots so you can flick through them to clearly see the differences
{F5694024}
{F5694031}
{F5694025}
{F5694028}
Reviewers: #kwin, #vdg, fredrik
Reviewed By: #vdg, fredrik
Subscribers: davidedmundson, matheusm, romangg, ivan, zzag, ngraham, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10281
2018-02-13 23:12:39 +00:00
|
|
|
QVector2D m_noiseTextureSizeNoisesample;
|
|
|
|
QMatrix4x4 m_matrixNoisesample;
|
|
|
|
|
2018-05-29 14:50:12 +00:00
|
|
|
bool m_valid = false;
|
|
|
|
|
|
|
|
Q_DISABLE_COPY(BlurShader);
|
2010-03-08 20:45:58 +00:00
|
|
|
};
|
|
|
|
|
2018-05-29 14:50:12 +00:00
|
|
|
inline bool BlurShader::isValid() const
|
|
|
|
{
|
|
|
|
return m_valid;
|
|
|
|
}
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
} // namespace KWin
|
|
|
|
|
|
|
|
#endif
|