diff --git a/effects/cube/CMakeLists.txt b/effects/cube/CMakeLists.txt index 647142f716..492fd671e4 100644 --- a/effects/cube/CMakeLists.txt +++ b/effects/cube/CMakeLists.txt @@ -21,13 +21,25 @@ install( FILES # Data files install( FILES - cube/data/cube-cap.glsl - cube/data/cube-reflection.glsl cube/data/cubecap.png - cube/data/cylinder.vert - cube/data/sphere.vert DESTINATION ${DATA_INSTALL_DIR}/kwin ) +install( FILES + cube/data/1.10/cube-cap.glsl + cube/data/1.10/cube-reflection.glsl + cube/data/1.10/cylinder.vert + cube/data/1.10/sphere.vert + DESTINATION ${DATA_INSTALL_DIR}/kwin/shaders/1.10 +) + +install( FILES + cube/data/1.40/cube-cap.glsl + cube/data/1.40/cube-reflection.glsl + cube/data/1.40/cylinder.vert + cube/data/1.40/sphere.vert + DESTINATION ${DATA_INSTALL_DIR}/kwin/shaders/1.40 +) + ####################################### # Config diff --git a/effects/cube/cube.cpp b/effects/cube/cube.cpp index 271c4e9d93..4b240d447c 100644 --- a/effects/cube/cube.cpp +++ b/effects/cube/cube.cpp @@ -93,15 +93,21 @@ CubeEffect::CubeEffect() , zOrderingFactor(0.0f) , mAddedHeightCoeff1(0.0f) , mAddedHeightCoeff2(0.0f) + , m_shadersDir("kwin/shaders/1.10/") , m_cubeCapBuffer(NULL) , m_proxy(this) { desktopNameFont.setBold(true); desktopNameFont.setPointSize(14); - const QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/cube-reflection.glsl"); +#ifndef KWIN_HAVE_OPENGLES + if (GLPlatform::instance()->glslVersion() >= kVersionNumber(1, 40)) + m_shadersDir = "kwin/shaders/1.40/"; +#endif + + const QString fragmentshader = KGlobal::dirs()->findResource("data", m_shadersDir + "cube-reflection.glsl"); m_reflectionShader = ShaderManager::instance()->loadFragmentShader(ShaderManager::GenericShader, fragmentshader); - const QString capshader = KGlobal::dirs()->findResource("data", "kwin/cube-cap.glsl"); + const QString capshader = KGlobal::dirs()->findResource("data", m_shadersDir + "cube-cap.glsl"); m_capShader = ShaderManager::instance()->loadFragmentShader(ShaderManager::GenericShader, capshader); m_textureMirrorMatrix.scale(1.0, -1.0, 1.0); m_textureMirrorMatrix.translate(0.0, -1.0, 0.0); @@ -283,8 +289,8 @@ bool CubeEffect::loadShader() if (!(GLPlatform::instance()->supports(GLSL) && (effects->compositingType() == OpenGL2Compositing))) return false; - QString cylinderVertexshader = KGlobal::dirs()->findResource("data", "kwin/cylinder.vert"); - QString sphereVertexshader = KGlobal::dirs()->findResource("data", "kwin/sphere.vert"); + QString cylinderVertexshader = KGlobal::dirs()->findResource("data", m_shadersDir + "cylinder.vert"); + QString sphereVertexshader = KGlobal::dirs()->findResource("data", m_shadersDir + "sphere.vert"); if (cylinderVertexshader.isEmpty() || sphereVertexshader.isEmpty()) { kError(1212) << "Couldn't locate shader files" << endl; return false; diff --git a/effects/cube/cube.h b/effects/cube/cube.h index c707a18a7a..2de304570a 100644 --- a/effects/cube/cube.h +++ b/effects/cube/cube.h @@ -233,6 +233,8 @@ private: float mAddedHeightCoeff1; float mAddedHeightCoeff2; + QString m_shadersDir; + QMatrix4x4 m_rotationMatrix; QMatrix4x4 m_reflectionMatrix; QMatrix4x4 m_textureMirrorMatrix; diff --git a/effects/cube/data/cube-cap.glsl b/effects/cube/data/1.10/cube-cap.glsl similarity index 100% rename from effects/cube/data/cube-cap.glsl rename to effects/cube/data/1.10/cube-cap.glsl diff --git a/effects/cube/data/cube-reflection.glsl b/effects/cube/data/1.10/cube-reflection.glsl similarity index 100% rename from effects/cube/data/cube-reflection.glsl rename to effects/cube/data/1.10/cube-reflection.glsl diff --git a/effects/cube/data/cylinder.vert b/effects/cube/data/1.10/cylinder.vert similarity index 100% rename from effects/cube/data/cylinder.vert rename to effects/cube/data/1.10/cylinder.vert diff --git a/effects/cube/data/sphere.vert b/effects/cube/data/1.10/sphere.vert similarity index 100% rename from effects/cube/data/sphere.vert rename to effects/cube/data/1.10/sphere.vert diff --git a/effects/cube/data/1.40/cube-cap.glsl b/effects/cube/data/1.40/cube-cap.glsl new file mode 100644 index 0000000000..97e9f217e8 --- /dev/null +++ b/effects/cube/data/1.40/cube-cap.glsl @@ -0,0 +1,32 @@ +#version 140 +uniform sampler2D sampler; +uniform vec4 u_capColor; +uniform float u_opacity; +uniform int u_mirror; +uniform int u_untextured; + +in vec2 varyingTexCoords; + +out vec4 fragColor; + +vec2 mirrorTex(vec2 coords) { + vec2 mirrored = coords; + if (u_mirror != 0) { + mirrored.t = mirrored.t * (-1.0) + 1.0; + } + return mirrored; +} + +void main() { + vec4 color = u_capColor; + vec2 texCoord = mirrorTex(varyingTexCoords); + vec4 tex = texture(sampler, texCoord); + if (texCoord.s < 0.0 || texCoord.s > 1.0 || + texCoord.t < 0.0 || texCoord.t > 1.0 || u_untextured != 0) { + tex = u_capColor; + } + color.rgb = tex.rgb*tex.a + color.rgb*(1.0-tex.a); + color.a = u_opacity; + + fragColor = color; +} diff --git a/effects/cube/data/1.40/cube-reflection.glsl b/effects/cube/data/1.40/cube-reflection.glsl new file mode 100644 index 0000000000..f314483fa1 --- /dev/null +++ b/effects/cube/data/1.40/cube-reflection.glsl @@ -0,0 +1,11 @@ +#version 140 +uniform float u_alpha; + +in vec2 varyingTexCoords; + +out vec4 fragColor; + +void main() +{ + fragColor = vec4(0.0, 0.0, 0.0, u_alpha*varyingTexCoords.s); +} diff --git a/effects/cube/data/1.40/cylinder.vert b/effects/cube/data/1.40/cylinder.vert new file mode 100644 index 0000000000..123739201f --- /dev/null +++ b/effects/cube/data/1.40/cylinder.vert @@ -0,0 +1,50 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + + Copyright (C) 2008, 2011 Martin Gräßlin + +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. If not, see . +*********************************************************************/ +#version 140 +uniform mat4 projection; +uniform mat4 modelview; +uniform mat4 screenTransformation; +uniform mat4 windowTransformation; +uniform float width; +uniform float cubeAngle; +uniform float xCoord; +uniform float timeLine; + +in vec4 vertex; +in vec2 texCoord; + +out vec2 varyingTexCoords; + +void main() +{ + varyingTexCoords = texCoord; + vec4 transformedVertex = vec4(vertex.x - ( width - xCoord ), vertex.yzw); + float radian = radians(cubeAngle); + float radius = (width)*tan(radian); + float azimuthAngle = radians(transformedVertex.x/(width)*(90.0 - cubeAngle)); + + transformedVertex.x = width - xCoord + radius * sin( azimuthAngle ); + transformedVertex.z = vertex.z + radius * cos( azimuthAngle ) - radius; + + vec3 diff = (vertex.xyz - transformedVertex.xyz)*timeLine; + transformedVertex.xyz += diff; + + gl_Position = projection*(modelview*screenTransformation*windowTransformation)*transformedVertex; +} diff --git a/effects/cube/data/1.40/sphere.vert b/effects/cube/data/1.40/sphere.vert new file mode 100644 index 0000000000..f74a9b8a5e --- /dev/null +++ b/effects/cube/data/1.40/sphere.vert @@ -0,0 +1,56 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + + Copyright (C) 2008, 2011 Martin Gräßlin + +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. If not, see . +*********************************************************************/ +#version 140 +uniform mat4 projection; +uniform mat4 modelview; +uniform mat4 screenTransformation; +uniform mat4 windowTransformation; +uniform float width; +uniform float height; +uniform float cubeAngle; +uniform vec2 u_offset; +uniform float timeLine; + +in vec4 vertex; +in vec2 texCoord; + +out vec2 varyingTexCoords; + +void main() +{ + varyingTexCoords = texCoord; + vec4 transformedVertex = vertex; + transformedVertex.x = transformedVertex.x - width; + transformedVertex.y = transformedVertex.y - height; + transformedVertex.xy = transformedVertex.xy + u_offset; + float radian = radians(cubeAngle); + float radius = (width)/cos(radian); + float zenithAngle = acos(transformedVertex.y/radius); + float azimuthAngle = asin(transformedVertex.x/radius); + transformedVertex.z = radius * sin( zenithAngle ) * cos( azimuthAngle ) - radius*cos( radians( 90.0 - cubeAngle ) ); + transformedVertex.x = radius * sin( zenithAngle ) * sin( azimuthAngle ); + + transformedVertex.xy += vec2( width - u_offset.x, height - u_offset.y ); + + vec3 diff = (vertex.xyz - transformedVertex.xyz)*timeLine; + transformedVertex.xyz += diff; + + gl_Position = projection*(modelview*screenTransformation*windowTransformation)*transformedVertex; +}