GLSL 1.40 shader for lookingglass effect

REVIEW: 110574
This commit is contained in:
Martin Gräßlin 2013-05-21 10:56:10 +02:00
parent c00d468f0f
commit 5c78f7eabe
4 changed files with 39 additions and 3 deletions

View file

@ -15,8 +15,11 @@ install( FILES
# Data files
install( FILES
lookingglass/data/lookingglass.frag
DESTINATION ${DATA_INSTALL_DIR}/kwin )
lookingglass/data/1.10/lookingglass.frag
DESTINATION ${DATA_INSTALL_DIR}/kwin/shaders/1.10 )
install( FILES
lookingglass/data/1.40/lookingglass.frag
DESTINATION ${DATA_INSTALL_DIR}/kwin/shaders/1.40 )
#######################################
# Config

View file

@ -0,0 +1,28 @@
#version 140
uniform sampler2D sampler;
uniform vec2 u_cursor;
uniform float u_zoom;
uniform float u_radius;
uniform vec2 u_textureSize;
in vec2 varyingTexCoords;
out vec4 fragColor;
#define PI 3.14159
void main()
{
vec2 d = u_cursor - varyingTexCoords;
float dist = sqrt(d.x*d.x + d.y*d.y);
vec2 texcoord = varyingTexCoords;
if (dist < u_radius) {
float disp = sin(dist / u_radius * PI) * (u_zoom - 1.0) * 20.0;
texcoord += d / dist * disp;
}
texcoord = texcoord/u_textureSize;
texcoord.t = 1.0 - texcoord.t;
fragColor = texture(sampler, texcoord);
}

View file

@ -116,7 +116,12 @@ bool LookingGlassEffect::loadData()
return false;
}
const QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/lookingglass.frag");
QString shadersDir = "kwin/shaders/1.10/";
#ifndef KWIN_HAVE_OPENGLES
if (GLPlatform::instance()->glslVersion() >= kVersionNumber(1, 40))
shadersDir = "kwin/shaders/1.40/";
#endif
const QString fragmentshader = KGlobal::dirs()->findResource("data", shadersDir + "lookingglass.frag");
m_shader = ShaderManager::instance()->loadFragmentShader(ShaderManager::SimpleShader, fragmentshader);
if (m_shader->isValid()) {
ShaderBinder binder(m_shader);