[effects] Change cylinder to shader traits variant

This commit is contained in:
Martin Gräßlin 2015-12-01 12:05:14 +01:00
parent 6e35aded0b
commit 318fb6989b
3 changed files with 25 additions and 46 deletions

View file

@ -298,7 +298,6 @@ void CubeEffect::slotWallPaperLoaded()
void CubeEffect::slotResetShaders()
{
ShaderManager::instance()->resetShader(cylinderShader, ShaderManager::GenericShader);
ShaderManager::instance()->resetShader(sphereShader, ShaderManager::GenericShader);
}
@ -315,33 +314,19 @@ bool CubeEffect::loadShader()
return false;
}
cylinderShader = ShaderManager::instance()->loadVertexShader(ShaderManager::GenericShader, cylinderVertexshader);
QFile cvf(cylinderVertexshader);
if (!cvf.open(QIODevice::ReadOnly)) {
qCCritical(KWINEFFECTS) << "The cylinder shader couldn't be opened!";
return false;
}
cylinderShader = ShaderManager::instance()->generateCustomShader(ShaderTrait::MapTexture | ShaderTrait::AdjustSaturation | ShaderTrait::Modulate, cvf.readAll(), QByteArray());
if (!cylinderShader->isValid()) {
qCCritical(KWINEFFECTS) << "The cylinder shader failed to load!";
return false;
} else {
ShaderBinder binder(cylinderShader);
cylinderShader->setUniform("sampler", 0);
QMatrix4x4 projection;
float fovy = 60.0f;
float aspect = 1.0f;
float zNear = 0.1f;
float zFar = 100.0f;
float ymax = zNear * tan(fovy * M_PI / 360.0f);
float ymin = -ymax;
float xmin = ymin * aspect;
float xmax = ymax * aspect;
projection.frustum(xmin, xmax, ymin, ymax, zNear, zFar);
cylinderShader->setUniform(GLShader::ProjectionMatrix, projection);
QMatrix4x4 modelview;
float scaleFactor = 1.1 * tan(fovy * M_PI / 360.0f) / ymax;
modelview.translate(xmin * scaleFactor, ymax * scaleFactor, -1.1);
const QSize screenSize = effects->virtualScreenSize();
modelview.scale((xmax - xmin)*scaleFactor / screenSize.width(), -(ymax - ymin)*scaleFactor / screenSize.height(), 0.001);
cylinderShader->setUniform(GLShader::ModelViewMatrix, modelview);
const QMatrix4x4 identity;
cylinderShader->setUniform(GLShader::ScreenTransformation, identity);
cylinderShader->setUniform(GLShader::WindowTransformation, identity);
QRect rect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop());
cylinderShader->setUniform("width", (float)rect.width() * 0.5f);
}

View file

@ -17,33 +17,30 @@ 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/>.
*********************************************************************/
uniform mat4 projection;
uniform mat4 modelview;
uniform mat4 screenTransformation;
uniform mat4 windowTransformation;
uniform mat4 modelViewProjectionMatrix;
uniform float width;
uniform float cubeAngle;
uniform float xCoord;
uniform float timeLine;
attribute vec4 vertex;
attribute vec2 texCoord;
attribute vec4 position;
attribute vec4 texcoord;
varying vec2 varyingTexCoords;
varying vec2 texcoord0;
void main()
{
varyingTexCoords = texCoord;
vec4 transformedVertex = vec4(vertex.x - ( width - xCoord ), vertex.yzw);
texcoord0 = texcoord.st;
vec4 transformedVertex = vec4(position.x - ( width - xCoord ), position.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;
transformedVertex.z = position.z + radius * cos( azimuthAngle ) - radius;
vec3 diff = (vertex.xyz - transformedVertex.xyz)*timeLine;
vec3 diff = (position.xyz - transformedVertex.xyz)*timeLine;
transformedVertex.xyz += diff;
gl_Position = projection*(modelview*screenTransformation*windowTransformation)*transformedVertex;
gl_Position = modelViewProjectionMatrix*transformedVertex;
}

View file

@ -18,33 +18,30 @@ 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 mat4 modelViewProjectionMatrix;
uniform float width;
uniform float cubeAngle;
uniform float xCoord;
uniform float timeLine;
in vec4 vertex;
in vec2 texCoord;
in vec4 position;
in vec4 texcoord;
out vec2 varyingTexCoords;
out vec2 texcoord0;
void main()
{
varyingTexCoords = texCoord;
vec4 transformedVertex = vec4(vertex.x - ( width - xCoord ), vertex.yzw);
texcoord0 = texcoord.st;
vec4 transformedVertex = vec4(position.x - ( width - xCoord ), position.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;
transformedVertex.z = position.z + radius * cos( azimuthAngle ) - radius;
vec3 diff = (vertex.xyz - transformedVertex.xyz)*timeLine;
vec3 diff = (position.xyz - transformedVertex.xyz)*timeLine;
transformedVertex.xyz += diff;
gl_Position = projection*(modelview*screenTransformation*windowTransformation)*transformedVertex;
gl_Position = modelViewProjectionMatrix*transformedVertex;
}