GLSL 1.40 shaders for cube effect
Shaders are moved into dedicated directories 1.10 and 1.40. 1.10 contains the already existing versions, 1.40 copies of them adjusted to GLSL 1.40. REVIEW: 110571
This commit is contained in:
parent
2bee9a0ee0
commit
c1486596fb
11 changed files with 177 additions and 8 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -233,6 +233,8 @@ private:
|
|||
float mAddedHeightCoeff1;
|
||||
float mAddedHeightCoeff2;
|
||||
|
||||
QString m_shadersDir;
|
||||
|
||||
QMatrix4x4 m_rotationMatrix;
|
||||
QMatrix4x4 m_reflectionMatrix;
|
||||
QMatrix4x4 m_textureMirrorMatrix;
|
||||
|
|
32
effects/cube/data/1.40/cube-cap.glsl
Normal file
32
effects/cube/data/1.40/cube-cap.glsl
Normal file
|
@ -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;
|
||||
}
|
11
effects/cube/data/1.40/cube-reflection.glsl
Normal file
11
effects/cube/data/1.40/cube-reflection.glsl
Normal file
|
@ -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);
|
||||
}
|
50
effects/cube/data/1.40/cylinder.vert
Normal file
50
effects/cube/data/1.40/cylinder.vert
Normal file
|
@ -0,0 +1,50 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2008, 2011 Martin Gräßlin <kde@martin-graesslin.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
#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;
|
||||
}
|
56
effects/cube/data/1.40/sphere.vert
Normal file
56
effects/cube/data/1.40/sphere.vert
Normal file
|
@ -0,0 +1,56 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2008, 2011 Martin Gräßlin <kde@martin-graesslin.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
#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;
|
||||
}
|
Loading…
Reference in a new issue