[effects] Change sphere to use shader traits variant

This commit is contained in:
Martin Gräßlin 2015-12-01 12:11:02 +01:00
parent 318fb6989b
commit b258dc53b3
4 changed files with 23 additions and 50 deletions

View file

@ -120,7 +120,6 @@ CubeEffect::CubeEffect()
connect(effects, SIGNAL(tabBoxAdded(int)), this, SLOT(slotTabBoxAdded(int)));
connect(effects, SIGNAL(tabBoxClosed()), this, SLOT(slotTabBoxClosed()));
connect(effects, SIGNAL(tabBoxUpdated()), this, SLOT(slotTabBoxUpdated()));
connect(effects, SIGNAL(screenGeometryChanged(const QSize&)), this, SLOT(slotResetShaders()));
reconfigure(ReconfigureAll);
}
@ -296,11 +295,6 @@ void CubeEffect::slotWallPaperLoaded()
watcher->deleteLater();
}
void CubeEffect::slotResetShaders()
{
ShaderManager::instance()->resetShader(sphereShader, ShaderManager::GenericShader);
}
bool CubeEffect::loadShader()
{
effects->makeOpenGLContextCurrent();
@ -330,33 +324,19 @@ bool CubeEffect::loadShader()
QRect rect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop());
cylinderShader->setUniform("width", (float)rect.width() * 0.5f);
}
sphereShader = ShaderManager::instance()->loadVertexShader(ShaderManager::GenericShader, sphereVertexshader);
QFile svf(sphereVertexshader);
if (!svf.open(QIODevice::ReadOnly)) {
qCCritical(KWINEFFECTS) << "The sphere shader couldn't be opened!";
return false;
}
sphereShader = ShaderManager::instance()->generateCustomShader(ShaderTrait::MapTexture | ShaderTrait::AdjustSaturation | ShaderTrait::Modulate, svf.readAll(), QByteArray());
if (!sphereShader->isValid()) {
qCCritical(KWINEFFECTS) << "The sphere shader failed to load!";
return false;
} else {
ShaderBinder binder(sphereShader);
sphereShader->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);
sphereShader->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);
sphereShader->setUniform(GLShader::ModelViewMatrix, modelview);
const QMatrix4x4 identity;
sphereShader->setUniform(GLShader::ScreenTransformation, identity);
sphereShader->setUniform(GLShader::WindowTransformation, identity);
QRect rect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop());
sphereShader->setUniform("width", (float)rect.width() * 0.5f);
sphereShader->setUniform("height", (float)rect.height() * 0.5f);

View file

@ -140,7 +140,6 @@ private Q_SLOTS:
void slotTabBoxClosed();
void slotCubeCapLoaded();
void slotWallPaperLoaded();
void slotResetShaders();
private:
enum RotationDirection {
Left,

View file

@ -17,25 +17,22 @@ 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 height;
uniform float cubeAngle;
uniform vec2 u_offset;
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 = vertex;
texcoord0 = texcoord.st;
vec4 transformedVertex = position;
transformedVertex.x = transformedVertex.x - width;
transformedVertex.y = transformedVertex.y - height;
transformedVertex.xy = transformedVertex.xy + u_offset;
@ -48,8 +45,8 @@ void main()
transformedVertex.xy += vec2( width - u_offset.x, height - u_offset.y );
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,25 +18,22 @@ 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 height;
uniform float cubeAngle;
uniform vec2 u_offset;
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 = vertex;
texcoord0 = texcoord.st;
vec4 transformedVertex = position;
transformedVertex.x = transformedVertex.x - width;
transformedVertex.y = transformedVertex.y - height;
transformedVertex.xy = transformedVertex.xy + u_offset;
@ -49,8 +46,8 @@ void main()
transformedVertex.xy += vec2( width - u_offset.x, height - u_offset.y );
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;
}