diff options
Diffstat (limited to 'demos/cubehouse')
-rw-r--r-- | demos/cubehouse/cube.qrc | 7 | ||||
-rw-r--r-- | demos/cubehouse/cubehouse.pro | 12 | ||||
-rw-r--r-- | demos/cubehouse/cubeview.cpp | 460 | ||||
-rw-r--r-- | demos/cubehouse/cubeview.h | 108 | ||||
-rw-r--r-- | demos/cubehouse/main.cpp | 64 | ||||
-rw-r--r-- | demos/cubehouse/projectivetextureeffect.cpp | 148 | ||||
-rw-r--r-- | demos/cubehouse/projectivetextureeffect.h | 79 | ||||
-rw-r--r-- | demos/cubehouse/qtlogo.png | bin | 0 -> 13923 bytes | |||
-rw-r--r-- | demos/cubehouse/shaders/depth.frag | 50 | ||||
-rw-r--r-- | demos/cubehouse/shaders/depth.vert | 75 | ||||
-rw-r--r-- | demos/cubehouse/shaders/depthTestShader.frag | 91 | ||||
-rw-r--r-- | demos/cubehouse/shaders/depthTestShader.vert | 91 | ||||
-rw-r--r-- | demos/cubehouse/shaders/objectlineartexgen.frag | 52 | ||||
-rw-r--r-- | demos/cubehouse/shaders/objectlineartexgen.vert | 63 |
14 files changed, 1300 insertions, 0 deletions
diff --git a/demos/cubehouse/cube.qrc b/demos/cubehouse/cube.qrc new file mode 100644 index 000000000..9de1d255c --- /dev/null +++ b/demos/cubehouse/cube.qrc @@ -0,0 +1,7 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>qtlogo.png</file> + <file>shaders/objectlineartexgen.frag</file> + <file>shaders/objectlineartexgen.vert</file> +</qresource> +</RCC> diff --git a/demos/cubehouse/cubehouse.pro b/demos/cubehouse/cubehouse.pro new file mode 100644 index 000000000..70ee226aa --- /dev/null +++ b/demos/cubehouse/cubehouse.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +TARGET = cubehouse +CONFIG += qt warn_on qt3d +SOURCES = cubeview.cpp main.cpp projectivetextureeffect.cpp +HEADERS = cubeview.h projectivetextureeffect.h +win32:DEFINES+=_CRT_SECURE_NO_WARNINGS +RESOURCES = cube.qrc +DESTDIR = ../../bin + +OTHER_FILES += \ + shaders/objectlineartexgen.frag \ + shaders/objectlineartexgen.vert diff --git a/demos/cubehouse/cubeview.cpp b/demos/cubehouse/cubeview.cpp new file mode 100644 index 000000000..13933f957 --- /dev/null +++ b/demos/cubehouse/cubeview.cpp @@ -0,0 +1,460 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "cubeview.h" +#include "qglcube.h" +#include "qglteapot.h" +#include <QtCore/qdebug.h> +#include <QtCore/qtimer.h> +#include <QtCore/qpropertyanimation.h> +#include <stdio.h> +#include <qmath.h> +#include "projectivetextureeffect.h" + +//#define PROJECTOR_CAMERA_DEBUG_MARKERS + + +CubeView::CubeView(QWidget *parent) + : QGLView(parent), scene(0), cube(0), teapot(0), room(0), + sensitivity(0.1f), + lightParameters(0), + showFrameRate(false), + stereo(false), + useProjectiveTextureEffect(false), + cangle(0.0f), + prevX(0), + prevY(0), + prevZ(0), + havePrev(false), + projectiveTextureEffect(0) +{ + setOption(CameraNavigation, false); + + roomCamera = new QGLCamera(this); + roomCamera->setAdjustForAspectRatio(false); + + QPropertyAnimation *animation; + + animation = new QPropertyAnimation(this, "cubeAngle", this); + animation->setStartValue(0.0f); + animation->setEndValue(360.0f); + animation->setDuration(5000); + animation->setLoopCount(-1); + animation->start(); + + time.start(); +} + +void CubeView::initializeGL(QGLPainter *painter) +{ + QGLBuilder builder; + builder << QGL::Faceted << QGLCube(1.0f); + cube = builder.currentNode(); + builder << QGL::Faceted; + room = builder.currentNode(); + builder.pushNode(); + QGLSceneNode *back = builder.newNode(); + { + QGeometryData quad; + quad.appendVertex(QVector3D(-3.0f, -3.0f, -15.0f)); + quad.appendVertex(QVector3D( 3.0f, -3.0f, -15.0f)); + quad.appendVertex(QVector3D( 3.0f, 3.0f, -15.0f)); + quad.appendVertex(QVector3D(-3.0f, 3.0f, -15.0f)); + builder.addQuads(quad); + } + QGLSceneNode *left = builder.newNode(); + { + QGeometryData quad; + quad.appendVertex(QVector3D(-3.0f, -3.0f, -15.0f)); + quad.appendVertex(QVector3D(-3.0f, 3.0f, -15.0f)); + quad.appendVertex(QVector3D(-3.0f, 3.0f, 0.0f)); + quad.appendVertex(QVector3D(-3.0f, -3.0f, 0.0f)); + builder.addQuads(quad); + } + QGLSceneNode *right = builder.newNode(); + { + QGeometryData quad; + quad.appendVertex(QVector3D(3.0f, 3.0f, -15.0f)); + quad.appendVertex(QVector3D(3.0f, -3.0f, -15.0f)); + quad.appendVertex(QVector3D(3.0f, -3.0f, 0.0f)); + quad.appendVertex(QVector3D(3.0f, 3.0f, 0.0f)); + builder.addQuads(quad); + } + QGLSceneNode *top = builder.newNode(); + { + QGeometryData quad; + quad.appendVertex(QVector3D(-3.0f, 3.0f, -15.0f)); + quad.appendVertex(QVector3D( 3.0f, 3.0f, -15.0f)); + quad.appendVertex(QVector3D( 3.0f, 3.0f, 0.0f)); + quad.appendVertex(QVector3D(-3.0f, 3.0f, 0.0f)); + builder.addQuads(quad); + } + QGLSceneNode *bottom = builder.newNode(); + { + QGeometryData quad; + quad.appendVertex(QVector3D(-3.0f, -3.0f, -15.0f)); + quad.appendVertex(QVector3D(-3.0f, -3.0f, 0.0f)); + quad.appendVertex(QVector3D( 3.0f, -3.0f, 0.0f)); + quad.appendVertex(QVector3D( 3.0f, -3.0f, -15.0f)); + builder.addQuads(quad); + } + builder.popNode(); + + int index; + QGLMaterialCollection *palette = builder.sceneNode()->palette(); + + QGLMaterial *mat1 = new QGLMaterial(); + mat1->setDiffuseColor(QColor(128, 100, 0)); + index = palette->addMaterial(mat1); + back->setMaterialIndex(index); + + QGLMaterial *mat2 = new QGLMaterial(); + mat2->setDiffuseColor(Qt::cyan); + index = palette->addMaterial(mat2); + left->setMaterialIndex(index); + right->setMaterialIndex(index); + + QGLMaterial *mat3 = new QGLMaterial(); + mat3->setDiffuseColor(Qt::yellow); + index = palette->addMaterial(mat3); + top->setMaterialIndex(index); + bottom->setMaterialIndex(index); + + //qDumpScene(room); + + builder.newSection(); + builder << QGLTeapot(); + teapot = builder.currentNode(); + QGLMaterial *china = new QGLMaterial(); + china->setAmbientColor(QColor(192, 150, 128)); + china->setSpecularColor(QColor(60, 60, 60)); + china->setShininess(128); + teapot->setMaterial(china); + + scene = builder.finalizedSceneNode(); + scene->setParent(this); + + roomModel = new QGLLightModel(this); + roomModel->setAmbientSceneColor(Qt::white); + roomModel->setViewerPosition(QGLLightModel::LocalViewer); + + normalModel = new QGLLightModel(this); + + lightParameters = new QGLLightParameters(this); + lightParameters->setPosition(QVector3D(0.0f, 0.0f, 3.0f)); + painter->setMainLight(lightParameters); + + QImage textureImage(QLatin1String(":/qtlogo.png")); + texture.setImage(textureImage); + + if (stereo) { + camera()->setEyeSeparation(0.4f); + roomCamera->setEyeSeparation(0.1f); + } + + if (useProjectiveTextureEffect) + { + // initialize the projector camera + projectorCamera = new QGLCamera(this); + projectiveTextureEffect = new ProjectiveTextureEffect; + connect(projectorCamera, SIGNAL(viewChanged()), + this, SLOT(updateProjectorViewMatrix())); + connect(projectorCamera, SIGNAL(projectionChanged()), + this, SLOT(updateProjectorProjectionMatrix())); + } +} + +void CubeView::paintGL(QGLPainter *painter) +{ + if (showFrameRate) + qWarning("time since last frame: %d ms", time.restart()); + + glDisable(GL_BLEND); + + // Animate the projector position so the effect can be seen + if (useProjectiveTextureEffect) + { + projectorCamera->tiltPanRollCenter + (-0.1f, -0.3f, 0.0f, QGLCamera::PanTiltRoll); + } + + painter->modelViewMatrix().push(); + painter->projectionMatrix().push(); + + painter->setStandardEffect(QGL::LitMaterial); + painter->setCamera(roomCamera); + painter->setLightModel(roomModel); + room->draw(painter); + + painter->modelViewMatrix().pop(); + painter->projectionMatrix().pop(); + + painter->modelViewMatrix().push(); + // These are the model transformations + painter->modelViewMatrix().translate(-0.8f, -1.5f, -3.0f); + painter->setLightModel(normalModel); + if (useProjectiveTextureEffect) + { + modelMatrix.push(); + // For an effect that looks like we have only one projector + // Over the whole screen, we duplicate transformations into the + // projector's model matrix. For now, we don't apply the transform + // to center the effect on each object and see it more clearly. + // modelMatrix.translate(-0.8f, -1.5f, -3.0f); + + updateProjectiveTextureEffect(); + + painter->setUserEffect(projectiveTextureEffect); + texture.bind(); + } + else + { + painter->setStandardEffect(QGL::LitMaterial); + } + teapot->draw(painter); + + if (useProjectiveTextureEffect) + modelMatrix.pop(); + painter->modelViewMatrix().pop(); + + + // These are the model transformations + painter->modelViewMatrix().push(); + painter->modelViewMatrix().translate(1.0f, -0.5f, 0.0f); + painter->modelViewMatrix().rotate(cangle, 1.0f, 1.0f, 1.0f); + + texture.bind(); + if (useProjectiveTextureEffect) + { + modelMatrix.push(); + // For an effect that looks like we have only one projector + // Over the whole screen, we duplicate transformations into the + // projector's model matrix. For now, we don't apply the transform + // to center the effect on each object and see it more clearly. +// modelMatrix.translate(1.0f, -0.5f, 0.0f); + modelMatrix.rotate(cangle, 1.0f, 1.0f, 1.0f); + updateProjectiveTextureEffect(); + painter->setUserEffect(projectiveTextureEffect); +// painter->setStandardEffect(QGL::FlatDecalTexture2D); + cube->draw(painter); + modelMatrix.pop(); + } + else + { + glEnable(GL_BLEND); + painter->setStandardEffect(QGL::LitDecalTexture2D); + painter->setFaceColor(QGL::AllFaces, QColor(170, 202, 0, 120)); + glDisable(GL_DEPTH_TEST); + glCullFace(GL_FRONT); + glEnable(GL_CULL_FACE); + cube->draw(painter); + glCullFace(GL_BACK); + cube->draw(painter); + glDisable(GL_CULL_FACE); + glEnable(GL_DEPTH_TEST); + glBindTexture(GL_TEXTURE_2D, 0); + } + + painter->modelViewMatrix().pop(); +#ifdef PROJECTOR_CAMERA_DEBUG_MARKERS + if (useProjectiveTextureEffect) + { + + painter->modelViewMatrix().push(); + modelMatrix.push(); + painter->modelViewMatrix().translate(projectorCamera->eye()); + painter->modelViewMatrix().scale(0.2); + painter->setStandardEffect(QGL::LitMaterial); + modelMatrix.translate(projectorCamera->eye()); + cube->draw(painter); + + modelMatrix.pop(); + painter->modelViewMatrix().pop(); + + painter->modelViewMatrix().push(); + modelMatrix.push(); + painter->modelViewMatrix().translate(projectorCamera->center()); + painter->modelViewMatrix().scale(0.1); + painter->setStandardEffect(QGL::LitMaterial); + cube->draw(painter); + modelMatrix.pop(); + painter->modelViewMatrix().pop(); + + QVector3DArray verts; + + QVector3D origin = projectorCamera->eye(); + + QVector3D target = projectorCamera->center(); + QVector3D direction = projectorCamera->center() - projectorCamera->eye(); + + QVector3D normal = projectorCamera->upVector().normalized(); + qreal nearPlane = projectorCamera->nearPlane(); + qreal farPlane = projectorCamera->farPlane(); + qreal fieldOfView = projectorCamera->fieldOfView(); + + QVector3D nearTopLeft; + QVector3D nearTopRight; + QVector3D nearBottomLeft; + QVector3D nearBottomRight; + QVector3D farTopLeft; + QVector3D farTopRight; + QVector3D farBottomLeft; + QVector3D farBottomRight; + + QSizeF viewSize = projectorCamera->viewSize(); + + qreal fieldDepthRatio = farPlane / nearPlane; + + QVector3D rightVector = QVector3D::crossProduct(direction, normal).normalized() * viewSize.width() / 2.0; + QVector3D topVector = normal * viewSize.height() / 2.0; + + QVector3D topLeftVector = direction + topVector - rightVector; + QVector3D topRightVector = direction + topVector + rightVector; + QVector3D bottomLeftVector = direction - topVector - rightVector; + QVector3D bottomRightVector = direction - topVector + rightVector; + + verts.append(origin, origin + (direction * (farPlane / direction.length()))); + + verts.append(origin, origin + (topLeftVector * fieldDepthRatio)); + verts.append(origin, origin + (topRightVector * fieldDepthRatio)); + verts.append(origin, origin + (bottomLeftVector * fieldDepthRatio)); + verts.append(origin, origin + (bottomRightVector * fieldDepthRatio)); + + verts.append(origin + topLeftVector, origin + topRightVector); + verts.append(origin + topRightVector, origin + bottomRightVector); + verts.append(origin + bottomRightVector, origin + bottomLeftVector); + verts.append(origin + bottomLeftVector, origin + topLeftVector); + + verts.append(origin + (topLeftVector * fieldDepthRatio), + (origin + topRightVector * fieldDepthRatio)); + verts.append(origin + (topRightVector * fieldDepthRatio), + (origin + bottomRightVector * fieldDepthRatio)); + verts.append(origin + (bottomRightVector * fieldDepthRatio), + (origin + bottomLeftVector * fieldDepthRatio)); + verts.append(origin + (bottomLeftVector * fieldDepthRatio), + (origin + topLeftVector * fieldDepthRatio)); + + verts.append(origin, origin + normal); + + painter->modelViewMatrix().push(); + painter->setStandardEffect(QGL::FlatColor); + painter->clearAttributes(); + painter->setVertexAttribute(QGL::Position, QGLAttributeValue(verts)); + glLineWidth(1.0f); + + painter->setColor(QColor(255,255,255,255)); + painter->draw(QGL::Lines, verts.size()); + painter->modelViewMatrix().pop(); + } +#endif +} + +//inline void CubeView::setProjectiveTextureEffect(bool value) +//{ +// useProjectiveTextureEffect = value; +//} + +void CubeView::setCubeAngle(qreal angle) +{ + cangle = angle; + accelerometerTimeout(); + update(); +} + +void CubeView::accelerometerTimeout() +{ + QVector3D g = gravity(); + camera()->setMotionAdjustment(g); + roomCamera->setMotionAdjustment(g); +} + +QVector3D CubeView::gravity() const +{ + // Access the raw accelerometer data on the N900. + FILE *file = fopen("/sys/class/i2c-adapter/i2c-3/3-001d/coord", "r"); + if (!file) + return QVector3D(0, 0, -1); + float x = 0; + float y = 0; + float z = 0; + fscanf(file, "%f %f %f", &x, &y, &z); + fclose(file); + + // Smooth out the reported values. Large changes are applied as-is, + // and small jitters smooth to the rest position. + if (havePrev) { + qreal xdiff = x - prevX; + qreal ydiff = y - prevY; + qreal zdiff = z - prevZ; + if (qAbs(xdiff) < 20.0f && qAbs(ydiff) < 20.0f && qAbs(zdiff) < 20.0f) { + x = prevX + xdiff * 0.1f; + y = prevY + ydiff * 0.1f; + z = prevZ + zdiff * 0.1f; + } + } + prevX = x; + prevY = y; + prevZ = z; + havePrev = true; + + return QVector3D((x / 1000.0f) * sensitivity, + (-y / 1000.0f) * sensitivity, -z / 1000.0f); +} + +void CubeView::updateProjectorViewMatrix() +{ + Q_ASSERT_X(projectorCamera != 0, Q_FUNC_INFO, "Null projector camera in updateProjectorViewMatrix()"); + projectiveTextureEffect->setProjectorViewMatrix(projectorCamera->modelViewMatrix()); + updateProjectiveTextureEffect(); +} + +void CubeView::updateProjectorProjectionMatrix() +{ + qreal projectorAspectRatio = 1.0; + projectiveTextureEffect->setProjectorProjectionMatrix(projectorCamera->projectionMatrix(projectorAspectRatio)); + updateProjectiveTextureEffect(); +} + +void CubeView::updateProjectiveTextureEffect() +{ + projectiveTextureEffect->setProjectorDirection(projectorCamera->center() - projectorCamera->eye()); + projectiveTextureEffect->setModelMatrix(modelMatrix); +} diff --git a/demos/cubehouse/cubeview.h b/demos/cubehouse/cubeview.h new file mode 100644 index 000000000..b9e25a20b --- /dev/null +++ b/demos/cubehouse/cubeview.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CUBEVIEW_H +#define CUBEVIEW_H + +#include "qglview.h" +#include "qglbuilder.h" +#include "qgltexture2d.h" +#include <QtCore/qdatetime.h> + +class ProjectiveTextureEffect; + +class CubeView : public QGLView +{ + Q_OBJECT + Q_PROPERTY(qreal cubeAngle READ cubeAngle WRITE setCubeAngle) +public: + CubeView(QWidget *parent = 0); + ~CubeView() {} + + void setShowFrameRate(bool value) { showFrameRate = value; } + void setStereo(bool value) { stereo = value; } + void setProjectiveTextureEffect(bool value) +{ + useProjectiveTextureEffect = value; +} + + qreal cubeAngle() const { return cangle; } + void setCubeAngle(qreal angle); + +protected: + void initializeGL(QGLPainter *painter); + void paintGL(QGLPainter *painter); + +private slots: + void accelerometerTimeout(); + void updateProjectorViewMatrix(); + void updateProjectorProjectionMatrix(); + void updateProjectiveTextureEffect(); + +private: + QGLTexture2D texture; + QGLSceneNode *scene; + QGLSceneNode *cube; + QGLSceneNode *teapot; + QGLSceneNode *room; + QGLCamera *roomCamera; + QGLCamera *projectorCamera; + qreal sensitivity; + QGLLightModel *roomModel; + QGLLightModel *normalModel; + QGLLightParameters *lightParameters; + bool showFrameRate; + bool stereo; + bool useProjectiveTextureEffect; + QTime time; + qreal cangle; + mutable qreal prevX, prevY, prevZ; + mutable bool havePrev; + + QVector3D gravity() const; + + ProjectiveTextureEffect* projectiveTextureEffect; + QMatrix4x4 biasMatrix; + QMatrix4x4Stack modelMatrix; + QMatrix4x4 objectLinearTexgenMatrix; +}; + +#endif diff --git a/demos/cubehouse/main.cpp b/demos/cubehouse/main.cpp new file mode 100644 index 000000000..29326a535 --- /dev/null +++ b/demos/cubehouse/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include "cubeview.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + CubeView view; + if (QApplication::arguments().contains(QLatin1String("-framerate"))) + view.setShowFrameRate(true); + if (QApplication::arguments().contains(QLatin1String("-projectivetexture"))) + view.setProjectiveTextureEffect(true); + if (QApplication::arguments().contains(QLatin1String("-stereo"))) + view.setStereo(true); + else if (view.stereoType() != QGLView::RedCyanAnaglyph) + view.setStereo(true); + if (QApplication::arguments().contains(QLatin1String("-maximize"))) + view.showMaximized(); + else if (QApplication::arguments().contains(QLatin1String("-fullscreen"))) + view.showFullScreen(); + else + view.show(); + return app.exec(); +} diff --git a/demos/cubehouse/projectivetextureeffect.cpp b/demos/cubehouse/projectivetextureeffect.cpp new file mode 100644 index 000000000..6e69a2ebb --- /dev/null +++ b/demos/cubehouse/projectivetextureeffect.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QFile> +#include "projectivetextureeffect.h" +#include <QtOpenGL/qglshaderprogram.h> + +static const QMatrix4x4 biasMatrix = QMatrix4x4(0.5, 0.0, 0.0, 0.5, + 0.0, 0.5, 0.0, 0.5, + 0.0, 0.0, 0.5, 0.5, + 0.0, 0.0, 0.0, 1.0); + +/*! + The ProjectiveTextureEffect mimics the effect of shining a projector onto + a scene from a specific direction. Vertex coordinates in object space are + transformed into eye-space coordinates relative to the light direction, + using the objectLinearTexgenMatrix. +*/ +ProjectiveTextureEffect::ProjectiveTextureEffect() : + matrixDirty(true) +{ + setupShaders(); +} + +void ProjectiveTextureEffect::setActive(QGLPainter *painter, bool flag) +{ + QGLShaderProgramEffect::setActive(painter, flag); +} + +void ProjectiveTextureEffect::update(QGLPainter *painter, QGLPainter::Updates updates) +{ + QGLShaderProgramEffect::update(painter, updates); + + if (matrixDirty) + { + recalulateObjectLinearTexgenMatrix(); + matrixDirty = false; + } + + program()->setUniformValue("objectLinearTexgenMatrix", + objectLinearTexgenMatrix); + program()->setUniformValue("projectorDirection", + projectorDirection); +} + +void ProjectiveTextureEffect::setProjectorDirection(const QVector4D &direction) +{ + this->projectorDirection = direction; + matrixDirty = true; +} + +void ProjectiveTextureEffect::setCameraModelViewMatrix(const QMatrix4x4 &newCameraModelViewMatrix) +{ + cameraModelViewMatrix = newCameraModelViewMatrix; + bool invertible; + inverseCameraModelViewMatrix = + newCameraModelViewMatrix.inverted(&invertible); + Q_ASSERT(invertible); + if (!invertible) + qWarning() << "camera Model view matrix not invertible in ProjectiveDepthTestEffect::setCameraModelViewMatrix()"; + matrixDirty = true; +} + +void ProjectiveTextureEffect::setProjectorProjectionMatrix(const QMatrix4x4 &newMatrix) +{ + projectorProjectionMatrix = newMatrix; + matrixDirty = true; +} + +void ProjectiveTextureEffect::setProjectorViewMatrix(const QMatrix4x4 &newMatrix) +{ + projectorViewMatrix = newMatrix; + matrixDirty = true; +} + +void ProjectiveTextureEffect::setModelMatrix(const QMatrix4x4 &newMatrix) +{ + modelMatrix = newMatrix; + matrixDirty = true; +} + +void ProjectiveTextureEffect::recalulateObjectLinearTexgenMatrix() +{ + objectLinearTexgenMatrix = biasMatrix * + projectorProjectionMatrix * + projectorViewMatrix * + modelMatrix; +} + +void ProjectiveTextureEffect::setupShaders() +{ + QString vertexShaderFileName = QLatin1String(":/shaders/objectlineartexgen.vert"); + QFile vertexShaderFile(vertexShaderFileName); + if (vertexShaderFile.open(QIODevice::ReadOnly | QIODevice::Text)) + { + setVertexShader(vertexShaderFile.readAll()); + } else { + qWarning() << "Could not open file "<<vertexShaderFileName<<", failed to load vertex shader"; + } + + QString fragmentShaderFileName = QLatin1String(":/shaders/objectlineartexgen.frag"); + QFile fragmentShaderFile(fragmentShaderFileName); + if (fragmentShaderFile.open(QIODevice::ReadOnly | QIODevice::Text)) + { + setFragmentShader(fragmentShaderFile.readAll()); + } else { + qWarning() << "Could not open file "<<fragmentShaderFileName<<", failed to load fragment shader"; + } + +} diff --git a/demos/cubehouse/projectivetextureeffect.h b/demos/cubehouse/projectivetextureeffect.h new file mode 100644 index 000000000..eb000e68a --- /dev/null +++ b/demos/cubehouse/projectivetextureeffect.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PROJECTIVEDTEXTUREEFFECT_H +#define PROJECTIVEDTEXTUREEFFECT_H + +#include "qglshaderprogrameffect.h" +//#include "deptheffect.h" +#include "qmatrix4x4.h" + +class ProjectiveTextureEffect : public QGLShaderProgramEffect +{ +public: + explicit ProjectiveTextureEffect(); + virtual void setActive(QGLPainter *painter, bool flag); + virtual void update(QGLPainter *painter, QGLPainter::Updates updates); + virtual void setProjectorDirection(const QVector4D &direction); + + void setCameraModelViewMatrix(const QMatrix4x4 &newCameraModelViewMatrix); + void setProjectorProjectionMatrix(const QMatrix4x4 &newMatrix); + void setProjectorViewMatrix(const QMatrix4x4 &newMatrix); + void setModelMatrix(const QMatrix4x4 &newMatrix); + +// TODO: +// QMatrix4x4 eyeLinearTexgenMatrix; + +protected: + virtual void setupShaders(); +private: + virtual void recalulateObjectLinearTexgenMatrix(); + bool matrixDirty; + QMatrix4x4 modelMatrix; + QMatrix4x4 objectLinearTexgenMatrix; + QMatrix4x4 cameraModelViewMatrix; + QMatrix4x4 inverseCameraModelViewMatrix; + QMatrix4x4 projectorProjectionMatrix; + QMatrix4x4 projectorViewMatrix; + QVector4D projectorDirection; +}; + +#endif // PROJECTIVEDTEXTUREEFFECT_H diff --git a/demos/cubehouse/qtlogo.png b/demos/cubehouse/qtlogo.png Binary files differnew file mode 100644 index 000000000..7d3e97eb3 --- /dev/null +++ b/demos/cubehouse/qtlogo.png diff --git a/demos/cubehouse/shaders/depth.frag b/demos/cubehouse/shaders/depth.frag new file mode 100644 index 000000000..939cfc954 --- /dev/null +++ b/demos/cubehouse/shaders/depth.frag @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +varying float depth; + +void main(void) +{ + float stupidMathsDepth = depth; + stupidMathsDepth = (stupidMathsDepth + 10.0) / 20.0; +// gl_FragColor = vec4(vec3(stupidMathsDepth), 1.0); + gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0); +}; diff --git a/demos/cubehouse/shaders/depth.vert b/demos/cubehouse/shaders/depth.vert new file mode 100644 index 000000000..8e13193b9 --- /dev/null +++ b/demos/cubehouse/shaders/depth.vert @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +attribute highp vec4 vertex; +varying float depth; +uniform highp mat4 qt_ModelViewMatrix; +uniform highp mat4 qt_ProjectionMatrix; + +attribute highp vec4 texCoords; + +uniform highp mat4 cameraCombinedMatrix; +uniform highp mat4 cameraModelViewMatrix; +uniform highp mat4 cameraProjectionMatrix; + +uniform highp mat4 lightCombinedMatrix; + +varying highp vec4 qt_TexCoord0; +varying highp vec4 onScreenPosition; +varying highp vec4 lightScreenPosition; +varying highp vec4 worldSpaceVertex; + +void main(void) +{ + qt_TexCoord0 = texCoords; + + // qt_ProjectionMatrix == cameraProjectionMatrix +// onScreenPosition = qt_ProjectionMatrix * qt_ModelViewMatrix * vertex; +//onScreenPosition = cameraProjectionMatrix * qt_ModelViewMatrix * vertex; + + onScreenPosition = cameraProjectionMatrix + * cameraModelViewMatrix +// * qt_ModelViewMatrix + * vertex; + depth = onScreenPosition.z; + + gl_Position = onScreenPosition; +}; diff --git a/demos/cubehouse/shaders/depthTestShader.frag b/demos/cubehouse/shaders/depthTestShader.frag new file mode 100644 index 000000000..b2c6957b1 --- /dev/null +++ b/demos/cubehouse/shaders/depthTestShader.frag @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// This is equivilent to GL_REPLACE +varying highp vec4 qt_TexCoord0; + +uniform mediump sampler2D texture; +uniform mediump mat4 textureMatrix; +varying highp vec4 onScreenPosition; +varying highp vec4 lightScreenPosition; +varying highp vec4 worldSpaceVertex; +varying float lightDepth; +varying float actualDepth; + +void main(void) +{ + + // I should be able to build a matrix to do this: +// vec4 normalizedOnScreenPosition = (onScreenPosition + 5.0) / 10.0; +vec4 normalizedLightScreenPosition = (((lightScreenPosition +//+ lightScreenPosition.w +) / lightScreenPosition.w ) + 1.0) / 2.0; + +// float lightMapDepth = texture2D(texture, normalizedLightScreenPosition.st).z; + float lightMapDepth = texture2D(texture, normalizedLightScreenPosition.st ).z; +// gl_FragColor = vec4(lightMapDepth, lightMapDepth, lightMapDepth, 1.0); + +// gl_FragColor = vec4(normalizedLightScreenPosition.st,0.0,1.0); + +// float lightActualDepth = normalizedLightScreenPosition.z; + float lightActualDepth = lightDepth; +// gl_FragColor = vec4(lightActualDepth, lightActualDepth, lightActualDepth, 1.0); + float lightActualDepthWithStupidMaths = (lightActualDepth + 10.0) / 20.0; + float lightDepthWithStupidMaths = (lightDepth + 10.0) / 20.0; +// gl_FragColor = vec4(vec3(lightActualDepthWithStupidMaths), 1.0); + + +// if (lightActualDepthWithStupidMaths > lightMapDepth ) +// gl_FragColor = vec4(0.2, 0.2, 0.2, 1.0); +// else + gl_FragColor = vec4(1.0, 1.0, 0.5, 1.0); + + +// gl_FragColor = vec4(lightDepthWithStupidMaths, lightDepthWithStupidMaths, lightDepthWithStupidMaths, 1.0); + + +//float stupidMathslightDepth = (lightDepth + 10.0) / 20; +//gl_FragColor = vec4(stupidMathslightDepth, stupidMathslightDepth, stupidMathslightDepth, 1.0); + +//float stupidMathsActualDepth = (actualDepth + 10.0) / 20.0; +//gl_FragColor = vec4(stupidMathsActualDepth, stupidMathsActualDepth, stupidMathsActualDepth, 1.0); + +}; diff --git a/demos/cubehouse/shaders/depthTestShader.vert b/demos/cubehouse/shaders/depthTestShader.vert new file mode 100644 index 000000000..6f640c875 --- /dev/null +++ b/demos/cubehouse/shaders/depthTestShader.vert @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +attribute highp vec4 vertex; +attribute highp vec4 texCoords; + +uniform highp mat4 matrix; +uniform highp mat4 qt_ProjectionMatrix; +uniform highp mat4 qt_ModelViewMatrix; + +uniform highp mat4 cameraCombinedMatrix; +uniform highp mat4 lightCombinedMatrix; + +uniform highp mat4 cameraModelViewMatrix; +uniform highp mat4 inverseCameraModelViewMatrix; +uniform highp mat4 lightModelViewMatrix; + +uniform highp mat4 cameraProjectionMatrix; +uniform highp mat4 lightProjectionMatrix; + +varying highp vec4 qt_TexCoord0; +varying highp vec4 onScreenPosition; +varying highp vec4 lightScreenPosition; +varying highp vec4 worldSpaceVertex; +varying float lightDepth; +varying float actualDepth; + +void main(void) +{ + qt_TexCoord0 = texCoords; +// onScreenPosition = matrix * vertex; +//onScreenPosition = cameraCombinedMatrix * vertex; // works + onScreenPosition = qt_ProjectionMatrix * + qt_ModelViewMatrix + * vertex; + + highp vec4 worldPosition = inverseCameraModelViewMatrix * + qt_ModelViewMatrix * vertex; + +// lightScreenPosition = lightCombinedMatrix * vertex; +// lightScreenPosition = lightCombinedMatrix * worldPosition; + lightScreenPosition = lightProjectionMatrix * lightModelViewMatrix * vertex; + lightDepth = lightScreenPosition.z; + + actualDepth = onScreenPosition.z; + + worldSpaceVertex = vertex; + +// gl_Position = qt_ProjectionMatrix * worldPosition; +//gl_Position = onScreenPosition; +gl_Position = onScreenPosition; +// gl_Position = lightScreenPosition; +}; diff --git a/demos/cubehouse/shaders/objectlineartexgen.frag b/demos/cubehouse/shaders/objectlineartexgen.frag new file mode 100644 index 000000000..a4439f28a --- /dev/null +++ b/demos/cubehouse/shaders/objectlineartexgen.frag @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +uniform sampler2D texture; +varying highp vec4 texCoord; +varying float facingProjector; + +void main(void) +{ + vec2 clampedCoords = texCoord.st; + clampedCoords = clamp(texCoord.st, vec2(0.0), vec2(1.0)); + vec4 textureColor = texture2D(texture, clampedCoords); + gl_FragColor = vec4(textureColor.rgb * facingProjector, 1.0); +}; diff --git a/demos/cubehouse/shaders/objectlineartexgen.vert b/demos/cubehouse/shaders/objectlineartexgen.vert new file mode 100644 index 000000000..b78b938c5 --- /dev/null +++ b/demos/cubehouse/shaders/objectlineartexgen.vert @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtQuick3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +attribute highp vec4 qt_Vertex; +attribute highp vec4 qt_Normal; +uniform highp mat3 qt_NormalMatrix; +uniform highp mat4 qt_ModelViewProjectionMatrix; + +uniform highp mat4 objectLinearTexgenMatrix; +uniform highp vec4 projectorDirection; + +varying highp vec4 texCoord; +varying float facingProjector; + +void main(void) +{ + texCoord = objectLinearTexgenMatrix * qt_Vertex; + vec4 normal = normalize(vec4(qt_NormalMatrix * vec3(qt_Vertex), qt_Vertex.w)); + // We're facing the projector if the normal and projector direction + // are pointing in opposite directions, i.e. if their dot product + // is negative. + facingProjector = -dot(normalize(normal), normalize(projectorDirection)); + facingProjector = clamp(facingProjector, 0.0, 1.0); + gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex; +}; |