[effects] Change cylinder to shader traits variant
This commit is contained in:
parent
6e35aded0b
commit
318fb6989b
3 changed files with 25 additions and 46 deletions
|
@ -298,7 +298,6 @@ void CubeEffect::slotWallPaperLoaded()
|
||||||
|
|
||||||
void CubeEffect::slotResetShaders()
|
void CubeEffect::slotResetShaders()
|
||||||
{
|
{
|
||||||
ShaderManager::instance()->resetShader(cylinderShader, ShaderManager::GenericShader);
|
|
||||||
ShaderManager::instance()->resetShader(sphereShader, ShaderManager::GenericShader);
|
ShaderManager::instance()->resetShader(sphereShader, ShaderManager::GenericShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,33 +314,19 @@ bool CubeEffect::loadShader()
|
||||||
return false;
|
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()) {
|
if (!cylinderShader->isValid()) {
|
||||||
qCCritical(KWINEFFECTS) << "The cylinder shader failed to load!";
|
qCCritical(KWINEFFECTS) << "The cylinder shader failed to load!";
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
ShaderBinder binder(cylinderShader);
|
ShaderBinder binder(cylinderShader);
|
||||||
cylinderShader->setUniform("sampler", 0);
|
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());
|
QRect rect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop());
|
||||||
cylinderShader->setUniform("width", (float)rect.width() * 0.5f);
|
cylinderShader->setUniform("width", (float)rect.width() * 0.5f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,33 +17,30 @@ GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
uniform mat4 projection;
|
uniform mat4 modelViewProjectionMatrix;
|
||||||
uniform mat4 modelview;
|
|
||||||
uniform mat4 screenTransformation;
|
|
||||||
uniform mat4 windowTransformation;
|
|
||||||
uniform float width;
|
uniform float width;
|
||||||
uniform float cubeAngle;
|
uniform float cubeAngle;
|
||||||
uniform float xCoord;
|
uniform float xCoord;
|
||||||
uniform float timeLine;
|
uniform float timeLine;
|
||||||
|
|
||||||
attribute vec4 vertex;
|
attribute vec4 position;
|
||||||
attribute vec2 texCoord;
|
attribute vec4 texcoord;
|
||||||
|
|
||||||
varying vec2 varyingTexCoords;
|
varying vec2 texcoord0;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
varyingTexCoords = texCoord;
|
texcoord0 = texcoord.st;
|
||||||
vec4 transformedVertex = vec4(vertex.x - ( width - xCoord ), vertex.yzw);
|
vec4 transformedVertex = vec4(position.x - ( width - xCoord ), position.yzw);
|
||||||
float radian = radians(cubeAngle);
|
float radian = radians(cubeAngle);
|
||||||
float radius = (width)*tan(radian);
|
float radius = (width)*tan(radian);
|
||||||
float azimuthAngle = radians(transformedVertex.x/(width)*(90.0 - cubeAngle));
|
float azimuthAngle = radians(transformedVertex.x/(width)*(90.0 - cubeAngle));
|
||||||
|
|
||||||
transformedVertex.x = width - xCoord + radius * sin( azimuthAngle );
|
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;
|
transformedVertex.xyz += diff;
|
||||||
|
|
||||||
gl_Position = projection*(modelview*screenTransformation*windowTransformation)*transformedVertex;
|
gl_Position = modelViewProjectionMatrix*transformedVertex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
#version 140
|
#version 140
|
||||||
uniform mat4 projection;
|
uniform mat4 modelViewProjectionMatrix;
|
||||||
uniform mat4 modelview;
|
|
||||||
uniform mat4 screenTransformation;
|
|
||||||
uniform mat4 windowTransformation;
|
|
||||||
uniform float width;
|
uniform float width;
|
||||||
uniform float cubeAngle;
|
uniform float cubeAngle;
|
||||||
uniform float xCoord;
|
uniform float xCoord;
|
||||||
uniform float timeLine;
|
uniform float timeLine;
|
||||||
|
|
||||||
in vec4 vertex;
|
in vec4 position;
|
||||||
in vec2 texCoord;
|
in vec4 texcoord;
|
||||||
|
|
||||||
out vec2 varyingTexCoords;
|
out vec2 texcoord0;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
varyingTexCoords = texCoord;
|
texcoord0 = texcoord.st;
|
||||||
vec4 transformedVertex = vec4(vertex.x - ( width - xCoord ), vertex.yzw);
|
vec4 transformedVertex = vec4(position.x - ( width - xCoord ), position.yzw);
|
||||||
float radian = radians(cubeAngle);
|
float radian = radians(cubeAngle);
|
||||||
float radius = (width)*tan(radian);
|
float radius = (width)*tan(radian);
|
||||||
float azimuthAngle = radians(transformedVertex.x/(width)*(90.0 - cubeAngle));
|
float azimuthAngle = radians(transformedVertex.x/(width)*(90.0 - cubeAngle));
|
||||||
|
|
||||||
transformedVertex.x = width - xCoord + radius * sin( azimuthAngle );
|
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;
|
transformedVertex.xyz += diff;
|
||||||
|
|
||||||
gl_Position = projection*(modelview*screenTransformation*windowTransformation)*transformedVertex;
|
gl_Position = modelViewProjectionMatrix*transformedVertex;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue